How do i use more than 8 colors in ncurses?

2019-08-15 05:27发布

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.

标签: c linux ncurses
1条回答
迷人小祖宗
2楼-- · 2019-08-15 05:37

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,

查看更多
登录 后发表回答