How do i use more than 8 colors in ncurses?

烂漫一生 提交于 2019-12-13 02:25:20

问题


I just started to use ncurses on Linux. I wanted to use more than 8 colors, but there were only 8 available.

How can I use more colors, or create my own by giving them a names, and set their RGB values?

I tried editing a color with init_color, but that will simply replace one of the current 8 instead of creating new ones.

Note: the value of the global var COLORS is 256, so I believe I can use up to 256 different colors.


回答1:


If your terminal supports it, you should choose (or customize) a terminal description which has more than 8 colors. As it is, there are a lot of existing terminal descriptions which could be used: most are customized for particular terminals (or terminal emulators).

If your terminal supports it, the corresponding description would have the capability initc. That is used by the library call init_color. The xterm-256color entry has this for instance:

initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,

which tells the library how to translate the three parameters into an escape sequence. The terminal entries are built up from reusable parts such as xterm+256color, because some terminals lack the feature you are interested in. For those, xterm+256setaf is appropriate.

For reference,

  • Terminal Database Most systems have this as base (small) and extra (large) packages.
  • start_color, init_pair, init_color, has_colors, can_change_color, color_content, pair_content, COLOR_PAIR - curses color manipulation routines
  • My terminal doesn't recognize color
  • Why only 16 (or 256) colors?


来源:https://stackoverflow.com/questions/35945710/how-do-i-use-more-than-8-colors-in-ncurses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!