NCURSES_VERSION "5.7".
I checked COLOR_PAIRS in my terminal(iTerm2) is 32767 by below.
FILE *outputfile;
outputfile = fopen(“d.txt”, “a”);
fprintf(outputfile, “%d\n”, COLOR_PAIRS);
fclose(outputfile);
I tried the below code.
#include <ncurses.h>
int main()
{
initscr();
start_color();
short cnt = 1;
for (short bg = 0; bg < 100; bg++) {
for (short fg = 0; fg < 100; fg++) {
init_pair(cnt, fg, bg);
attron(COLOR_PAIR(cnt));
addstr("aaa");
attroff(COLOR_PAIR(cnt));
cnt++;
}
}
refresh();
getch();
endwin();
return 0;
}
It works well.
Even though you changed the cnt as 10, it works as well.
short cnt = 10;
However, if you switch the cnt to 500, it gets broken.
#include <ncurses.h>
int main()
{
initscr();
start_color();
short cnt = 500;
for (short bg = 0; bg < 100; bg++) {
for (short fg = 0; fg < 100; fg++) {
init_pair(cnt, fg, bg);
attron(COLOR_PAIR(cnt));
addstr("aaa");
attroff(COLOR_PAIR(cnt));
cnt++;
}
}
refresh();
getch();
endwin();
return 0;
}
After investigating, I think this gets broken around 200 or higher.
I just don't understand why this happens and how to avoid. From my understanding, I can set pair_colors up to 32768.
===
P.S.
I tried the code below as well. And it's broken.
#include <stdlib.h>
#include <ncurses.h>
int main()
{
initscr();
start_color();
// int a = 255; works
// int a = 256; prints 0 pair color
int a = 257; // broken
init_pair(a, 4, 52);
attron(COLOR_PAIR(a));
addstr("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
attroff(COLOR_PAIR(a));
refresh();
getch();
endwin();
return 0;
}
It looks like init_pair only accepts 256?