简体   繁体   中英

Unable to change terminal background with NCurses

Okay so I am trying to change the terminal background with the NCurses library for C++.

Here is my code:

int ncurses_test()
{
     initscr();
     start_color();
     init_pair(1, COLOR_GREEN, COLOR_BLACK);
     init_pair(2, COLOR_GREEN, COLOR_BLACK);
     init_pair(3,COLOR_BLUE, COLOR_RED);
     wbkgd(WINDOW,COLOR_PAIR(3))
     noecho();
     raw();
     int c;
     attron(COLOR_PAIR(1));
     printw("Write something [ESC to escape]: ");
     while((c=getch())!=27)
     {
            move(10,0);
            attron(COLOR_PAIR(1));
            printw("Keycode: %d, and the chracter: %c",c,c);
            move(0,0);
            attron(COLOR_PAIR(1));
            printw("Write something [ESC to escape]: ");
            refresh();

     }
     endwin();
     return 0;
}

I get an error when compiling the file. Here is the error:

main.cpp: In function 'int ncurses_test()':
main.cpp:27:18: error: expected primary-expression before ',' token
      wbkgd(WINDOW,COLOR_PAIR(3))

Does anyone have any ideas?

Okay I managed to get my code to work:

int ncurses_test()
{
     initscr();
     start_color();
     init_pair(1, COLOR_GREEN, COLOR_BLACK);
     init_pair(2, COLOR_GREEN, COLOR_BLACK);
     init_pair(3, COLOR_BLACK, COLOR_BLUE);
     init_pair(4, COLOR_BLACK, COLOR_WHITE);
     noecho();
     WINDOW *win = newwin(10, 10, 10, 10);
     wbkgd(stdscr, COLOR_PAIR(3));
     wbkgd(win, COLOR_PAIR(4));
     refresh();
     wrefresh(win);
     raw();
     int c;
     attron(COLOR_PAIR(1));
     printw("Write something [ESC to escape]: ");
     while((c=getch())!=27)
     {
            move(10,0);
            attron(COLOR_PAIR(1));
            printw("Keycode: %d, and the chracter: %c",c,c);
            move(0,0);
            attron(COLOR_PAIR(1));
            printw("Write something [ESC to escape]: ");
            refresh();

     }
     endwin();
     return 0;
}

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