gpt4 book ai didi

c - ncurses color_content() 给了我错误的值

转载 作者:行者123 更新时间:2023-11-30 16:34:56 25 4
gpt4 key购买 nike

我正在使用xterm-256color。这是我的简短程序片段:

  mvwprintw(stdscr,1,1,"You have %d colors",COLORS);
mvwprintw(stdscr,2,1,"You have %d color pairs",COLOR_PAIRS);
wprintw(stdscr,"\n\n");
for (i=1;i<10;i++)
{
short r,g,b;
short thiscolor=i+70;
init_pair(i,thiscolor,COLOR_BLACK);
color_content(thiscolor,&r,&g,&b);
wattron(stdscr,COLOR_PAIR(i));
wprintw(stdscr,"This is color %d\t%d %d %d\n",thiscolor,r,g,b);
wattroff(stdscr,COLOR_PAIR(i));
}
refresh();

它打印出 10 种不同深浅的绿色,但 color_content 的输出与其打印的绿色不匹配:

 You have 256 colors
You have 256 color pairs

This is color 71 1000 1000 1000
This is color 72 0 0 0
This is color 73 1000 0 0
This is color 74 0 1000 0
This is color 75 1000 1000 0
This is color 76 0 0 1000
This is color 77 1000 0 1000
This is color 78 0 1000 1000
This is color 79 1000 1000 1000

我希望看到中间值 (G) 始终是一个相当高的数字。我不会预计会看到 0。

我做错了什么吗?或者我误解了 color_content 应该输出什么?

最佳答案

ncurses 无法预知给定终端仿真器使用的调色板。除非您初始化颜色 (init_color),否则它只有内置表。没有可移植的方法来确定终端的调色板。

关于 start_color 的部分手册上说

  • If the terminal supports the initc (initialize_color) capability, start_color initializes its internal table representing the red, green and blue components of the color palette.

    The components depend on whether the terminal uses CGA (aka "ANSI") or HLS (i.e., the hls (hue_lightness_saturation) capability is set). The table is initialized first for eight basic colors (black, red, green, yellow, blue, magenta, cyan, and white), and after that (if the terminal supports more than eight colors) the components are initialized to 1000.

    start_color does not attempt to set the terminal's color palette to match its built-in table. An application may use init_color to alter the internal table along with the terminal's color.

“初始化为 1000”可能更清楚。该库使用 8 种 ANSI 颜色中的红/绿/蓝图案作为在前 8 种颜色之后重复使用的内容(使用 1000 作为非零值)(请参阅 source-code ...)。

这是库中内置的默认。如果您想要不同的东西,您必须使用 init_color 告诉它那是什么。 。 ncurses-examples有一些程序(ncurses、picsmap、savescreen)可以使用的示例调色板数据文件来实现此目的。

关于c - ncurses color_content() 给了我错误的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49134336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com