How to enable 32k color pairs in ncurses?

I read that ncurses can support up to 256 colors and up to 32 thousand color pairs. Although I managed to customize 256 colors myself, I cannot find any information on how to set up 32x color pairs.

Result

printf("%d - %d\n", COLORS, COLOR_PAIRS); 

is an

 256 - 256 

and while for hardcore terminal fans two colors and two color pairs may be enough, I would like to know how to get most of the colors from the library.

+5
source share
2 answers

By default, ncurses6 is configured with --enable-ext-colors enabled. You also need --enable-widec (otherwise, the type cchar_t in which the advanced colors are stored is not used). The configuration script warns about this:

 checking if you want to use extended colors... yes configure: WARNING: This option applies only to wide-character library 

Assuming you have built a library with extended colors (and wide characters), it is capable of displaying up to 256 colors and up to 32767 color pairs (maximum value in 16-bit value). After that, it depends on the description of the terminal you are using (and the terminal emulator). Most terminal emulators running on X Windows can display 256 colors. Outside of X, it is not clear that there is a majority.

ncurses has fairly accurate descriptions of the terminals for each of them (and no, using TERM=xterm-256color not the answer for each of them, since special keys and other characteristics are usually different from xterm: FAQ Why not just use the 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:

enter image description here

+2
source

The ncurses color pair is actually a combination of foreground color and background color. You can manipulate them using color_pair ( color_pair page here ). There are 32,768 combinations, because there are 256 combinations for the background and the same for the background, but when counting red + blue (for example) as blue + red there are 256x256 / 2 = 32,768 combinations.

You can then use pairs of foreground and background with a checkerboard pattern (such as β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ ) to create more colors. See here .

I think there may be a misunderstanding inherent in your question. On the manual page:

This [linux] implementation will return ERR when trying to use color values ​​outside the range of 0 to COLORS-1 (except for the default color extension) or use color pairs outside the range of 0 to COLOR_PAIR-1.

What does this mean that you can use only color_pair color pairs color_pair once (i.e., available for use through init_pair() ) - on your implementation, that is 256. But there are 32,768 color pairs - just not all at once through init_pair() . This is how I understand him.

+2
source

Source: https://habr.com/ru/post/1237060/


All Articles