Copyright 1989 AT&T
Portions Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
cc [ flag... ] file.. .-lcurses [ library... ] #include <curses.h>
The curses library routines give the user a terminal-independent method of updating character screens with reasonable optimization.
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 representing all or part of a CRT screen. A default window called stdscr, which is the size of the terminal screen, is supplied. Others may be created with newwin(3CURSES).
Windows are referred to by variables declared as WINDOW *. These data structures are manipulated with routines described on 3CURSES pages (whose names begin "curs_"). Among which the most basic routines are move(3CURSES) and addch(3CURSES). More general versions of these routines are included with names beginning with w, allowing the user to specify a window. The routines not beginning with w affect stdscr.
After using routines to manipulate a window, refresh(3CURSES) 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 which are not constrained to the size of the screen and whose contents need not be completely displayed. See curs_pad(3CURSES) 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, in reverse video, or in 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 <curses.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 effect a program running in an AT&T 630 layer, 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 att4424, then the compiled terminal definition is found in
/usr/share/lib/terminfo/a/att4424.
(The `a' is copied from the first letter of att4424 to avoid creation of huge directories.) However, if TERMINFO is set to $HOME/myterms, curses first checks
and if that fails, it then checks
/usr/share/lib/terminfo/a/att4424.
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 <curses.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.
The curses routines also define the WINDOW * variable curscr which is used for certain low-level operations like clearing and redrawing a screen containing garbage. The curscr can be used in only a few routines.
The number of bytes and the number of columns to hold a character from the supplementary character set is locale-specific (locale category LC_CTYPE) and can be specified in the character class table.
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.
Many curses routines have two or more versions. The routines prefixed with w require a window argument. The routines prefixed with p require a pad argument. Those without a prefix generally use stdscr.
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(3CURSES) 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 below are always of type chtype. The types WINDOW, SCREEN, bool, and chtype are defined in <curses.h>. The type TERMINAL is defined in <term.h>. All other arguments are integers.
The following table lists each curses routine and the name of the manual page on which it is described. curses Routine Name
Manual Page Name
curs_addch(3CURSES)
curs_addchstr(3CURSES)
curs_addchstr(3CURSES)
curs_addstr(3CURSES)
curs_addwstr(3CURSES)
curs_addstr(3CURSES)
curs_addwch(3CURSES)
curs_addwchstr(3CURSES)
curs_addwchstr(3CURSES)
curs_addwstr(3CURSES)
curs_alecompat(3CURSES)
curs_attr(3CURSES)
curs_attr(3CURSES)
curs_attr(3CURSES)
curs_termattrs(3CURSES)
curs_beep(3CURSES)
curs_bkgd(3CURSES)
curs_bkgd(3CURSES)
curs_border(3CURSES)
curs_border(3CURSES)
curs_color(3CURSES)
curs_inopts(3CURSES)
curs_clear(3CURSES)
curs_outopts(3CURSES)
curs_clear(3CURSES)
curs_clear(3CURSES)
curs_color(3CURSES)
curs_overlay(3CURSES)
curs_kernel(3CURSES)
curs_kernel(3CURSES)
curs_kernel(3CURSES)
curs_terminfo(3CURSES)
curs_util(3CURSES)
curs_delch(3CURSES)
curs_deleteln(3CURSES)
curs_initscr(3CURSES)
curs_window(3CURSES)
curs_window(3CURSES)
curs_refresh(3CURSES)
curs_window(3CURSES)
curs_inopts(3CURSES)
curs_addch(3CURSES)
curs_addwch(3CURSES)
curs_initscr(3CURSES)
curs_clear(3CURSES)
curs_termattrs(3CURSES)
curs_util(3CURSES)
curs_beep(3CURSES)
curs_util(3CURSES)
curs_getyx(3CURSES)
curs_getch(3CURSES)
curs_getyx(3CURSES)
curs_getwstr(3CURSES)
curs_getyx(3CURSES)
curs_getstr(3CURSES)
curs_kernel(3CURSES)
curs_getwch(3CURSES)
curs_util(3CURSES)
curs_getwstr(3CURSES)
curs_getyx(3CURSES)
curs_inopts(3CURSES)
curs_color(3CURSES)
curs_termattrs(3CURSES)
curs_termattrs(3CURSES)
curs_outopts(3CURSES)
curs_outopts(3CURSES)
curs_outopts(3CURSES)
curs_inch(3CURSES)
curs_inchstr(3CURSES)
curs_inchstr(3CURSES)
curs_color(3CURSES)
curs_color(3CURSES)
curs_initscr(3CURSES)
curs_instr(3CURSES)
curs_inwstr(3CURSES)
curs_insch(3CURSES)
curs_deleteln(3CURSES)
curs_deleteln(3CURSES)
curs_insstr(3CURSES)
curs_inswstr(3CURSES)
curs_insstr(3CURSES)
curs_instr(3CURSES)
curs_inswch(3CURSES)
curs_inswstr(3CURSES)
curs_inopts(3CURSES)
curs_inwch(3CURSES)
curs_inwchstr(3CURSES)
curs_inwchstr(3CURSES)
curs_inwstr(3CURSES)
curs_touch(3CURSES)
curs_touch(3CURSES)
curs_initscr(3CURSES)
curs_util(3CURSES)
curs_inopts(3CURSES)
curs_termattrs(3CURSES)
curs_outopts(3CURSES)
curs_termattrs(3CURSES)
curs_inopts(3CURSES)
curs_move(3CURSES)
curs_alecompat(3CURSES)
curs_alecompat(3CURSES)
curs_addch(3CURSES)
curs_addchstr(3CURSES)
curs_addchstr(3CURSES)
curs_addstr(3CURSES)
curs_addwstr(3CURSES)
curs_addstr(3CURSES)
curs_addwch(3CURSES)
curs_addwchstr(3CURSES)
curs_addwchstr(3CURSES)
curs_addwstr(3CURSES)
curs_terminfo(3CURSES)
curs_delch(3CURSES)
curs_window(3CURSES)
curs_getch(3CURSES)
curs_getwstr(3CURSES)
curs_getstr(3CURSES)
curs_getwch(3CURSES)
curs_getwstr(3CURSES)
curs_inch(3CURSES)
curs_inchstr(3CURSES)
curs_inchstr(3CURSES)
curs_instr(3CURSES)
curs_inwstr(3CURSES)
curs_insch(3CURSES)
curs_insstr(3CURSES)
curs_inswstr(3CURSES)
curs_insstr(3CURSES)
curs_instr(3CURSES)
curs_inswch(3CURSES)
curs_inswstr(3CURSES)
curs_inwch(3CURSES)
curs_inwchstr(3CURSES)
curs_inwchstr(3CURSES)
curs_inwstr(3CURSES)
curs_printw(3CURSES)
curs_scanw(3CURSES)
curs_addch(3CURSES)
curs_addchstr(3CURSES)
curs_addchstr(3CURSES)
curs_addstr(3CURSES)
curs_addwstr(3CURSES)
curs_addstr(3CURSES)
curs_addwch(3CURSES)
curs_addwchstr(3CURSES)
curs_addwchstr(3CURSES)
curs_addwstr(3CURSES)
curs_delch(3CURSES)
curs_getch(3CURSES)
curs_getwstr(3CURSES)
curs_getstr(3CURSES)
curs_getwch(3CURSES)
curs_getwstr(3CURSES)
curs_window(3CURSES)
curs_inch(3CURSES)
curs_inchstr(3CURSES)
curs_inchstr(3CURSES)
curs_instr(3CURSES)
curs_inwstr(3CURSES)
curs_insch(3CURSES)
curs_insstr(3CURSES)
curs_insstr(3CURSES)
curs_instr(3CURSES)
curs_inswch(3CURSES)
curs_inswstr(3CURSES)
curs_inwch(3CURSES)
curs_inwchstr(3CURSES)
curs_inwchstr(3CURSES)
curs_inwstr(3CURSES)
curs_printw(3CURSES)
curs_scanw(3CURSES)
curs_kernel(3CURSES)
curs_pad(3CURSES)
curs_initscr(3CURSES)
curs_window(3CURSES)
curs_outopts(3CURSES)
curs_inopts(3CURSES)
curs_inopts(3CURSES)
curs_inopts(3CURSES)
curs_outopts(3CURSES)
curs_inopts(3CURSES)
curs_inopts(3CURSES)
curs_inopts(3CURSES)
curs_overlay(3CURSES)
curs_overlay(3CURSES)
curs_color(3CURSES)
curs_pad(3CURSES)
curs_pad(3CURSES)
curs_pad(3CURSES)
curs_pad(3CURSES)
curs_printw(3CURSES)
curs_terminfo(3CURSES)
curs_util(3CURSES)
curs_inopts(3CURSES)
curs_inopts(3CURSES)
curs_refresh(3CURSES)
curs_refresh(3CURSES)
curs_kernel(3CURSES)
curs_kernel(3CURSES)
curs_kernel(3CURSES)
curs_terminfo(3CURSES)
curs_kernel(3CURSES)
curs_kernel(3CURSES)
curs_scanw(3CURSES)
curs_scr_dump(3CURSES)
curs_scr_dump(3CURSES)
curs_scr_dump(3CURSES)
curs_scr_dump(3CURSES)
curs_scroll(3CURSES)
curs_outopts(3CURSES)
curs_terminfo(3CURSES)
curs_initscr(3CURSES)
curs_outopts(3CURSES)
curs_kernel(3CURSES)
curs_terminfo(3CURSES)
curs_terminfo(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_slk(3CURSES)
curs_scroll(3CURSES)
curs_attr(3CURSES)
curs_attr(3CURSES)
curs_color(3CURSES)
curs_pad(3CURSES)
curs_window(3CURSES)
curs_window(3CURSES)
curs_termattrs(3CURSES)
curs_termattrs(3CURSES)
curs_termcap(3CURSES)
curs_termcap(3CURSES)
curs_termcap(3CURSES)
curs_termcap(3CURSES)
curs_termcap(3CURSES)
curs_terminfo(3CURSES)
curs_terminfo(3CURSES)
curs_terminfo(3CURSES)
curs_inopts(3CURSES)
curs_touch(3CURSES)
curs_touch(3CURSES)
curs_terminfo(3CURSES)
curs_terminfo(3CURSES)
curs_inopts(3CURSES)
curs_util(3CURSES)
curs_getch(3CURSES)
curs_getwch(3CURSES)
curs_touch(3CURSES)
curs_util(3CURSES)
curs_terminfo(3CURSES)
curs_terminfo(3CURSES)
curs_printw(3CURSES)
curs_scanw(3CURSES)
curs_addch(3CURSES)
curs_addchstr(3CURSES)
curs_addchstr(3CURSES)
curs_addstr(3CURSES)
curs_addwstr(3CURSES)
curs_addstr(3CURSES)
curs_addwch(3CURSES)
curs_addwchstr(3CURSES)
curs_addwchstr(3CURSES)
curs_addwstr(3CURSES)
curs_alecompat(3CURSES)
curs_attr(3CURSES)
curs_attr(3CURSES)
curs_attr(3CURSES)
curs_bkgd(3CURSES)
curs_bkgd(3CURSES)
curs_border(3CURSES)
curs_clear(3CURSES)
curs_clear(3CURSES)
curs_clear(3CURSES)
curs_window(3CURSES)
curs_delch(3CURSES)
curs_deleteln(3CURSES)
curs_addch(3CURSES)
curs_addwch(3CURSES)
curs_clear(3CURSES)
curs_getch(3CURSES)
curs_getstr(3CURSES)
curs_getwstr(3CURSES)
curs_getstr(3CURSES)
curs_getwch(3CURSES)
curs_getwstr(3CURSES)
curs_border(3CURSES)
curs_inch(3CURSES)
curs_inchstr(3CURSES)
curs_inchstr(3CURSES)
curs_instr(3CURSES)
curs_inwstr(3CURSES)
curs_insch(3CURSES)
curs_deleteln(3CURSES)
curs_deleteln(3CURSES)
curs_insstr(3CURSES)
curs_inswstr(3CURSES)
curs_insstr(3CURSES)
curs_instr(3CURSES)
curs_inswch(3CURSES)
curs_inswstr(3CURSES)
curs_inwch(3CURSES)
curs_inwchstr(3CURSES)
curs_inwchstr(3CURSES)
curs_inwstr(3CURSES)
curs_move(3CURSES)
curs_alecompat(3CURSES)
curs_alecompat(3CURSES)
curs_refresh(3CURSES)
curs_printw(3CURSES)
curs_refresh(3CURSES)
curs_refresh(3CURSES)
curs_scanw(3CURSES)
curs_scroll(3CURSES)
curs_outopts(3CURSES)
curs_attr(3CURSES)
curs_attr(3CURSES)
curs_window(3CURSES)
curs_window(3CURSES)
curs_inopts(3CURSES)
curs_touch(3CURSES)
curs_border(3CURSES)
Routines that return an integer return ERR upon failure and an integer value other than ERR upon successful completion, unless otherwise noted in the routine descriptions.
All macros return the value of the w 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.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE ATTRIBUTE VALUE |
MT-Level Unsafe |
curses(3XCURSES), libcurses(3LIB), libcurses(3XCURSES), terminfo(4), attributes(5)
The header <curses.h> automatically includes the headers <stdio.h> and <unctrl.h>.