【发布时间】:2019-09-22 03:09:36
【问题描述】:
在 6.1 版中,ncurses 引入了init_extended_pair 以将可能的颜色对的限制扩展到short 限制之上。
在我的实验中,直到值 255 为止一切正常。对于 256 或更大的值,没有错误,但前景和背景具有默认值。对于 32767 及更大的值,函数返回 error。
程序返回:
COLOR_PAIRS: 65536
Error: 32767
创建大量颜色对的正确原因是什么?就我而言,我至少需要 65536 个。 (在 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;
}
编辑:
关于类似问题How to enable 32k color pairs in ncurses?。在我的情况下,COLOR_PAIRS 返回值 65536 而不是 256,更多问题来自 2015 年,init_extended_pair 于 2017.04.01 和released in version 6.1 January 27, 2018 添加到库中。尽管如此,我还是使用 --enable-ext-colors 重建了 libncursesw6 包(--enable-widec 已经可用),但我得到了相同的结果。
【问题讨论】:
-
嗨@MarcSances,恐怕这不是我的问题。我正在使用更新的 API -
init_extended_pair在 2015 年不可用,COLOR_PAIRS返回值65536而不是256。
标签: c++ colors terminal console ncurses