#include <curses.h>
void init(void){
    initscr(); /* 開始 curses */
    cbreak(); /* 立即讀取字元 */
    noecho(); /* 螢幕上不顯示輸入的字元 */
    nonl(); /* 送出 '\n' 時不加上 carriage return */
    intrflush(stdscr,FALSE); /* 避免中斷按鍵導致的 flush */
    keypad(stdscr,TRUE);
    nodelay(stdscr,FALSE); /* 等待使用者輸入 */
    /* raw() 類似 cbreak(),但是連會產生 signal 的按鍵也會被擋下*/
    /* noqiflush() 避免 INTR、QUIT、SUSP 造成 I/O queue 的 flush 
     * 可用於 signal handler */


}
/* 開新 window:newwin() */
int main(){
    init();
/* 屬性表 */
    attron(A_NORMAL);       addstr("Normal display (no highlight)\n");
    attron(A_STANDOUT);     addstr("Best highlighting mode of the terminal.\n");
    attroff(A_STANDOUT);
    attron(A_UNDERLINE);    addstr("Underlining\n");
    attroff(A_UNDERLINE);
    attron(A_REVERSE);      addstr("Reverse video\n");
    attroff(A_REVERSE);
    attron(A_BLINK);        addstr("Blinking\n");
    attroff(A_BLINK);
    attron(A_DIM);          addstr("Half bright\n");
    attroff(A_DIM);
    attron(A_BOLD);         addstr("Extra bright or bold\n");
    attroff(A_BOLD);
    attron(A_PROTECT);      addstr("Protected mode\n");
    attroff(A_PROTECT);
    attron(A_INVIS);        addstr("Invisible or blank mode\n");
    attroff(A_INVIS);
    attron(A_ALTCHARSET);   addstr("Alternate character set\n");
    attroff(A_ALTCHARSET);
    attron(A_CHARTEXT);     addstr("Bit-mask to extract a character\n");
    attroff(A_CHARTEXT);
    refresh();
/*
    COLOR_PAIR(n)   Color-pair number n 
*/
    getch();
/* 顏色測試 */
/* 預設顏色表
        COLOR_BLACK   0
        COLOR_RED     1
        COLOR_GREEN   2
        COLOR_YELLOW  3
        COLOR_BLUE    4
        COLOR_MAGENTA 5
        COLOR_CYAN    6
        COLOR_WHITE   7
 */
    clear(),refresh();
    start_color();
    init_pair(12,COLOR_YELLOW,COLOR_BLUE);
    attron(COLOR_PAIR(12));
    mvprintw(3,3,"你好嗎?               \n");
    attroff(COLOR_PAIR(12));
    mvprintw(4,3,"你好嗎?               \n");
    getch();
    clear();
    mvaddstr(3,3,"Type something: ");
    int c;
    while((c=getch())!=27){
        addch(c | A_BOLD);
    }
    clear();
    refresh();
    /* my_win = newwin(height, width, starty, startx); */
    WINDOW* yes=newwin(5,5,5,5);
    wborder(yes, '.', '.', '.','.','.','.','.','.');
    mvwaddch(yes,6,6,'a');
    refresh();
    wrefresh(yes);
    getch();
    delwin(yes);
    refresh();
    getch();
    clear();
    refresh();
    getch();
    mvaddstr(3,3,"getstr test: ");
    char a[100];
    echo();
    getstr(a);
    mvaddstr(23,3,a);
    noecho();
    getch();
    int i,j;
    clear();
    move(0,0);
    refresh();
    for(i=0;i<24;i++){
        for(j=0;j<80;j++){
            addch('*');
        }
    }
    move(1,3);
    while(1){
    switch(getch()){
        case '1': insch('#'); break;
        case '2': insertln(); break;
        case '3': delch(); break;
        case '4': deleteln();
    }}
    endwin();
    return 0;
}