gpt4 book ai didi

ruby - 256 种颜色,前景和背景

转载 作者:数据小太阳 更新时间:2023-10-29 07:04:58 25 4
gpt4 key购买 nike

这是两个脚本的故事,与 previous question 有关.

这两个脚本位于 http://gist.github.com/50692 . ansi.rb 脚本在所有 256 种背景颜色上显示所有 256 种颜色。 ncurses.rb 脚本显示所有 256 种前景颜色,但背景显示基本的 16 种颜色,然后似乎循环显示各种属性,如闪烁和反向视频。

那么是什么给了?这是 ncurses 中的错误,它使用带符号的整数来表示颜色对吗? (即'tput colors'表示256但'tput pairs'表示32767而不是65536)似乎如果是这种情况,颜色对的前半部分会正确显示但后半部分会重复或进入属性作为int包裹。

最佳答案

原因是因为 ncurses pre ABI 6,它包括包括 Debian 和 Amazon AMI 在内的大多数发行版使用的当前版本,COLOR_PAIR(n) 不能引用任何超过 256 的定义对。这是因为COLOR_PAIR(n) 的参数是 cchar_t 类型。低 8 位选择颜色对,其余的被视为位标志 OR 用于特定终端属性。这就是为什么当您尝试超出示例代码中的第 255 对时会看到闪烁、反色、下划线等。

这非常不幸,我计划在我的程序中使用一个队列来使用 init_pair() 动态定义颜色,并且只是覆盖最近最少使用的对作为折衷方案。我写信给 ncurses 维护者 Thomas Dickey,询问是否有办法暂时离开 ncurses 以编写原始终端代码,然后返回到 ncurses。这是他的回复:

Essentially you'd have to forget about screen-optimization and just do your own drawing using the functions listed in terminfo(3), e.g., tigetstr, mvcur, tputs.

You can exit temporarily from ncurses, but then have to repaint the screen. Otherwise ncurses will be confused about what is on the screen and where the cursor is.

这个解决方案似乎存在太多陷阱,但如果您在 ncurses 程序中绝对需要超过 256 个同时对(不包括您可以使用 inverse 属性伪造的对),那么这就是您必须做的。

关于ruby - 256 种颜色,前景和背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/476878/

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