-1

Usually you need to write like below.

start_color();

init_pair(999, COLOR_WHITE, COLOR_BLACK);
attron(COLOR_PAIR(999));
addstr("neko");

In my case, there are plenty of RGB colors to display. I don't like to init_pair each times because it can be a lot of combinations.

Is there any way to do like below?

set_color(R, G, B); // set without init_pair
addstr("neko");

From my current understanding, I need to sacrifice 1 palette such as COLOR_CYAN to overwrite by init_color...? I don't like to do so...

init_color(COLOR_RED, 128, 128, 128);
attron(COLOR_PAIR(COLOR_RED));
addstr("neko");

init_color(COLOR_RED, 12, 12, 12);
attron(COLOR_PAIR(COLOR_RED));
addstr("neko");

init_color(COLOR_RED, 1, 1, 1);
attron(COLOR_PAIR(COLOR_RED));
addstr("neko");
eeeeeeeeengo
  • 133
  • 6

1 Answers1

1

You don't necessarily have to redefine an existing COLOR_* color when using init_color(). Check the value of COLORS -- on some terminals, yes, it will be as low as 8, and in those cases you'd have no choice. (But often, those terminals don't support color redefinition anyway.) Other terminals set COLORS to 256, or even higher. The 256-color terminals often present as "xterm-256color", and implement a predefined set of colors that you may find are already useful. (They, again, may or may not be redefinable.)

But pairs are the curses color model, like it or not. In your example code above, COLOR_PAIR(COLOR_RED) won't work, unless you've already called something like init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK) (assuming you wanted a black background) first.

William McBrine
  • 2,166
  • 11
  • 7