ncurses multi colors on screen

后端 未结 2 534
予麋鹿
予麋鹿 2020-12-11 02:13

I want to make a menu with ncurses.h and more than one color. I mean something like this:

┌────────────────────┐
│░░░░░░░░░░░░░░░░░░░░│ <- co         


        
2条回答
  •  再見小時候
    2020-12-11 02:37

    You need to initialize colors and use the COLOR_PAIR macro.

    Color pair 0 is reserved for default colors so you have to start your indexing at 1.

    ....
    
    initscr();
    start_color();
    
    init_pair(1, COLOR_BLACK, COLOR_RED);
    init_pair(2, COLOR_BLACK, COLOR_GREEN);
    
    attron(COLOR_PAIR(1));
    printw("This should be printed in black with a red background!\n");
    
    ....
    

提交回复
热议问题