基本 initscr(); 進入 curses 的第一個函式 endwin(); 暫時跳離 curses 模式 def_prog_mode(); 儲存目前的 tty 模式 reset_prog_mode(); 回復到先前儲存的 tty 模式 輸入控制 cbreak(), nocbreak(); cbreak 可以讓程式立即讀取使用者輸入的字元 (不需要按 Enter) raw(), noraw(); 類似 cbreak,但可以讓特殊按鍵不產生 signal echo(), noecho(); noecho 可以在輸入螢幕不顯示任何東西 keypad(WINDOW *win, bool bf); 範例:keypad(stdscr, TRUE); 啟動 keypad 可以將多字元的按鍵自動轉換成單一數值 nodelay(WINDOW *win, bool bf); 範例:nodelay(stdscr, FALSE); 啟動 nodelay 會使執行 getch 不等待使用者按鍵,如果讀不到字元就回傳 ERR intrflush(WINDOW *win, bool bf); 範例:intrflush(stdscr, FALSE); 關閉 intrflush 可避免中斷按鍵導致的 flush qiflush(), noqiflush(); noqiflush 避免 INTR、QUIT、SUSP 造成 I/O queue 的 flush 可用於 signal handler 輸出控制 curs_set(int visibility); 設定游標可見程度 0 : invisible 1 : normal 2 : very visible refresh(), wrefresh(WINDOW* win); 更新螢幕上的文字 clear() 清空螢幕內容 nl(), nonl(); nonl 會使送出 '\n' 不加上 CR (carriage return) redrawwin(WINDOW *win); wredrawln(WINDOW *win, int beg_line, int num_lines); 將整個螢幕或特定的幾行標記為已修改 下次 refresh 時 curses 會去重繪這幾行 輸出文字的屬性 attroff(int attrs); wattroff(WINDOW *win, int attrs); attron(int attrs); wattron(WINDOW *win, int attrs); 設定文字輸出的屬性 屬性表 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 attrset(int attrs); 設定文字輸出的屬性,套用至所有 window chgat(int n, attr_t attr, short color, const void *opts); wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts); mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts); mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color, const void *opts); chgat 可以改變目前螢幕上的文字屬性 參數 n 代表要修改幾個字元,若為 -1 則修改到行尾 參數 attr 填入要設定的屬性 參數 color 填入要設定的顏色 參數 opts 目前沒有功能,請填 NULL 顏色 bool has_colors(void); 檢查終端機是否支援顏色 start_color(); 開始彩色模式 init_pair(short pair, short f, short b); 初始化顏色對 參數 pair 設定顏色對編號 參數 f 設定前景顏色 參數 b 設定背景顏色 init_color(short color, short r, short g, short b); 修改顏色的定義,r、g、b 都必須在 0 到 1000 之間 顏色表 COLOR_BLACK COLOR_RED COLOR_GREEN COLOR_YELLOW COLOR_BLUE COLOR_MAGENTA COLOR_CYAN COLOR_WHITE 輸出文字 delch(void); wdelch(WINDOW *win); mvdelch(int y, int x); mvwdelch(WINDOW *win, int y, int x); 刪除游標所在的字元,緊跟在後的文字會向左移一格 deleteln(void); wdeleteln(WINDOW *win); 刪除一行 insdelln(int n); winsdelln(WINDOW *win, int n); 插入 n 個空白行 insertln(void); winsertln(WINDOW *win); 插入一行 insch(chtype ch); winsch(WINDOW *win, chtype ch); mvinsch(int y, int x, chtype ch); mvwinsch(WINDOW *win, int y, int x, chtype ch); 插入一個字元 clrtobot(void); wclrtobot(WINDOW *win); 清除到螢幕尾端 clrtoeol(void); wclrtoeol(WINDOW *win); 清除到行尾 window 控制 WINDOW *newwin(int nlines, int ncols, int begin_y, int begin_x); 新增一個 window Note: A new full-screen window is created by calling newwin(0,0,0,0). delwin(WINDOW *win); 刪除一個 window (window 上的資料不會清除!) mvwin(WINDOW *win, int y, int x); 移動 window