简体   繁体   中英

Color at specific point - ncurses

I'm trying to color at a specific point of the screen using ncurses lib.
I have written this code:

#include<curses.h>

int main(void)
{
    initscr();
    start_color();
    init_pair(1, COLOR_BLACK, COLOR_RED);
    attron(COLOR_PAIR(1));
    move(10, 10);
    printw(" \n");
    refresh();
    getch();
    endwin();

    return 0;
}

There is a better way to do this? Or this is the only way?

Have a look at mvchgat() for changing the color (and other attributes) of an already-existing character.
You can also use mvaddch (10, 10, ' ' | COLOR_PAIR(1)) to move the cursor and output a space character with a custom color (or other attributes).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM