I'm trying to learn about color text in a terminal window. (In case it matters I'm using Terminal.app on OS X.) I'd like to get the terminal's current foreground and background color pair. It looks like I should be able to get this info in a perl script using the Term::Cap library, but the solution eludes me.
In a perl script how would I query the terminal's current foreground and background color pair value?
The feature is outside the scope of terminfo and termcap, because it deals with terminal responses, while terminfo/termcap describe these capabilities:
While in principle, there is no limitation on what could be part of a terminal description, there was little commonality across terminals back in the 1980s for responses. A few terminals could report specific features, most of those were constant (e.g., version information). Most of the variable responses came after terminfo/termcap had more or less solidified in X/Open Curses. ncurses extends that, but again, most of the extensions are either features or special keys.
Terminal.app implements the most commonly-used features of xterm
, but (like other imitators) omits most of the terminal responses. Among other things, xterm
provides terminal responses which can tell an application what the window's colors are currently. There are a couple of command-line utilities (xtermset
and xtermcontrol
) which have been written to use this information (and again, they cover only a part of the repertoire). Using xtermcontrol
demonstrates that Terminal.app is lacking in this area — see screenshot: