I've read that ncurses can support up to 256 colors and up to 32k color pairs. While I managed to set up 256 colors by myself, I can't find any information on how to set up 32k color pairs.
The result of
printf("%d - %d\n", COLORS, COLOR_PAIRS);
is
256 - 256
and while 2 colors and 2 color pairs may be enough for hardcore terminal fans, I'd like to know how to get the most colors out of the library.
Why does ncurses support only eight colors? But why only eight colors, and why these particular colors? At least with the Linux console, if you're running on a PC, the color range's origins are with the PC hardware.
To use color, you must call the start_color() function soon after calling initscr() , to initialize the default color set (the curses. wrapper() function does this automatically). Once that's done, the has_colors() function returns TRUE if the terminal in use can actually display color.
By default, ncurses6 configures with --enable-ext-colors
enabled. You need also --enable-widec
(otherwise, the cchar_t
type which stores extended colors is not used). The configure script warns about this:
checking if you want to use extended colors... yes
configure: WARNING: This option applies only to wide-character library
Assuming that you built the library with extended colors (and wide characters), it is capable of displaying up to 256 colors and up to 32767 color pairs (the maximum value in a signed 16-bit number). After that, it depends on the terminal description that you are using (and the terminal emulator). A majority of the terminal emulators running in X Windows can display 256 colors. Outside of X, it's not clear that there is a majority.
ncurses has reasonably accurate terminal descriptions for each of these (and no, using TERM=xterm-256color
is not the answer for each, since special keys and other characteristics generally differ from xterm: the FAQ Why not just use TERM set to "xterm"? also applies to xterm-256color
).
Here is a screenshot showing xterm
running the ncurses
test program (from ncurses-examples) for wide colors:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With