ncurses多种颜色在屏幕上

我想用ncurses.h和多种颜色做一个菜单.
我的意思是这样的:
┌────────────────────┐
│░░░░░░░░░░░░░░░░░░░░│ <- color 1
│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│ <- color 2
└────────────────────┘

但是如果我使用init_pair(),attron()和attroff(),整个屏幕的颜色是一样的,而不是像我所料.

initscr();

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

attron(0);
printw("This should be printed in black with a red background!\n");
refresh();

attron(1);
printw("And this in a green background!\n");
refresh()    

sleep(2);

endwin();

这段代码有什么问题?

感谢每一个答案!

解决方法

这是一个工作版本:
#include <curses.h>

int main(void) {
    initscr();
    start_color();

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

    attron(COLOR_PAIR(1));
    printw("This should be printed in black with a red background!\n");

    attron(COLOR_PAIR(2));
    printw("And this in a green background!\n");
    refresh();

    getch();

    endwin();
}

笔记:

>你需要在initscr()之后调用start_color()来使用颜色.
>您必须使用COLOR_PAIR宏将分配给init_pair的颜色对传递给attron等.
>你不能使用颜色对0.
>你只需要调用refresh()一次,只有当你想要在这一点上看到你的输出,而不是调用像getch()这样的输入函数.

This HOWTO是非常有帮助的.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...