ncurses ======= % sudo apt-get install libncurses5-dev ncurses-examples ncurses-doc http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ ``` #include int main() { initscr(); /* Initialize term in curses mode & create 'stdscr'. */ cbreak(); /* Turn off line buffering. See below. */ keypad(stdscr, TRUE); /* Read arrow keys, etc. See below. */ noecho(); /* Don't echo() while we getch. See below. */ printw("Hello World !!!"); /* Print to stdscr. */ refresh(); /* Copy from stdscr to the real screen */ getch(); /* Wait for user input. */ endwin(); /* End curses mode. */ return 0; } ``` Turn off the normal buffering of terminal input that happens before the user hits ENTER with either `raw` or `cbreak`. `raw` lets us handle interrupts like Ctrl-Z and Ctrl-C, while `cbreak` passes them through to act as they normally do. Turn off the normal echoing of typed characters to the terminal with `noecho`. `keypad` reads arrow keys and function keys like F1, etc. ## Windows ## `initscr` creates the default window 'stdscr', but we can create additional windows. When manipulating windows besides stdscr, use different function, typically ones that end in 'w'. ``` printw("Hi There !!!"); refresh(); wprintw(win, "Hi There !!!"); wrefresh(win); printw(string); /* Print on stdscr at present cursor position */ mvprintw(y, x, string); /* Move to (y, x) then print string */ wprintw(win, string); /* Print on window win at present cursor position */ mvwprintw(win, y, x, string); /* Move and print to (y, x) relative to window */ ```