Sample Header Ad - 728x90

Terminal escape sequences: why don't terminals report what features they support, instead of relying on terminfo?

11 votes
2 answers
3627 views
I've been looking into escape sequences lately, and I'm surprised of what they can do. You can even move an xterm X11 window with them (try printf '\e[3;0;0t'), wow! The most common way to know what features a terminal supports seems to be using a database. That's what ncurses does, and it's used by 99.9% of applications that rely on escape sequences. Ncurses reads the terminfo database for your shell's TERM environment variable in order to decide which features are supported by your console. You can change the TERM environment variable of your shell, and if you do it most applications could start using less features or misbehaving (try running nano or vim after setting TERM=""). I've seen that some escape codes cause the terminal to report stuff. For instance [6n causes the terminal to report the cursor position. (printf '\e[6n') - Why don't we use similar report mechanisms to let the console report which features it supports? Instead of coupling the features with the value of TERM, each console could advertise its own features, making the whole thing more precise and reliable. Why isn't this a thing? --- Edit: something that I should have asked before... I'd like to create a new escape sequence, to hack konsole and gnome-terminal in order to support it and to use it in some scripts. I'd like to be able to query the console in order to know whether the one I'm running supports this feature - what's the suggested way to do that?
Asked by peoro (3938 rep)
Sep 4, 2017, 11:57 PM
Last activity: Jul 15, 2020, 12:50 PM