我了解到ncurses可以支持256种颜色和32000个颜色对。虽然我已经成功地设置了256种颜色,但我找不到任何关于如何设置32000个颜色对的信息。
结果:
printf("%d - %d\n", COLORS, COLOR_PAIRS);
是
256 - 256
虽然对于喜欢使用终端的用户来说,两种颜色和两种颜色组合已经足够了,但我想知道如何从库中获取最多的颜色。
--enable-ext-colors
。您还需要 --enable-widec
(否则,存储扩展颜色的 cchar_t
类型将不会被使用)。配置脚本会发出警告:checking if you want to use extended colors... yes
configure: WARNING: This option applies only to wide-character library
ncurses
中的颜色对实际上是前景色和背景色的组合。您可以使用color_pair
(手册页面here)来操作它们。由于前景色和背景色各有256种组合,但如果将红+蓝(例如)视为蓝+红,则有256×256/2 = 32,768种组合。░░░░░░░░░░░░
)的前景+背景对生成更多颜色。请参见here。这意味着您只能同时使用This [linux] implementation will return
ERR
on attempts to use color values outside the range0
toCOLORS-1
(except for the default colors extension), or use color pairs outside the range0
toCOLOR_PAIR-1.
COLOR_PAIR
颜色对(即通过init_pair()
可用的颜色对数)-在您的实现中为256。但仍有32,768个颜色对可用,只是不能通过init_pair()
一次性使用所有这些颜色对。那就是我的理解方式。
COLOR_PAIRS
的值。你需要重新编译库。 - abligh