先生们,有人可以告诉我,问题出在哪里吗?为什么我看不到彩色文本/背景?
#include <ncurses.h>
int main()
{
initscr();
int lines = 20;
int cols = 30;
int y = 1;
int x = 1;
WINDOW* win = newwin(lines, cols, y, x);
start_color();
init_pair(1, COLOR_WHITE, COLOR_RED);
attrset(COLOR_PAIR(1));
mvwprintw(win, 2, 2, "Some words...\n\n");
attroff(COLOR_PAIR(1));
wrefresh(win);
return 0;
}
我想知道如何在 ncurses 窗口中显示彩色文本/背景。
还有更多问题:
你没有正确结束ncurses
您为默认窗口设置了颜色(对于名为
screen
的窗口),但您使用了打印到自己的窗口。
#include <ncurses.h>
int main()
{
int lines = 20;
int cols = 30;
int y = 1;
int x = 1;
WINDOW* win;
initscr();
start_color();
win = newwin(lines, cols, y, x);
init_pair(1, COLOR_WHITE, COLOR_RED);
wattron(win, COLOR_PAIR(1));
mvwprintw(win, 2, 2, "Some words...\n\n");
wattroff(win, COLOR_PAIR(1));
wrefresh(win);
/* wait on press any key */
getchar();
/* close ncurses */
endwin();
return 0;
}