0

I'm working with ncurses on Linux, I have created two windows (winReception and winTransmission) basically winTransmission is for writing stuff to print in winReception. So, I'd like to print the text in winReception in certain color but it's not working it prints normally, no colors.

Any thoughts on why it's not working? I tried changing the colors of the window instead but it changes the color of all the text in the window, which is not what I want.

Edit: Forgot to mention that winTransmission do not need to change colors. Only winReception needs to change colors.

Here is the code you need to understand what I'm doing:

    initscr();

    /* WINDOW RECEPTION */
    winReception = newwin(27, 0, 0, 0);

    /* WINDOW TRANSMISSION */
    winTransmission = newwin(8, 0, 27, 0);

    if (!has_colors()) {
        endwin();
        fprintf(stderr, "Error - no color support on this terminal\n");
        exit(1);
    }

    if (start_color() != OK) {
        endwin();
        fprintf(stderr, "Error - could not initialize colors\n");
        exit(2);
    }

    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_RED, COLOR_GREEN);


    attrset(COLOR_PAIR(1));
    /* WINDOW RECEPTION */
    mvwprintw(winReception, 1, 2, "%s", textinwindow);
    wrefresh(winReception);

    /* WINDOW TRANSMISSION */
    touchwin(winTransmission);
    wclear(winTransmission);
    wrefresh(winTransmission);
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
KanerDev
  • 23
  • 6

1 Answers1

0

The only place you are setting a color attribute is

attrset(COLOR_PAIR(1));

but that is applied only to stdscr

Perhaps you meant

wattrset(winReception, COLOR_PAIR(1));
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Yeah, I did that but it changes the color of the whole window (all the text). But I want some lines to be written in RED on Black and some in Red on GREEN. – KanerDev Nov 20 '19 at 02:20