Why is this text not ncurses colored?

I wanted to create a window in ncurses, surround it with a box and write colored text in it.

When I try to make plain color text in a standard window, it works fine, but when I try to put it in a new window, the text looks white on black (i.e. by default)

Here is the code I tried. Why is this not working?

#include <ncurses.h>

int main(int argc, char *argv[])
{
    initscreen();
    WINDOW * win = newwin(8,15,1,1);
    box(win,0,0);
    start_color();
    init_pair(1, COLOR_BLACK, COLOR_RED);
    attron(COLOR_PAIR(1));
    mvwprintw(win,1,1,"colored text");
    wrefresh(win);
    getch();
    return 0;
}
+4
source share
1 answer

I solved the problem using

wattron(win, COLOR_PAIR(1));

instead

attron(COLOR_PAIR(1));

wattronaffects this window, but attronassumes what you mean stdscr, not the current window.

+11
source

Source: https://habr.com/ru/post/1527746/


All Articles