如何更改ncurses表单中的光标颜色? [英] How do I change the cursor color in ncurses forms?

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

问题描述

我找不到在ncurses表单库中将光标颜色从绿色更改为其他颜色的任何方法.谷歌搜索和搜索手册页中的光标或颜色没有帮助.有人知道如何做到吗?

解决方案

您可以通过编写\e]12;COLOR\a\033]12;COLOR\007来更改颜色,它们都是一样的,这里是一个简单的示例:

#include <stdio.h>
#include <unistd.h>

void cursor_set_color_string(const char *color) {
    printf("\e]12;%s\a", color);
    fflush(stdout);
}

int main(int argc, char **argv) {

    cursor_set_color_string("yellow"); sleep(1);
    cursor_set_color_string("gray"); sleep(1); 
    cursor_set_color_string("blue"); sleep(1);
    cursor_set_color_string("red"); sleep(1);
    cursor_set_color_string("brown"); sleep(1);

    return 0;
}

以下是颜色名称的列表: Xterm颜色.

看起来您也可以使用\e]12;#XXXXXX\a形式的RGB颜色:

#include <stdio.h>
#include <unistd.h>

void cursor_set_color_rgb(unsigned char red,
                          unsigned char green,
                          unsigned char blue) {
    printf("\e]12;#%.2x%.2x%.2x\a", red, green, blue);
    fflush(stdout);
}

int main(int argc, char **argv) {

    cursor_set_color_rgb(0xff, 0xff, 0xff); sleep(1);
    cursor_set_color_rgb(0xff, 0xff, 0x00); sleep(1);
    cursor_set_color_rgb(0xff, 0x00, 0xff); sleep(1);
    cursor_set_color_rgb(0x00, 0xff, 0xff); sleep(1);

    return 0;
}

I can't find any method of changing the cursor color in ncurses forms library from green to anything else. Googling and searching the manpage for cursor or color hasn't helped. Anyone know how this is done?

解决方案

You can change the color by writing \e]12;COLOR\a or \033]12;COLOR\007, they all the same, here a simple example:

#include <stdio.h>
#include <unistd.h>

void cursor_set_color_string(const char *color) {
    printf("\e]12;%s\a", color);
    fflush(stdout);
}

int main(int argc, char **argv) {

    cursor_set_color_string("yellow"); sleep(1);
    cursor_set_color_string("gray"); sleep(1); 
    cursor_set_color_string("blue"); sleep(1);
    cursor_set_color_string("red"); sleep(1);
    cursor_set_color_string("brown"); sleep(1);

    return 0;
}

Here is a list of the color names: Xterm Colors.

It looks like you can also use RGB color in the form \e]12;#XXXXXX\a:

#include <stdio.h>
#include <unistd.h>

void cursor_set_color_rgb(unsigned char red,
                          unsigned char green,
                          unsigned char blue) {
    printf("\e]12;#%.2x%.2x%.2x\a", red, green, blue);
    fflush(stdout);
}

int main(int argc, char **argv) {

    cursor_set_color_rgb(0xff, 0xff, 0xff); sleep(1);
    cursor_set_color_rgb(0xff, 0xff, 0x00); sleep(1);
    cursor_set_color_rgb(0xff, 0x00, 0xff); sleep(1);
    cursor_set_color_rgb(0x00, 0xff, 0xff); sleep(1);

    return 0;
}

这篇关于如何更改ncurses表单中的光标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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