cc [flag . . .] file -locurses [library . . .]#include <ocurses.h>
The curses package allows: overall screen, window and pad manipulation; output to windows and pads; reading terminal input; control over terminal and curses input and output options; environment query routines; color manipulation; use of soft label keys; terminfo access; and access to low-level curses routines.
To initialize the routines, the routine initscr or newterm must be called before any of the other routines that deal with windows and screens are used. The routine endwin must be called before exiting. To get character-at-a-time input without echoing (most interactive, screen-oriented programs want this), the following sequence should be used:
initscr(); cbreak(); noecho();
Most programs would additionally use the sequence:
nonl(); intrflush(stdscr,FALSE); keypad(stdscr,TRUE);
Before a curses program is run, the tab stops of the terminal should be set and its initialization strings, if defined, must be output. This can be done by executing the tput init command after the shell environment variable TERM has been exported. [See terminfo(4) for further details.]
The curses library permits manipulation of data structures, called ``windows'', which can be thought of as two-dimensional arrays of characters. A default window called stdscr, which is the size of the terminal screen, is supplied. Others may be created with newwin().
Windows are referred to by variables declared as WINDOW *. These data structures are manipulated with routines described on 3ocurses pages (whose names begin ``curs_''). Among the most basic routines are move and addch. More general versions of these routines are included that allow the user to specify a window.
After using routines to manipulate a window, refresh is called, telling curses to make the user's CRT screen look like stdscr. The characters in a window are actually of type chtype (character and attribute data) so that other information about the character may also be stored with each character.
Special windows called ``pads'' may also be manipulated. These are windows that are not necessarily associated with a viewable part of the screen. See curs_pad(3ocurses) for more information.
In addition to drawing characters on the screen, video attributes and colors may be included, causing the characters to show up in such modes as underlined, reverse video or color on terminals that support such display enhancements. Line drawing characters may be specified to be output. On input, curses is also able to translate arrow and function keys that transmit escape sequences into single values. The video attributes, line drawing characters and input values use names, defined in ocurses.h, such as A_REVERSE, ACS_HLINE, and KEY_LEFT.
If the environment variables LINES and COLUMNS are set, or if the program is executing in a window environment, line and column information in the environment will override information read by terminfo. This would affect a program running in a window environment, for example, where the size of a screen is changeable.
If the environment variable TERMINFO is defined, any program using curses checks for a local terminal definition before checking in the standard place. For example, if TERM is set to wyse150, then the compiled terminal definition is found in
/usr/share/lib/terminfo/w/wyse150
(The w is copied from the first letter of wyse150 to avoid creation of huge directories.) However, if TERMINFO is set to $HOME/myterms, curses first checks
$HOME/myterms/w/wyse150
and if that fails, it then checks
/usr/share/lib/terminfo/w/wyse150
This is useful for developing experimental definitions or when write permission in /usr/share/lib/terminfo is not available.
The integer variables LINES and COLS are defined in ocurses.h and will be filled in by initscr with the size of the screen. The constants TRUE and FALSE have the values 1 and 0, respectively.
curses routines also define the WINDOW * variable curscr which is used for certain low-level operations like clearing and redrawing a screen containing garbage. curscr can be used in only a few routines.
For editing, operating at the character level is entirely appropriate. For screen formatting, arbitrary movement of characters on screen is not desirable.
Overwriting characters (addch, for example) operates on a screen level. Overwriting a character by a character that requires a different number of columns may produce ``orphaned columns''. These orphaned columns are filled with background characters.
Inserting characters (insch, for example) operates on a character level (that is, at the character boundaries). The specified character is inserted right before the character, regardless of which column of a character the cursor points to. Before insertion, the cursor position is adjusted to the first column of the character.
As with inserting characters, deleting characters (delch, for example) operates on a character level (that is, at the character boundaries). The character at the cursor is deleted whichever column of the character the cursor points to. Before deletion, the cursor position is adjusted to the first column of the character.
A multi-column character cannot be put on the last column of a line. When such attempts are made, the last column is set to the background character. In addition, when such an operation creates orphaned columns, the orphaned columns are filled with background characters.
Overlapping and overwriting a window follows the operation of overwriting characters around its edge. The orphaned columns, if any, are handled as in the character operations.
The cursor is allowed to be placed anywhere in a window. If the insertion or deletion is made when the cursor points to the second or later column position of a character that holds multiple columns, the cursor is adjusted to the first column of the character before the insertion or deletion.
The routines prefixed with mv require an x and y coordinate to move to before performing the appropriate action. The mv routines imply a call to move before the call to the other routine. The coordinate y always refers to the row (of the window), and x always refers to the column. The upper left-hand corner is always (0,0), not (1,1).
The routines prefixed with mvw take both a window argument and x and y coordinates. The window argument is always specified before the coordinates.
In each case, ``win'' is the window affected, and ``pad'' is the pad affected; ``win'' and ``pad'' are always pointers to type WINDOW.
Option setting routines require a Boolean flag ``bf'' with the value TRUE or FALSE; ``bf'' is always of type bool. The variables ``ch'' and ``attrs'' are always of type chtype. The types WINDOW, SCREEN, bool, and chtype are defined in ocurses.h. The type TERMINAL is defined in oterm.h. All other arguments are integers.
curses Routine Name | Manual Page Name |
---|---|
addch | curs_addch(3ocurses) |
addchnstr | curs_addchstr(3ocurses) |
addchstr | curs_addchstr(3ocurses) |
addnstr | curs_addstr(3ocurses) |
addnwstr | curs_addwstr(3ocurses) |
addstr | curs_addstr(3ocurses) |
addwch | curs_addwch(3ocurses) |
addwchnstr | curs_addwchstr(3ocurses) |
addwchstr | curs_addwchstr(3ocurses) |
addwstr | curs_addwstr(3ocurses) |
attroff | curs_attr(3ocurses) |
attron | curs_attr(3ocurses) |
attrset | curs_attr(3ocurses) |
baudrate | curs_termattrs(3ocurses) |
beep | curs_beep(3ocurses) |
bkgd | curs_bkgd(3ocurses) |
bkgdset | curs_bkgd(3ocurses) |
border | curs_border(3ocurses) |
box | curs_border(3ocurses) |
can_change_color | curs_color(3ocurses) |
cbreak | curs_inopts(3ocurses) |
clear | curs_clear(3ocurses) |
clearok | curs_outopts(3ocurses) |
clrtobot | curs_clear(3ocurses) |
clrtoeol | curs_clear(3ocurses) |
color_content | curs_color(3ocurses) |
copywin | curs_overlay(3ocurses) |
curs_set | curs_kernel(3ocurses) |
def_prog_mode | curs_kernel(3ocurses) |
def_shell_mode | curs_kernel(3ocurses) |
del_curterm | curs_terminfo(3ocurses) |
delay_output | curs_util(3ocurses) |
delch | curs_delch(3ocurses) |
deleteln | curs_deleteln(3ocurses) |
delscreen | curs_initscr(3ocurses) |
delwin | curs_window(3ocurses) |
derwin | curs_window(3ocurses) |
doupdate | curs_refresh(3ocurses) |
draino | curs_util(3ocurses) |
dupwin | curs_window(3ocurses) |
echo | curs_inopts(3ocurses) |
echochar | curs_addch(3ocurses) |
echowchar | curs_addwch(3ocurses) |
endwin | curs_initscr(3ocurses) |
erase | curs_clear(3ocurses) |
erasechar | curs_termattrs(3ocurses) |
filter | curs_util(3ocurses) |
flash | curs_beep(3ocurses) |
flushinp | curs_util(3ocurses) |
getbegyx | curs_getyx(3ocurses) |
getch | curs_getch(3ocurses) |
getmaxyx | curs_getyx(3ocurses) |
getnwstr | curs_getwstr(3ocurses) |
getparyx | curs_getyx(3ocurses) |
getstr | curs_getstr(3ocurses) |
getsyx | curs_kernel(3ocurses) |
getwch | curs_getwch(3ocurses) |
getwin | curs_util(3ocurses) |
getwstr | curs_getwstr(3ocurses) |
getyx | curs_getyx(3ocurses) |
halfdelay | curs_inopts(3ocurses) |
has_colors | curs_color(3ocurses) |
has_ic | curs_termattrs(3ocurses) |
has_il | curs_termattrs(3ocurses) |
hline | curs_border(3ocurses) |
idcok | curs_outopts(3ocurses) |
idlok | curs_outopts(3ocurses) |
immedok | curs_outopts(3ocurses) |
inch | curs_inch(3ocurses) |
inchnstr | curs_inchstr(3ocurses) |
inchstr | curs_inchstr(3ocurses) |
init_color | curs_color(3ocurses) |
init_pair | curs_color(3ocurses) |
initscr | curs_initscr(3ocurses) |
innstr | curs_instr(3ocurses) |
innwstr | curs_inwstr(3ocurses) |
insch | curs_insch(3ocurses) |
insdelln | curs_deleteln(3ocurses) |
insertln | curs_deleteln(3ocurses) |
insnstr | curs_insstr(3ocurses) |
insnwstr | curs_inswstr(3ocurses) |
insstr | curs_insstr(3ocurses) |
instr | curs_instr(3ocurses) |
inswch | curs_inswch(3ocurses) |
inswstr | curs_inswstr(3ocurses) |
intrflush | curs_inopts(3ocurses) |
inwch | curs_inwch(3ocurses) |
inwchnstr | curs_inwchstr(3ocurses) |
inwchstr | curs_inwchstr(3ocurses) |
inwstr | curs_inwstr(3ocurses) |
is_linetouched | curs_touch(3ocurses) |
is_wintouched | curs_touch(3ocurses) |
isendwin | curs_initscr(3ocurses) |
keyname | curs_util(3ocurses) |
keypad | curs_inopts(3ocurses) |
killchar | curs_termattrs(3ocurses) |
leaveok | curs_outopts(3ocurses) |
longname | curs_termattrs(3ocurses) |
meta | curs_inopts(3ocurses) |
move | curs_move(3ocurses) |
mvaddch | curs_addch(3ocurses) |
mvaddchnstr | curs_addchstr(3ocurses) |
mvaddchstr | curs_addchstr(3ocurses) |
mvaddnstr | curs_addstr(3ocurses) |
mvaddnwstr | curs_addwstr(3ocurses) |
mvaddstr | curs_addstr(3ocurses) |
mvaddwch | curs_addwch(3ocurses) |
mvaddwchnstr | curs_addwchstr(3ocurses) |
mvaddwchstr | curs_addwchstr(3ocurses) |
mvaddwstr | curs_addwstr(3ocurses) |
mvcur | curs_terminfo(3ocurses) |
mvdelch | curs_delch(3ocurses) |
mvderwin | curs_window(3ocurses) |
mvgetch | curs_getch(3ocurses) |
mvgetnwstr | curs_getwstr(3ocurses) |
mvgetstr | curs_getstr(3ocurses) |
mvgetwch | curs_getwch(3ocurses) |
mvgetwstr | curs_getwstr(3ocurses) |
mvinch | curs_inch(3ocurses) |
mvinchnstr | curs_inchstr(3ocurses) |
mvinchstr | curs_inchstr(3ocurses) |
mvinnstr | curs_instr(3ocurses) |
mvinnwstr | curs_inwstr(3ocurses) |
mvinsch | curs_insch(3ocurses) |
mvinsnstr | curs_insstr(3ocurses) |
mvinsnwstr | curs_inswstr(3ocurses) |
mvinsstr | curs_insstr(3ocurses) |
mvinstr | curs_instr(3ocurses) |
mvinswch | curs_inswch(3ocurses) |
mvinswstr | curs_inswstr(3ocurses) |
mvinwch | curs_inwch(3ocurses) |
mvinwchnstr | curs_inwchstr(3ocurses) |
mvinwchstr | curs_inwchstr(3ocurses) |
mvinwstr | curs_inwstr(3ocurses) |
mvprintw | curs_printw(3ocurses) |
mvscanw | curs_scanw(3ocurses) |
mvwaddch | curs_addch(3ocurses) |
mvwaddchnstr | curs_addchstr(3ocurses) |
mvwaddchstr | curs_addchstr(3ocurses) |
mvwaddnstr | curs_addstr(3ocurses) |
mvwaddnwstr | curs_addwstr(3ocurses) |
mvwaddstr | curs_addstr(3ocurses) |
mvwaddwch | curs_addwch(3ocurses) |
mvwaddwchnstr | curs_addwchstr(3ocurses) |
mvwaddwchstr | curs_addwchstr(3ocurses) |
mvwaddwstr | curs_addwstr(3ocurses) |
mvwdelch | curs_delch(3ocurses) |
mvwgetch | curs_getch(3ocurses) |
mvwgetnwstr | curs_getwstr(3ocurses) |
mvwgetstr | curs_getstr(3ocurses) |
mvwgetwch | curs_getwch(3ocurses) |
mvwgetwstr | curs_getwstr(3ocurses) |
mvwin | curs_window(3ocurses) |
mvwinch | curs_inch(3ocurses) |
mvwinchnstr | curs_inchstr(3ocurses) |
mvwinchstr | curs_inchstr(3ocurses) |
mvwinnstr | curs_instr(3ocurses) |
mvwinnwstr | curs_inwstr(3ocurses) |
mvwinsch | curs_insch(3ocurses) |
mvwinsnstr | curs_insstr(3ocurses) |
mvwinsstr | curs_insstr(3ocurses) |
mvwinstr | curs_instr(3ocurses) |
mvwinswch | curs_inswch(3ocurses) |
mvwinswstr | curs_inswstr(3ocurses) |
mvwinwch | curs_inwch(3ocurses) |
mvwinwchnstr | curs_inwchstr(3ocurses) |
mvwinwchstr | curs_inwchstr(3ocurses) |
mvwinwstr | curs_inwstr(3ocurses) |
mvwprintw | curs_printw(3ocurses) |
mvwscanw | curs_scanw(3ocurses) |
napms | curs_kernel(3ocurses) |
newpad | curs_pad(3ocurses) |
newterm | curs_initscr(3ocurses) |
newwin | curs_window(3ocurses) |
nl | curs_outopts(3ocurses) |
nocbreak | curs_inopts(3ocurses) |
nodelay | curs_inopts(3ocurses) |
noecho | curs_inopts(3ocurses) |
nonl | curs_outopts(3ocurses) |
noqiflush | curs_inopts(3ocurses) |
noraw | curs_inopts(3ocurses) |
notimeout | curs_inopts(3ocurses) |
overlay | curs_overlay(3ocurses) |
overwrite | curs_overlay(3ocurses) |
pair_content | curs_color(3ocurses) |
pechochar | curs_pad(3ocurses) |
pechowchar | curs_pad(3ocurses) |
pnoutrefresh | curs_pad(3ocurses) |
prefresh | curs_pad(3ocurses) |
printw | curs_printw(3ocurses) |
putp | curs_terminfo(3ocurses) |
putwin | curs_util(3ocurses) |
qiflush | curs_inopts(3ocurses) |
raw | curs_inopts(3ocurses) |
redrawwin | curs_refresh(3ocurses) |
refresh | curs_refresh(3ocurses) |
reset_prog_mode | curs_kernel(3ocurses) |
reset_shell_mode | curs_kernel(3ocurses) |
resetty | curs_kernel(3ocurses) |
restartterm | curs_terminfo(3ocurses) |
ripoffline | curs_kernel(3ocurses) |
savetty | curs_kernel(3ocurses) |
scanw | curs_scanw(3ocurses) |
scr_dump | curs_scr_dump(3ocurses) |
scr_init | curs_scr_dump(3ocurses) |
scr_restore | curs_scr_dump(3ocurses) |
scr_set | curs_scr_dump(3ocurses) |
scrl | curs_scroll(3ocurses) |
scroll | curs_scroll(3ocurses) |
scrollok | curs_outopts(3ocurses) |
set_curterm | curs_terminfo(3ocurses) |
set_term | curs_initscr(3ocurses) |
setscrreg | curs_outopts(3ocurses) |
setsyx | curs_kernel(3ocurses) |
setterm | curs_terminfo(3ocurses) |
setupterm | curs_terminfo(3ocurses) |
slk_attroff | curs_slk(3ocurses) |
slk_attron | curs_slk(3ocurses) |
slk_attrset | curs_slk(3ocurses) |
slk_clear | curs_slk(3ocurses) |
slk_init | curs_slk(3ocurses) |
slk_label | curs_slk(3ocurses) |
slk_noutrefresh | curs_slk(3ocurses) |
slk_refresh | curs_slk(3ocurses) |
slk_restore | curs_slk(3ocurses) |
slk_set | curs_slk(3ocurses) |
slk_touch | curs_slk(3ocurses) |
standend | curs_attr(3ocurses) |
standout | curs_attr(3ocurses) |
start_color | curs_color(3ocurses) |
subpad | curs_pad(3ocurses) |
subwin | curs_window(3ocurses) |
syncok | curs_window(3ocurses) |
termattrs | curs_termattrs(3ocurses) |
termname | curs_termattrs(3ocurses) |
tgetent | curs_termcap(3ocurses) |
tgetflag | curs_termcap(3ocurses) |
tgetnum | curs_termcap(3ocurses) |
tgetstr | curs_termcap(3ocurses) |
tgoto | curs_termcap(3ocurses) |
tigetflag | curs_terminfo(3ocurses) |
tigetnum | curs_terminfo(3ocurses) |
tigetstr | curs_terminfo(3ocurses) |
timeout | curs_inopts(3ocurses) |
touchline | curs_touch(3ocurses) |
touchwin | curs_touch(3ocurses) |
tparm | curs_terminfo(3ocurses) |
tputs | curs_termcap(3ocurses) |
tputs | curs_terminfo(3ocurses) |
typeahead | curs_inopts(3ocurses) |
unctrl | curs_util(3ocurses) |
ungetch | curs_getch(3ocurses) |
ungetwch | curs_getwch(3ocurses) |
untouchwin | curs_touch(3ocurses) |
use_env | curs_util(3ocurses) |
vidattr | curs_terminfo(3ocurses) |
vidputs | curs_terminfo(3ocurses) |
vline | curs_border(3ocurses) |
vwprintw | curs_printw(3ocurses) |
vwscanw | curs_scanw(3ocurses) |
waddch | curs_addch(3ocurses) |
waddchnstr | curs_addchstr(3ocurses) |
waddchstr | curs_addchstr(3ocurses) |
waddnstr | curs_addstr(3ocurses) |
waddnwstr | curs_addwstr(3ocurses) |
waddstr | curs_addstr(3ocurses) |
waddwch | curs_addwch(3ocurses) |
waddwchnstr | curs_addwchstr(3ocurses) |
waddwchstr | curs_addwchstr(3ocurses) |
waddwstr | curs_addwstr(3ocurses) |
wattroff | curs_attr(3ocurses) |
wattron | curs_attr(3ocurses) |
wattrset | curs_attr(3ocurses) |
wbkgd | curs_bkgd(3ocurses) |
wbkgdset | curs_bkgd(3ocurses) |
wborder | curs_border(3ocurses) |
wclear | curs_clear(3ocurses) |
wclrtobot | curs_clear(3ocurses) |
wclrtoeol | curs_clear(3ocurses) |
wcursyncup | curs_window(3ocurses) |
wdelch | curs_delch(3ocurses) |
wdeleteln | curs_deleteln(3ocurses) |
wechochar | curs_addch(3ocurses) |
wechowchar | curs_addwch(3ocurses) |
werase | curs_clear(3ocurses) |
wgetch | curs_getch(3ocurses) |
wgetnstr | curs_getstr(3ocurses) |
wgetnwstr | curs_getwstr(3ocurses) |
wgetstr | curs_getstr(3ocurses) |
wgetwch | curs_getwch(3ocurses) |
wgetwstr | curs_getwstr(3ocurses) |
whline | curs_border(3ocurses) |
winch | curs_inch(3ocurses) |
winchnstr | curs_inchstr(3ocurses) |
winchstr | curs_inchstr(3ocurses) |
winnstr | curs_instr(3ocurses) |
winnwstr | curs_inwstr(3ocurses) |
winsch | curs_insch(3ocurses) |
winsdelln | curs_deleteln(3ocurses) |
winsertln | curs_deleteln(3ocurses) |
winsnstr | curs_insstr(3ocurses) |
winsnwstr | curs_inswstr(3ocurses) |
winsstr | curs_insstr(3ocurses) |
winstr | curs_instr(3ocurses) |
winswch | curs_inswch(3ocurses) |
winswstr | curs_inswstr(3ocurses) |
winwch | curs_inwch(3ocurses) |
winwchnstr | curs_inwchstr(3ocurses) |
winwchstr | curs_inwchstr(3ocurses) |
winwstr | curs_inwstr(3ocurses) |
wmove | curs_move(3ocurses) |
wnoutrefresh | curs_refresh(3ocurses) |
wprintw | curs_printw(3ocurses) |
wredrawln | curs_refresh(3ocurses) |
wrefresh | curs_refresh(3ocurses) |
wscanw | curs_scanw(3ocurses) |
wscrl | curs_scroll(3ocurses) |
wsetscrreg | curs_outopts(3ocurses) |
wstandend | curs_attr(3ocurses) |
wstandout | curs_attr(3ocurses) |
wsyncdown | curs_window(3ocurses) |
wsyncup | curs_window(3ocurses) |
wtimeout | curs_inopts(3ocurses) |
wtouchln | curs_touch(3ocurses) |
wvline | curs_border(3ocurses) |
All macros return the value of the window version, except setscrreg, wsetscrreg, getyx, getbegyx and getmaxyx. The return values of setscrreg, wsetscrreg, getyx, getbegyx and getmaxyx are undefined (that is, these should not be used as the right-hand side of assignment statements).
Routines that return pointers return NULL on error.