PDCurses User's Guide

February 19, 2025 ยท View on GitHub

Curses Overview

The X/Open Curses Interface Definition describes a set of C-Language functions that provide screen-handling and updating, which are collectively known as the curses library.

The curses library permits manipulation of data structures called windows which may be thought of as two-dimensional arrays of characters representing all or part of a terminal's screen. The windows are manipulated using a procedural interface described elsewhere. The curses package maintains a record of what characters are on the screen. At the most basic level, manipulation is done with the routines move() and addch() which are used to "move" the curses around and add characters to the default window, stdscr, which represents the whole screen.

An application may use these routines to add data to the window in any convenient order. Once all data have been added, the routine refresh() is called. The package then determines what changes have been made which affect the screen. The screen contents are then changed to reflect those characters now in the window, using a sequence of operations optimized for the type of terminal in use.

At a higher level routines combining the actions of move() and addch() are defined, as are routines to add whole strings and to perform format conversions in the manner of printf().

Interfaces are also defined to erase the entire window and to specify the attributes of individual characters in the window. Attributes such as inverse video, underline and blink can be used on a per-character basis.

New windows can be created by allowing the application to build several images of the screen and display the appropriate one very quickly. New windows are created using the routine newwin(). For each routine that manipulates the default window, stdscr, there is a corresponding routine prefixed with w to manipulate the contents of a specified window; for example, move() and wmove(). In fact, move(...) is functionally equivalent to wmove( stdscr, ...). This is similar to the interface offered by printf(...) and fprintf(stdout, ...).

Windows do not have to correspond to the entire screen. It is possible to create smaller windows, and also to indicate that the window is only partially visible on the screen. Furthermore, large windows or pads, which are bigger than the actual screen size, may be created.

Interfaces are also defined to allow input character manipulation and to disable and enable many input attributes: character echo, single character input with or without signal processing (cbreak or raw modes), carriage returns mapping to newlines, screen scrolling, etc.

Data Types and the <curses.h> Header

The data types supported by curses are described in this section.

As the library supports a procedural interface to the data types, actual structure contents are not described. All curses data are manipulated using the routines provided.

The <curses.h> Header

The <curses.h> header defines various constants and declares the data types that are available to the application.

Data Types

The following data types are declared:

TypeDescription
WINDOW *pointer to screen representation
SCREEN *pointer to terminal descriptor
boolboolean data type
chtyperepresentation of a character in a window
cchar_tthe wide-character equivalent of chtype
attr_tfor WA_-style attributes

The actual WINDOW and SCREEN objects used to store information are created by the corresponding routines and a pointer to them is provided. All manipulation is through that pointer.

Variables

The following variables are defined:

VariableDescription
LINESnumber of lines on terminal screen
COLSnumber of columns on terminal screen
stdscrpointer to the default screen window
curscrpointer to the current screen image
SPpointer to the current SCREEN struct
Mouse_statusstatus of the mouse
COLORSnumber of colors available
COLOR_PAIRSnumber of color pairs available
TABSIZEsize of one TAB block
acs_map[]alternate character set map
ttytype[]terminal name/description

Constants

The following constants are defined:

General

ConstantDescription
FALSEboolean false value
TRUEboolean true value
NULLzero pointer value
ERRvalue returned on error condition
OKvalue returned on successful completion

Video Attributes

Normally, attributes are a property of the character.

For chtype:

AttributeDescription
A_ALTCHARSETuse the alternate character set
A_BLINKbright background or blinking
A_BOLDbright foreground or bold
A_DIMhalf bright -- no effect in PDCurses
A_INVISinvisible -- no effect in PDCurses
A_ITALICitalic
A_LEFTline along the left edge
A_PROTECTprotected -- no effect in PDCurses
A_REVERSEreverse video
A_RIGHTline along the right edge
A_STANDOUTterminal's best highlighting mode
A_UNDERLINEunderline
A_ATTRIBUTESbit-mask to extract attributes
A_CHARTEXTbit-mask to extract a character
A_COLORbit-mask to extract a color-pair

Not all attributes will work on all terminals. A_ITALIC is not standard, but is shared with ncurses.

For attr_t:

AttributeDescription
WA_ALTCHARSETsame as A_ALTCHARSET
WA_BLINKsame as A_BLINK
WA_BOLDsame as A_BOLD
WA_DIMsame as A_DIM
WA_INVISsame as A_INVIS
WA_ITALICsame as A_ITALIC
WA_LEFTsame as A_LEFT
WA_PROTECTsame as A_PROTECT
WA_REVERSEsame as A_REVERSE
WA_RIGHTsame as A_RIGHT
WA_STANDOUTsame as A_STANDOUT
WA_UNDERLINEsame as A_UNDERLINE

The following are also defined, for compatibility, but currently have no effect in PDCurses: A_HORIZONTAL, A_LOW, A_TOP, A_VERTICAL and their WA_* equivalents.

The Alternate Character Set

For use in chtypes and with related functions. These are a portable way to represent graphics characters on different terminals.

VT100-compatible symbols -- box characters:

NameDescription
ACS_ULCORNERupper left box corner
ACS_LLCORNERlower left box corner
ACS_URCORNERupper right box corner
ACS_LRCORNERlower right box corner
ACS_RTEEright "T"
ACS_LTEEleft "T"
ACS_BTEEbottom "T"
ACS_TTEEtop "T"
ACS_HLINEhorizontal line
ACS_VLINEvertical line
ACS_PLUSplus sign, cross, or four-corner piece

VT100-compatible symbols -- other:

NameDescription
ACS_S1scan line 1
ACS_S9scan line 9
ACS_DIAMONDdiamond
ACS_CKBOARDcheckerboard -- 50% grey
ACS_DEGREEdegree symbol
ACS_PLMINUSplus/minus sign
ACS_BULLETbullet

Teletype 5410v1 symbols -- these are defined in SysV curses, but are not well-supported by most terminals. Stick to VT100 characters for optimum portability:

NameDescription
ACS_LARROWleft arrow
ACS_RARROWright arrow
ACS_DARROWdown arrow
ACS_UARROWup arrow
ACS_BOARDcheckerboard -- less dense than ACS_CKBOARD
ACS_LANTERNlantern symbol
ACS_BLOCKsolid block

That goes double for these -- undocumented SysV symbols. Don't use them:

NameDescription
ACS_S3scan line 3
ACS_S7scan line 7
ACS_LEQUALless than or equal
ACS_GEQUALgreater than or equal
ACS_PIpi
ACS_NEQUALnot equal
ACS_STERLINGpounds sterling symbol

Box character aliases:

NameDescription
ACS_BSSBsame as ACS_ULCORNER
ACS_SSBBsame as ACS_LLCORNER
ACS_BBSSsame as ACS_URCORNER
ACS_SBBSsame as ACS_LRCORNER
ACS_SBSSsame as ACS_RTEE
ACS_SSSBsame as ACS_LTEE
ACS_SSBSsame as ACS_BTEE
ACS_BSSSsame as ACS_TTEE
ACS_BSBSsame as ACS_HLINE
ACS_SBSBsame as ACS_VLINE
ACS_SSSSsame as ACS_PLUS

For cchar_t and wide-character functions, WACS_ equivalents are also defined.

Colors

For use with init_pair(), color_set(), etc.:

NameBGR valueRGB value
COLOR_BLACK00
COLOR_BLUE14
COLOR_GREEN22
COLOR_CYAN36
COLOR_RED41
COLOR_MAGENTA55
COLOR_YELLOW63
COLOR_WHITE77

Use the symbolic names instead of numeric values. The definition of the colors depends on the implementation of curses.

Input Values

The following constants might be returned by getch() if keypad() has been enabled. Note that not all of these may be supported on a particular terminal:

NameDescription
KEY_BREAKbreak key
KEY_DOWNthe four arrow keys
KEY_UP
KEY_LEFT
KEY_RIGHT
KEY_HOMEhome key (upward+left arrow)
KEY_BACKSPACEbackspace
KEY_F0function keys; space for 64 keys is reserved
KEY_F(n)(KEY_F0+(n))
KEY_DLdelete line
KEY_ILinsert line
KEY_DCdelete character
KEY_ICinsert character
KEY_EICexit insert character mode
KEY_CLEARclear screen
KEY_EOSclear to end of screen
KEY_EOLclear to end of line
KEY_SFscroll 1 line forwards
KEY_SRscroll 1 line backwards (reverse)
KEY_NPAGEnext page
KEY_PPAGEprevious page
KEY_STABset tab
KEY_CTABclear tab
KEY_CATABclear all tabs
KEY_ENTERenter or send
KEY_SRESETsoft (partial) reset
KEY_RESETreset or hard reset
KEY_PRINTprint or copy
KEY_LLhome down or bottom (lower left)
KEY_A1upper left of virtual keypad
KEY_A3upper right of virtual keypad
KEY_B2center of virtual keypad
KEY_C1lower left of virtual keypad
KEY_C3lower right of virtual keypad
KEY_BTABBack tab key
KEY_BEGBeginning key
KEY_CANCELCancel key
KEY_CLOSEClose key
KEY_COMMANDCmd (command) key
KEY_COPYCopy key
KEY_CREATECreate key
KEY_ENDEnd key
KEY_EXITExit key
KEY_FINDFind key
KEY_HELPHelp key
KEY_MARKMark key
KEY_MESSAGEMessage key
KEY_MOVEMove key
KEY_NEXTNext object key
KEY_OPENOpen key
KEY_OPTIONSOptions key
KEY_PREVIOUSPrevious object key
KEY_REDORedo key
KEY_REFERENCEReference key
KEY_REFRESHRefresh key
KEY_REPLACEReplace key
KEY_RESTARTRestart key
KEY_RESUMEResume key
KEY_SAVESave key
KEY_SBEGShifted beginning key
KEY_SCANCELShifted cancel key
KEY_SCOMMANDShifted command key
KEY_SCOPYShifted copy key
KEY_SCREATEShifted create key
KEY_SDCShifted delete char key
KEY_SDLShifted delete line key
KEY_SELECTSelect key
KEY_SENDShifted end key
KEY_SEOLShifted clear line key
KEY_SEXITShifted exit key
KEY_SFINDShifted find key
KEY_SHELPShifted help key
KEY_SHOMEShifted home key
KEY_SICShifted input key
KEY_SLEFTShifted left arrow key
KEY_SMESSAGEShifted message key
KEY_SMOVEShifted move key
KEY_SNEXTShifted next key
KEY_SOPTIONSShifted options key
KEY_SPREVIOUSShifted prev key
KEY_SPRINTShifted print key
KEY_SREDOShifted redo key
KEY_SREPLACEShifted replace key
KEY_SRIGHTShifted right arrow
KEY_SRSUMEShifted resume key
KEY_SSAVEShifted save key
KEY_SSUSPENDShifted suspend key
KEY_SUNDOShifted undo key
KEY_SUSPENDSuspend key
KEY_UNDOUndo key

The virtual keypad is arranged like this:

A1     up     A3
left   B2  right
C1    down    C3

This list is incomplete -- see curses.h for the full list, and use the testcurs demo to see what values are actually returned. The above are just the keys required by X/Open. In particular, PDCurses defines many CTL_ and ALT_ combinations; these are not portable.