【发布时间】:2015-06-12 16:39:28
【问题描述】:
我正在尝试进入 ncurses 库。我对 Gnome 终端可以通过 ANSI 转义字符打印红色而不是 ncurses 中预定义的红色感到失望。
#include <curses.h>
void init_colors() {
int a;
for(a = 1; a < COLORS; a++) {
init_pair(a, a, COLOR_BLACK);
}
}
void print_colors() {
int a;
for(a = 1; a < COLORS; a++) {
attron(COLOR_PAIR(a));
mvprintw(a, 0, "color");
attroff(COLOR_PAIR(a));
}
}
int main() {
initscr();
cbreak();
noecho();
curs_set(0);
if(has_colors())
start_color();
init_colors();
print_colors();
getch();
endwin();
return 0;
}
这应该以任何默认 ncurses 颜色打印单词“color”,但第二行(init_pair 应该将第二个 COLOR_PAIR 初始化为 red ) 根本不打印。似乎 Gnome 终端只是跳过了这一行。我该如何解决这个问题?
【问题讨论】:
-
可以打印其他颜色吗?还是只是红色失败了?
-
@MooingDuck 我可以毫无问题地打印任何其他预定义颜色:包括黑色、绿色、黄色、蓝色、洋红色、青色和白色。
-
这可能是本地问题或您的
gnome-terminal中的设置。它适用于 3.14.2。
标签: c ubuntu terminal ncurses gnome