In version 6.1, ncurses introduce init_extended_pair to extend limit of possible color pairs above short
limit.
In my experiment everything works till value 255. For values 256 and greater, there is no error, but foreground and background have default values. For values 32767 and greater function return error.
Program return:
COLOR_PAIRS: 65536
Error: 32767
What is the proper why to create large number of color pairs? In my case I need at least 65536 of them. (Tested on Ubuntu 19.04)
#include <iostream>
#include <ncurses.h>
// g++ main.cpp -l:libncursesw.so.6.1 -ltinfo
int main() {
initscr();
start_color();
std::cout << "COLOR_PAIRS: " << COLOR_PAIRS << std::endl;
init_extended_color(2, 999, 0, 0);
init_extended_color(3, 0, 999, 0);
int pair1 = 255;
if (init_extended_pair(pair1, 2, 3) == ERR)
std::cout << "Error: " << pair1 << std::endl;
attron(COLOR_PAIR(pair1));
mvprintw(2, 1, "pair255");
attroff(COLOR_PAIR(pair1));
int pair2 = 256;
if (init_extended_pair(pair2, 2, 3) == ERR)
std::cout << "Error: " << pair2 << std::endl;
attron(COLOR_PAIR(pair2));
mvprintw(3, 1, "pair256");
attroff(COLOR_PAIR(pair2));
int pair3 = 32767; // 2^15-1
if (init_extended_pair(pair3, 3, 2) == ERR)
std::cout << "Error: " << pair3 << std::endl;
attron(COLOR_PAIR(pair3));
mvprintw(4, 1, "pair32767");
attroff(COLOR_PAIR(pair3));
refresh();
getch();
endwin();
return 0;
}
Edit:
Regarding similar problem How to enable 32k color pairs in ncurses?. In my case COLOR_PAIRS
return value 65536 not 256, more over question is from 2015, and init_extended_pair
was added to library on 2017.04.01, and released in version 6.1 January 27, 2018. Despite this I rebuild libncursesw6 package with --enable-ext-colors
(--enable-widec
was already available), but I get same result.