|
|

#include <ncurses.h>
initscr() 开始curses模式,可能由于内存不足而分配空间失败
refresh() 刷新屏幕
endwin() 结束curses模式,释放curses分配的内存并把终端置回普通模式
当前window称为stdscr
第4章 初始化
raw() buffer disabled,捕获所有按键,ctrl-c,ctrl-z等按键不产生中断
cbreak() buffer disabled,ctrl-c,ctrl-z等产生中断
echo() noecho() 显/不显示按键输出
keypad() enable功能键,箭头键等.用法keypad(stdscr, TRUE)
halfdelay() buffer disabled, 有时间限制的输入.it waits for 'X' tenths of a second for input and then returns ERR, if no input is available. 'X' is the timeout value passed to the function halfdelay(). This function is useful when you want to ask the user for input, and if he doesn't respond with in certain time, we can do some thing else. One possible example is a timeout at the password prompt.
第5章 窗口
printw() 于printf对应的curses模式的标准输出
KEY_F(1) curses.h里定义的对应功能键的宏
attron(A_BOLD) 设置粗体属性
attroff(A_BOLD) 取消粗体属性
wprintw(win, "HI") 输出到指定窗口
wrefresh(win) 刷新指定窗口
mvprintw(y,x,string) 移动到(y,x)打印string(字符串指针)
mvwprintw(win,y,x,string) 移到相对win窗口的(y,x)并输出string
第6章 输出
addch() 输出单个带属性的字符
printw() 格式化输出,像printf()
addstr() 输出字符串
详解:
addch(): 输出字符到当前光标位置并把光标前进一位
两种方法输出带属性字符:
或形式: addch(ch | A_BOLD | A_UNDERLINE);
用attrset(),attron(),attroff()等函数.
curses提供基于字符的画图.可画表单,横竖线等.尝试在ncurses.h里查找以ACS_开头的宏.
mvaddch(row,col,ch) 移到指定位置输出字符
waddch() 在指定窗口输出字符
mvwaddch() 在指定窗口移到指定位置输出字符
mvprintw() 移到指定位置输出
wprintw() 在指定窗口输出
mvwprintw() 在指定窗口移到指定位置输出
vwprintw() 与vprintf()类似,可用于可变参数输出This can be used when variable number of arguments are to be printed.
getmaxyx(stdscr, row, col) 取stdscr窗口的行数和列数
mvaddstr(), mvwaddstr(), waddstr()服从类似命名规则
addnstr() 多带一个n参数,输出最多n个字符到屏幕.若n为负,输出整个字符串.
第7章 输入
getch() 读入一个字符
scanw() 与scanf()类似,可从屏幕任意位置读入
mvscanw()
wscanw(), mvwscanw()
vwscanw() 与vscanf()类似,This can be used when a variable number of arguments are to be scanned.
getstr(str) 读入字符串,字符串存在str中
wgetstr()
第8章 属性
getyx(stdscr, y, x) 取stdscr窗口当前光标位置,存在y和x中.注意:这是宏,所以不必传址
clear() 清楚屏幕
move(0, 0) 移动光标到(0,0)
attron(),attroff() 属性设置on/off
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
COLOR_PAIR(n) Color-pair number n
用或的形式取得组合效果,例如attron(A_REVERSE | A_BLINK);
attron()在原来属性基础上加入参数里的属性设置.attrset()舍弃以前所有设置,把属性设为参数中的.
attroff()在原来属性基础上取消参数里的属性设置.
standend() 相当于attrset(A_NORMAL),关闭所有属性,回到普通模式.
attr_get() 取得窗口当前的属性和颜色对.
chgat() 不改变光标位置,改变从当前光标位置起到指定长度的字符的属性.长度为-1表示更新到行结束(end of line).
chgat(-1, A_REVERSE, 0, NULL);
wchgat(), mvchgat(), wchgat()
init_pair(1, COLOR_CYAN, COLOR_BLACK) 设置颜色对.
mvchgat(0, 0, -1, A_BLINK, 1, NULL) 移到(0,0),-1表示更新到行尾,A_BLINK属性,1表示上面init_pair函数的第1个参数设置的颜色对号码,最后一个参数总是NULL.
第9章 窗口
newwin() 创建window.为window分配内存,不显示在屏幕上.返回指向WINDOW结构的指针.
delwin() 毁灭窗口.
box(0, 0) 在窗口周围画框.0,0给默认的垂直和水平画线字符
wborder(local_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ')
8个' '依次为左,右,上,下,左上,右上,左下,右下
COLS, LINES 变量,在initscr()后被初始化,存储当前屏幕大小.
mvhline(), mvvline() 在指定位置创造一个水平(h)或垂直(v)线
mvhline(y, x+1, p_win->border.ts, w-1) 移到(y,x+1)画w-1个ts字符
start_color() 开始颜色功能
第10章 颜色
has_colors() 测试中断有无颜色显示功能,返回TRUE或FALSE
start_color() 开始颜色功能
attron(COLOR_PAIR(1)) 设置属性为以前属性加颜色对1
COLOR_BLACK 0
COLOR_RED 1
COLOR_GREEN 2
COLOR_YELLOW 3
COLOR_BLUE 4
COLOR_MAGENTA 5
COLOR_CYAN 6
COLOR_WHITE 7
init_color() 改变由curses初始的颜色的rgb值
init_color(COLOR_RED, 700, 0, 0) 改变COLOR_RED,二,三,四参数为rgb值,min=0,max=1000.若终端不能改变颜色,函数返回ERR
can_change_color() 测试终端有无改变颜色内容的能力.
color_content() pair_content() 查颜色内容和前景,背景颜色组合对.
第11章 键盘
getch() 读入一个字符,若字符为普通字符,返回对应的值,若为其他字符则返回在curses.h里定义的对应的常量.注意此时返回值可能比char大,所以要用int型.
第12章 鼠标
mousemask(mmask_t newmask, /* The events you want to listen to */
mmask_t *oldmask) /* The old events mask */
设置监听.第一个参数是想监听的bit mask,默认全部不监听.
以下是所有event masks:
Name Description
---------------------------------------------------------------------
BUTTON1_PRESSED mouse button 1 down
BUTTON1_RELEASED mouse button 1 up
BUTTON1_CLICKED mouse button 1 clicked
BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked
BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked
BUTTON2_PRESSED mouse button 2 down
BUTTON2_RELEASED mouse button 2 up
BUTTON2_CLICKED mouse button 2 clicked
BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked
BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked
BUTTON3_PRESSED mouse button 3 down
BUTTON3_RELEASED mouse button 3 up
BUTTON3_CLICKED mouse button 3 clicked
BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked
BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked
BUTTON4_PRESSED mouse button 4 down
BUTTON4_RELEASED mouse button 4 up
BUTTON4_CLICKED mouse button 4 clicked
BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked
BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked
BUTTON_SHIFT shift was down during button state change
BUTTON_CTRL control was down during button state change
BUTTON_ALT alt was down during button state change
ALL_MOUSE_EVENTS report all button state changes
REPORT_MOUSE_POSITION report mouse movement
一旦监听,getch()类函数在鼠标事件发生时返回KEY_MOUSE.然后可用getmouse()取得鼠标事件.程序大致如下:
MEVENT event;
ch = getch();
if(ch == KEY_MOUSE)
if(getmouse(&event) == OK)
. /* Do some thing with the event */
.
.
getmouse()把事件保存到传入的指针所指内存.指针所指类型的结构为:
typedef struct
{
short id; /* ID to distinguish multiple devices */
int x, y, z; /* event coordinates */
mmask_t bstate; /* button state bits */
}
其中bstate标示了鼠标状态.
监测鼠标事件如下:
if(event.bstate & BUTTON1_PRESSED)
printw("Left Button Pressed");
mouse_trafo() wmouse_trafo() 用来把鼠标坐标转换为屏幕相对坐标.查看curs_mouse(3X)的man文档.
mouseinterval函数 sets the maximum time (in thousands of a second) that can elapse between press and release events in order for them to be recognized as a click. This function returns the previous interval value. The default is one fifth of a second.
第13章 屏幕操纵
getyx(win, y, x) 取得window的光标当前所在
getparyx() 取得子窗口的相对主窗口的开始坐标.When designing fancy stuff like writing multiple menus, it becomes difficult to store the menu positions, their first option co-ordinates etc. A simple solution to this problem, is to create menus in sub windows and later find the starting co-ordinates of the menus by using getparyx().
getbegyx() getmaxyx() 保存当前窗口的开始和最大坐标.These functions are useful in the same way as above in managing the windows and sub windows effectively.
scr_dump() 把屏幕内容dump到参数指定的文件中.
scr_restore() 把scr_dump()产生的指定文件的内容dump到屏幕
putwin() 把当前窗口状态放到文件
getwin() 把由putwin()产生的指定文件恢复为窗口状态
putwin() puts the present window state into a file, which can be later restored by getwin().
第14章 其他特性
curs_set() 设置光标可见性.参数0:不可见,1:普通,2:very visible
def_prog_mode() 保存tty模式
reset_prog_mode() 返回由def_prog_mode()保存的tty模式
第16章 面板库
#include <panel.h>
new_panel() 创建面板
update_panels() 把面板以正确的可见顺序写入虚拟屏幕
doupdate() 把面板显示到屏幕上
hide_panel() 隐藏面板.只从面板堆栈中移除,并不是消毁面板的数据
show_panel() 显示隐藏的面板
move_panel() 移动面板到指定位置,不改变在面板栈里的位置.注意:确保用move_panel()而不是mvwin()来移动于面板相关联的窗口
panel_hidden()
panel_window()
可以给面板attch上自定义信息指针,指针可指向任意内容.
set_panel_userptr() 设置面板的用户指针
panel_userptr() 取得面板的用户指针
del_panel() 删除面板
PANEL *mypanel 面板指针
mypanel = new_panel(my_win) 把窗口绑定到面板,以调用次序压栈,栈顶完全可见
top_panel() 把指定面板带到最前面
replace_panel() 改变(replace)与面板相关联的窗口
panel_window() 返回于指定面板相关联的窗口指针
clrtoeol() 清除从光标处直至一行结束
panel_above() 返回指定面板的上层面板指针.若参数为NULL,返回最顶层面板指针
panel_below() 返回指定面板的下层面板指针.若参数为NULL,返回最底层面板指针 |
|