How do I change the cursor color in ncurses forms?

心不动则不痛 提交于 2019-12-01 09:50:05

问题


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?


回答1:


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;
}


来源:https://stackoverflow.com/questions/18425103/how-do-i-change-the-cursor-color-in-ncurses-forms

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