Colours in NCurses
I decided to do some experimentation with how the colours defined in ncurses are actually displayed in terminals, what the effects are of combining these colours with other attributes, and how colour schemes of a terminal can affect the displayed colours. To this end I wrote a small c file and ran it in different terminals and different configurations. Note that only the 8 basic NCurses colours are tested, the more flexible init_color() function is not used.
Some screenshots can be found below, but more screenshots are always welcome! Please send your (.png) screenshots to firstname.lastname@example.org.
- The most obvious conclusion: the displayed colours do not have the exact same colour value in every terminal. Some terminals also allow users to modify these colours.
- You can not assume that the default foreground or background colour can be represented by one of the 8 basic colours defined by NCurses.
- Specifying -1 as colour, to indicate the default foreground or background colour, seems to work fine in any terminal tested so far.
- All tested terminals render the foreground colour in a lighter shade when the A_BOLD attribute is set. This does not apply to the background colour. The result of this is that the text becomes visible when using A_BOLD when the foreground and background colour are set to the same value.
- Unfortunately, not all terminals are configured in such a way that all possible colours are readable. So as a developer you'll still have to support configurable colour schemes in your ncurses application. :-(
- On most terminals, setting the foreground and background colour to the same value without applying the A_BOLD attribute will make the text invisible. Don't rely on this, however, as this is not the case on OS X.
To avoid wasting unecessary space, the comparison screenshots below only display the colour table. Here's a screenshot of the full output of the program, which also explains what each column means.
- Arch Linux, Roxterm, Default color scheme
- Arch Linux, Roxterm, GTK color scheme
- Arch Linux, Roxterm, Tango color scheme
- Arch Linux, Roxterm, Modified Tango color scheme
- Arch Linux, xterm (default settings)
- Ubuntu 11.10, Gnome-terminal
- Debian Squeeze, VT (default settings)
- FreeBSD, VT (default settings)
- Mac OS X, Terminal
- Mac OS X, iTerm2