Question

I wrote a little-more-than-throwaway monitoring script in Python which uses ncurses and color to display some values which update frequently, but which are hardly ever of interest. To alert me to significant changes, I set things up so that when these values get into the realm of being interesting, the text changes from black-on-white to white-on-red. This works fine on my Linux (openSuSE 12.2) box, but on Solaris 10 curses.can_change_color() always returns False, no matter what I have tried. On both platforms, I am using the same version of Python (2.7.2) and ncurses (5.7). I have a number of terminal emulators available to me (gnome-terminal, xterm, rxvt). All are capable of displaying my shell prompt in red, so I know they support color. I've tried setting TERM to a number of xterm variants, including xtermc, xterm-color, rxvt, rxvt-16color. Some of those terminal names aren't in the default location, so I occasionally also have to set TERMINFO to point at a terminfo capability database. I'm thus sure the entries I desire are found.

The Python curses.can_change_color() function is just a thin wrapper around the ncurses library routine of the same name. Why is it always returning False?

Was it helpful?

Solution

can_change_color() actually reports whether colors can be remapped, via init_color() -- an uncommon capability -- not whether colors can be used at all, via init_pair(). To check for that basic color capability, what you want is has_colors().

init_color(), on the terminals where it works, lets you do things like tweak the exact shade of blue used -- or make the terminal's idea of "blue" show up as something else entirely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top