Home About MIT CC BY-SA 4.0 RSS

NCurses Notes

Moving About

  • move(i, i) – move to (y, x) on the screen; coordinates are 0-indexed

Getting Input

  • [int] getch() – get next input (mouse clicks, special chars, etc.)
  • getnstr(s, i) – put at most i chars from keyboard buffer into s
  • flushinp() – flush keyboard buffer

Inserting Text

  • mvwaddch(w, i, i, c), waddch(w, c), addch(c) – add char
  • insertln() – add line empty line to current y-pos; doesn’t advance cursor; lines pushed past window are forgotten
  • addstr(s) – add string to current cursor
  • insch(c) – add char to current cursor; chars pushed past window size are forgotten; doesn’t advance cursor
  • ungetchar(c) – put char back into keyboard queue
  • overlay(w, w), overwrite(w, w), copywin(w, w, i, i, i, i, i, i, b), dupwin(w) – copy from source window to destination
  • box(w, c, c) – draw a box with (cx, cy) chars
  • hline(c, i), vline(c, i) – draw a line

Misc. Text Manipulation

  • scroll(), scrl(i), wscrl(w, i) – scroll; scrl(i) for i < 0 scrolls up
  • scr_dump(s), putwin() – put window contents to disk
  • scr_restore(s), [WINDOW *] getwin() – restore window contents from disk

Window Management

  • wrefresh(w), refresh() – refresh appropriate window
  • touchwin(w) – touch the window, so refresh will update the terminal
  • [WINDOW *] newwin(i, i, i, i)newwin(r, c, y_org, x_org)
  • [WINDOW *] subwin(w, i, i, i, i)subwin(r, c, y_org, x_org) where y_org and x_org are relative to the parent window
  • delwin(w) – delete the window
  • derwin(w) – delete subwindow
  • mvwin(w, i, i) – move the given window to new x and y coords
  • touchline(w, i, i) – touch ith line for i lines

Pad Management

  • [WINDOW *] newpad(i, i)
  • prefresh(p, i, i, i, i, i, i) – start at (px, py), transfer to (sx, sy) for (r, c) size
  • subpad(p, i, i, i, i) – cf. subwin

Deleting Text

  • deleteln() – delete current line; doesn’t advance cursor; doesn’t reverse word-rap
  • delch() – delete current char; doesn’t reverse word-wrap
  • clrtoeol() – delete from current line to EOL; doesn’t pull up next lines
  • clear(), erase() – deletes entire screen
  • clrtobot() – deletes text to bottom of screen

Modifying Behavior

  • nodelay(w, b) – getch returns immediately (returns ERR)
  • echo(), noecho() – toggle getch() input
  • keypad(w, b) – toggle keypad functions
  • raw(), noraw() – toggle function key handler
  • scrollok(w, b) – toggle if scrolling is allowed for current window
  • pechochar(p, c) – echo onto bound window as well as input into pad
  • curs_set(i) – set cursor echo (in mode i)

Query Window

  • getmaxyx(w, i, i) – get dimensions of current window
  • getyx(w, i, i) – get cursor position

Extras

Key Testing

  • KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT – cursor keys
  • KEY_HOME, KEY_NPAGE, KEY_PPAGE, KEY_END – page up / down, home and end keys
  • KEY_BACKSPACE
  • KEY_F(i) – function key

Soft Key Labels

  • slk_init(i) – called before initscr(); enable soft key label functions (rendered in mode i)
  • slk_set(i, s, i) – set ith label to s
  • slk_refresh() – display soft labels
  • slk_restore()
  • slk_clear()

Mice Operations

  • NCURSES_MOUSE_VERSION – non-zero if ncurses supports mouse operations
  • [mmask_t] mousemask(m, [mmask_t *] m) – test for supported mouse events; m is the requested actions (e.g. ALL_MOUSE_EVENTS), returns non-zero value if any mouse events are supported
  • getmouse([MEVENT *] e) – sets latest mouse event to e

Resources