更改颜色定义ncurses C [英] Changing Color Definitions ncurses C

查看:128
本文介绍了更改颜色定义ncurses C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习ncurses,我已经编写了一个小程序,我想用一种颜色填充我的窗口.

I am learning ncurses and I have made a little program and I want to fill my window with a color.

我想用红色填充它,但是默认的COLOR_RED是明亮的,让您发疯:) 这是我尝试过的.

I want to fill it with a Red color but the default COLOR_RED is to bright and drives you crazy :) Here is what I tried.

    WINDOW *wnd = initscr();

    start_color();

    init_color(COLOR_RED, 184, 142, 12);

    init_pair(1, COLOR_WHITE, COLOR_RED);

    wbkgd(wnd, COLOR_PAIR(1));
    refresh();

如何使用修改后的颜色?

How can I use a modified color ?

P.S:代码使背景仍然是旧的COLOR_RED,而不是我修改过的背景.

P.S : The code makes the background still the old COLOR_RED, not my modified one.

推荐答案

init_color()是创建颜色定义的方式.但是,如果您的终端支持8种以上的颜色,则只能创建新"颜色.大多数终端都启用,但是默认情况下不启用此功能.要进行检查,请像下面这样在ncurses库中打印COLORS变量:

init_color() is how you create a color definition. However, you can only create "new" colors if your terminal supports more than 8 colors. Most terminals do, but do not enable this by default. To check, print the COLORS variable in the ncurses library like so:

#include <ncurses.h>
printw("My terminal supports %d colors.\n", COLORS);

如果结果是8,则只能修改默认颜色,而不能定义自己的颜色.为了能够定义自己的颜色,您将需要使用支持8种以上颜色的终端.为此,请在命令行上尝试以下操作:

If it comes out to be 8, you will only be able to modify the default colors instead of defining your own. To be able to define your own colors, you will need to use a terminal that supports more than 8 colors. To do this try the following on the command line:

echo $TERM

如果结果是xterm-color,请在命令行中键入以下内容以启用256色终端:

If this comes out to be xterm-color, then type the following at the command line to enable a 256 color terminal:

export TERM=xterm-256color

然后再次检查COLORS变量.如果一切顺利,应该将其更新为256.现在,您可以使用init_color()定义自己的颜色.

Then check the COLORS variable again. It should be updated to 256, provided all went well. You can now use init_color() to define your own colors.

有关ncurses例程的更多信息,请参见: http://invisible-island.net/ncurses/man/curs_color.3x.html#h3-例程说明

More information on ncurses routines can be found here: http://invisible-island.net/ncurses/man/curs_color.3x.html#h3-Routine-Descriptions

这篇关于更改颜色定义ncurses C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆