Raouf Jacker
Raouf Jacker

Reputation: 59

How do i use more than 8 colors in ncurses?

I just started to use ncurses on Linux. I wanted to use more than 8 colors, but there were only 8 available.

How can I use more colors, or create my own by giving them a names, and set their RGB values?

I tried editing a color with init_color, but that will simply replace one of the current 8 instead of creating new ones.

Note: the value of the global var COLORS is 256, so I believe I can use up to 256 different colors.

Upvotes: 3

Views: 5501

Answers (2)

mikeyq6
mikeyq6

Reputation: 1148

The constant COLOR_PAIRS defines how many colour pairs a system will allow. See: http://pubs.opengroup.org/onlinepubs/7908799/xcurses/can_change_color.html.

You can substitute your own numbers in init_color to define new ones. eg init_color(9, 800, 700, 600);

Upvotes: 1

Thomas Dickey
Thomas Dickey

Reputation: 54583

If your terminal supports it, you should choose (or customize) a terminal description which has more than 8 colors. As it is, there are a lot of existing terminal descriptions which could be used: most are customized for particular terminals (or terminal emulators).

If your terminal supports it, the corresponding description would have the capability initc. That is used by the library call init_color. The xterm-256color entry has this for instance:

initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,

which tells the library how to translate the three parameters into an escape sequence. The terminal entries are built up from reusable parts such as xterm+256color, because some terminals lack the feature you are interested in. For those, xterm+256setaf is appropriate.

For reference,

Upvotes: 2

Related Questions