Ncurses <一>

前言: 最好的ncurses教程是 ncurses HOWTO,网上有中文版

编译ncurses引用的程序,需要加编译参数 -lncurses

并在.c文件中包含 ncurses.h头文件

1. 启动ncurses

initscr();

结束ncurse
endwin();

2. 判断是否支持彩色

has_color();

3. 进入无缓存模式

 raw();
noecho();

4. 获取输入键值

getch();

  

例子:

/** @file engine.c
* created by xx, 2013-09-25
*
* Definition of ncurses related functions
*
* This file presents ncurses implements functions of game's
* graphics
*/ #include <ncurses.h>
#include "engine.h" /** @function engine_init
*
* This function init ncurses configurations
*/ void engine_init()
{
//if(isColorEnabled() == TRUE)
//{
// console support color mode
// do something when it support color
//} //start ncurse
int ch=0;
initscr();
raw();
noecho();
printw("hello!\n");
refresh(); while( (ch=getch()) != '\n' )
{
addch(ch);
refresh();
}
} static int isColorEnabled()
{
return has_colors();
} /** @function engine_shut
* This function will shutdown mcurse
*/ void engine_shut()
{
endwin();
}

6. 判断当前console是否满足最小窗口大小

     
int win_row=0;
 int win_col=0;
getmaxyx(stdscr, win_row, win_col); if(win_row < MIN_ROW || win_col < MIN_COL)
{
game_abort("YOUR CONSOLE IS SMALLER THAN MIN WINDOW THE GAME NEEDED!");
}

  

上一篇:Python基础(字符编码与文件处理)


下一篇:五个 .NET 性能小贴士