ncurses多种颜色在屏幕上
发布时间:2020-12-16 03:25:02 所属栏目:百科 来源:网络整理
导读:我想用ncurses.h和多种颜色做一个菜单. 我的意思是这样的: ┌────────────────────┐│????????????????????│ - color 1│????????????????????│ - color 2└────────────────────┘ 但是如果我使用init_pair(),
我想用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()来使用颜色. This HOWTO是非常有帮助的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |