linux-c-curses(1)-颜色+中文1、初始化颜色//init_pair(short index,short foreground,short background)初
linux-c-curses(1)-颜色+中文
1、初始化颜色
//init_pair(short index,short foreground,short background)初始化颜色索引
//attron(COLOR_PAIR(索引号)|属性)
属性如下:
??? ?A_NORMAL? ?? ?? ?Normal display (no highlight)
? ???A_STANDOUT? ?? ? Best highlighting mode of the terminal.亮色
? ???A_UNDERLINE? ?? ?Underlining
? ???A_REVERSE? ?? ???Reverse video
? ???A_BLINK? ?? ?? ? Blinking闪烁
? ???A_DIM? ?? ?? ?? ?Half bright半亮度
? ???A_BOLD? ?? ?? ???Extra bright or bold高亮度
? ???A_PROTECT? ?? ???Protected mode
? ???A_INVIS? ?? ?? ? Invisible or blank mode
? ???A_ALTCHARSET? ???Alternate character set另类字符集
? ???A_CHARTEXT? ?? ? Bit-mask to extract a character
2、编译:
1)必须安装cursesew库
sudo apt-get install libncursesw5-dbg libncursesw5-dev
2)编译
mysea@mysea-desktop:~/test$ gcc -lncursesw -std=c99 -o cursestest cursestest.c
cursestest.c: In function ‘main’:
cursestest.c:12: warning: implicit declaration of function ‘exit’
cursestest.c:12: warning: incompatible implicit declaration of built-in function ‘exit’
mysea@mysea-desktop:~/test$ ./cursestest
?

?3、代码
#include <ncursesw/ncurses.h>#include <locale.h>int main(void){//init_pair(short index,short foreground,short background)初始化颜色索引//attron(COLOR_PAIR(索引号)|属性)?? ?setlocale(LC_ALL,"");?? ?initscr();//初始化?? ?box(stdscr,ACS_VLINE,ACS_HLINE);//画边框?? ?if (!has_colors()||start_color()==ERR){?? ? ? ?endwin();?? ? ? ?printf("终端不支持颜色\n");?? ? ? ?exit(1);?? ?}?? ?init_pair(1,COLOR_GREEN,COLOR_BLACK);?? ?init_pair(2,COLOR_RED,COLOR_BLACK);?? ?init_pair(3,COLOR_WHITE,COLOR_BLUE);?? ?for (int i=1;i<=3;i++){?? ? ? ? attron(COLOR_PAIR(i));?? ? ? ? move(i,10);?? ? ? ? printw("deepfuture.iteye.com颜色:%d",i);?? ?}?? ?for (int i=1;i<=3;i++){?? ? ? ? attron(COLOR_PAIR(i)|A_UNDERLINE);?? ? ? ? move(i+5,10);?? ? ? ? printw("deepfuture.iteye.com颜色+下划线:%d",i);?? ?}?? ?refresh();//刷新屏幕?? ?getch();//等待按键?? ?endwin();//结束?? ?return 0; ? ?}
1 楼 zhou347742 2012-05-25 师父,如何用ncurses在终端内画一个图形方框? 2 楼 deepfuture 2012-05-25 首先计算圆的每一点的坐标,然后在坐标处画点 3 楼 zhou347742 2012-05-25 deepfuture 写道首先计算圆的每一点的坐标,然后在坐标处画点
师父,我说得是那种正方形的小方框...