ncurses(3X)
π ncurses(3X) β character-cell terminal interface with optimized output
okay bestie, welcome to the iconic ncurses(3X) manual. this library literally ate, no cap. letβs get into it. π«Ά
πΈ NAME πΈ
ncurses β character-cell terminal interface with optimized output.
β¨ SYNOPSIS β¨
#include <curses.h>
π DESCRIPTION π
The βnew cursesβ library offers the programmer a terminal-independent means of reading keyboard and mouse input and writing to character-cell displays, with output optimized to minimize screen updates. ncurses replaces the curses libraries from System V Release 4 Unix (SVr4) and 4.4BSD Unix, the development of which ceased in the 1990s. This document describes ncurses version 6.6 (patch 20251230).
ncurses permits control of the terminal screenβs contents; abstraction and subdivision thereof with windows and pads; acquisition of keyboard and mouse events; selection of color and rendering attributes (such as bold or underline); the definition and use of soft label keys; access to the terminfo terminal capability database; a termcap compatibility interface; and an abstraction of the systemβs API for manipulating the terminal (such as termios(3)).
ncurses implements the interface described by X/Open Curses Issue 7. In many behavioral details not standardized by X/Open, ncurses emulates the curses library of SVr4 and provides numerous useful extensions.
ncurses man pages employ several sections to clarify matters of usage and interoperability with other curses implementations. β¨
- βNOTESβ describes issues and caveats of which any user of the
ncursesAPI should be aware, such as limitations on the size of an underlying integral type or the availability of a preprocessor macro exclusive of a function definition (which prevents its address from being taken). This section also describes implementation details of significance to the programmer but which are not standardized. - βEXTENSIONSβ presents
ncursesinnovations beyond the X/Open Curses standard and/or theSVr4curses implementation. They are termed extensions to indicate that they cannot be implemented solely by using the library API, but require access to the libraryβs internal state. - βPORTABILITYβ discusses matters (beyond the exercise of extensions) that should be considered when writing to a curses standard, or for multiple implementations.
- βHISTORYβ examines points of detail in
ncursesand other curses implementations over the decades of their development, particularly where precedent or inertia have frustrated better design (and, in a few cases, where such inertia has been overcome).
A curses application must be linked with the library; use the -lncurses option to your compiler or linker. A debugging version of the library may be available; if so, link with it using -lncurses_g. (Your system integrator may have installed these libraries such that you can use the options -lcurses and -lcurses_g, respectively.) The ncurses_g library logs events describing ncurses actions to a file called trace in the applicationβs working directory at startup. See section βALTERNATE CONFIGURATIONSβ below.
π Application Structure π
A curses application uses information from the system locale; setlocale(3) prepares it for curses library calls.
setlocale(LC_ALL, "");
If the locale is not thus initialized, the library assumes that characters are printable as in ISO 8859-1, to work with certain legacy programs. You should initialize the locale.
do not expect consistent behavior from the library when the locale has not been set up. π
initscr(3X) or newterm(3X) must be called to initialize curses before use of any functions that access or manipulate windows or screens.
To get character-at-a-time input without echoing β most interactive, screen-oriented programs want this β use the following sequence.
initscr(); cbreak(); noecho();
Most applications would perform further setup as follows.
noqiflush();
keypad(stdscr, TRUE);
A curses program then often enters an event-handling loop. Call endwin(3X) before exiting.
π Overview π
A curses library abstracts the terminal with a SCREEN data structure, and represents all or part of its display with WINDOW structures. Distinct properties apply to each; for example, the line discipline of a typical Unix terminal driver is in one of three modes: raw, cbreak, or canonical (βcookedβ). In curses, the line discipline is a property of the screen, applying identically to all windows associated with it.
A window is a rectangular grid of character cells, addressed by line and column coordinates (y, x), with the upper left corner as (0, 0). A window called stdscr, by default the same size as the terminal screen, is always available. Create others with newwin(3X).
A curses library does not manage overlapping windows (but see below). You can either use stdscr to manage one screen-filling window, or tile the screen into non-overlapping windows and not use stdscr at all.
Mixing the two approaches will result in unpredictable and undesired effects. π
Functions permit manipulation of a window and the cursor identifying the cell within it at which the next operation will occur. Among those, the most basic are move(3X) and addch(3X): these place the cursor within and write a character to stdscr, respectively.
Frequent changes to the terminal screen can cause unpleasant flicker or inefficient use of the communication channel to the device, so as a rule the library does not update it automatically. Therefore, after using curses functions to accumulate a set of desired updates that make sense to present together, call refresh(3X) to tell the library to make the userβs screen look like stdscr. The library optimizes its output by computing a minimal volume of operations to mutate the screen from its state at the previous refresh to the new one. Effective optimization demands accurate information about the terminal device: the management of such information is the province of the terminfo(3X) API, a feature of every standard curses implementation.
Special windows called pads may also be manipulated. These are not constrained to the size of the terminal screen and their contents need not be completely displayed. See curs_pad(3X).
Many terminals support configuration of character cell foreground and background colors as well as attributes, which cause characters to render in such modes as boldfaced, underlined, or in reverse video. See curs_color(3X) and curs_attr(3X).
curses defines constants to simplify access to a small set of forms-drawing graphics corresponding to the DEC Alternate Character Set (ACS), a feature of VT100 and other terminals. See addch(3X).
curses is implemented using the operating systemβs terminal driver; key events are received not as scan codes but as byte sequences. The driver reports graphical keycaps (alphanumeric and punctuation keys, and the space) as-is. Everything else, including the tab, enter/return, keypad, arrow, and function keys, appears to curses as a control character or a multibyte escape sequence. curses can translate the latter into unique key codes. See keypad(3X) and getch(3X).
ncurses provides reimplementations of the SVr4 panel(3X), form(3X), and menu(3X) libraries; they permit overlapping windows and ease construction of user interfaces with curses. slay. π
π οΈ Initialization π οΈ
The selection of an appropriate value of TERM in the process environment is essential to correct curses and terminfo library operation. A well-configured system selects a correct TERM value automatically; tset(1) may assist with troubleshooting exotic situations.
If you change the terminal type from a shell, export TERM, then run tset(1) or the tput init command. See subsection βTabs and Initializationβ of terminfo(5).
If the environment variables LINES and COLUMNS are set, or if the curses program is executing in a graphical windowing environment, the information obtained thence overrides that obtained by terminfo. An ncurses extension supports resizable terminal displays; see wresize(3X).
If the environment variable TERMINFO is defined, a curses program checks first for a terminal type description in the location it identifies. TERMINFO is useful for developing type descriptions or when write permission to /usr/share/misc/terminfo is not available.
See section βENVIRONMENTβ below.
π Naming Conventions π
curses offers many functions in variant forms using a regular set of alternatives to the name of an elemental one. Those prefixed with βwβ require a WINDOW pointer argument; those with a βmvβ prefix first perform cursor movement using wmove(3X); a βmvwβ prefix indicates both. The βwβ function is typically the elemental one; the removal of this prefix usually indicates operation on stdscr.
Four functions prefixed with βpβ require a pad argument; see below.
In function synopses, ncurses man pages apply the following names to parameters. We introduce the character types in the next subsection.
bfβ abool(TRUEorFALSE)cβ acharorintchβ achtypewcβ awchar_torwint_twchβ acchar_twinβ pointer to aWINDOWpadβ pointer to aWINDOWthat is a padpairβ a foreground/background color pair identifier
π¦ Wide and Non-wide Character Configurations π¦
This man page primarily surveys functions that appear in any configuration of the library. There are two common configurations; for others, see section βALTERNATE CONFIGURATIONSβ below.
ncurses is the library in its βnon-wideβ configuration, handling only eight-bit characters. It stores a character combined with attributes and a color pair identifier in a chtype datum, which is often an alias of int. A string of curses characters is similar to a C char string; a chtype string ends with an integral 0, the null curses character.
Attributes and a color pair identifier (with no corresponding character) can be stored in variables of chtype or attr_t type. In either case, they are accessed via an integral bit mask.
ncurses stores each cell of a WINDOW as a chtype. X/Open Curses does not specify the sizes of the character code or color pair identifier, nor the quantity of attribute bits, in chtype; these are implementation-dependent. ncurses uses eight bits for the character code. An application requiring a wider character type, for instance to represent Unicode, should use the wide-character API. π§
okay so ncursesw is the library in its βwideβ configuration β the version that actually handles character encodings needing a bigger data type than char (which is a byte-sized type, bless it) can represent. It provides extra functions that complement the ones in the non-wide library, specifically wherever the size of the underlying character type is significant. π
And there's a naming convention β a somewhat regular one, the man page said it, not me β that relates a whole bunch of the wide variants to their non-wide counterparts: if a non-wide function name contains ch or str, you prefix it with _w and boom, that's your wide counterpart. Like, waddch becomes wadd_wch. slay. β¨
Exception time π¨: ins_nwstr (and its variants) is spelled exactly thus, instead of insn_wstr. And the exceptions that add only a w comprise addwstr, inwstr, and their variants. iykyk π
This convention is straight-up inapplicable to some non-wide function names, so other transformations get used for the wide configuration:
- the window background management function
bkgdbecomesbkgrnd - the window border-drawing and -clearing functions get suffixed with
_set - character attribute manipulation functions like
attronbecomeattr_on
Now the data types, bestie, because this is the part that's giving β¨actually importantβ¨:
cchar_tβ a curses complex character, and it corresponds to the non-wide-character configuration'schtype. It's a structure type because it needs more storage than a standard scalar type offers. Why? Because a character code may not be representable as achar, and on top of that, more than one character may occupy a cell (as with accent marks and other diacritics). Here's the breakdown:- Each character is of type
wchar_t. - A complex character contains one spacing character and zero or more non-spacing characters (see below π).
- A string of complex characters ends with a
cchar_twhosewchar_tmember is the null wide character. - Attributes and a color pair identifier are stored in separate fields of the structure β not combined into an integer the way they are in
chtype. π
- Each character is of type
wchar_tβ stores a wide character. Likechtype, it may be an alias ofint. Depending on the character encoding, a wide character may be spacing (meaning it occupies a character cell by itself and typically accompanies cursor advancement) or non-spacing (meaning it occupies the same cell as a spacing character, is often regarded as a βmodifierβ of the base glyph it combines with, and typically does not advance the cursor). π¦wint_tβ can store awchar_tor the constantWEOF, analogously to theint-sized character manipulation functions of ISO C and its constantEOF. πΈ
ncurses stores each cell of a WINDOW as a cchar_t, just so you know. setcchar(3X) and getcchar(3X) are the ones that store and retrieve cchar_t data. And the wide library API of ncurses depends on two data types standardized by ISO C95 β that's wchar_t and wint_t right up there. π
π Function Name Index π
The following table lists the curses functions provided in the non-wide and wide APIs, plus the corresponding man pages that describe them. Those flagged with * are ncurses-specific β neither described by X/Open Curses nor present in SVr4. No cap. π€
Heads up bestie: the actual table lives in the next chunk of this page, so don't come for me β it's coming, and every single entry is gonna be there. π
okay so this next bit is literally the master directory β every single curses function in the game, alphabetically, mapped to the man page that actually documents it ποΈβ¨ read it like a phone book for terminal wizards, bestie. left side = the thing you call, right side = where the real tea is spilled. a * at the end of a page name is just carried over exactly like the original has it, so don't come for me about the asterisks π
COLOR_PAIRβcurs_color(3X)PAIR_NUMBERβcurs_color(3X)add_wchβcurs_add_wch(3X)add_wchnstrβcurs_add_wchstr(3X)add_wchstrβcurs_add_wchstr(3X)addchβcurs_addch(3X)addchnstrβcurs_addchstr(3X)addchstrβcurs_addchstr(3X)addnstrβcurs_addstr(3X)addnwstrβcurs_addwstr(3X)addstrβcurs_addstr(3X)addwstrβcurs_addwstr(3X)alloc_pairβnew_pair(3X)*assume_default_colorsβdefault_colors(3X)*attr_getβcurs_attr(3X)attr_offβcurs_attr(3X)attr_onβcurs_attr(3X)attr_setβcurs_attr(3X)attroffβcurs_attr(3X)attronβcurs_attr(3X)attrsetβcurs_attr(3X)baudrateβcurs_termattrs(3X)beepβcurs_beep(3X)bkgdβcurs_bkgd(3X)bkgdsetβcurs_bkgd(3X)bkgrndβcurs_bkgrnd(3X)bkgrndsetβcurs_bkgrnd(3X)borderβcurs_border(3X)border_setβcurs_border_set(3X)boxβcurs_border(3X)box_setβcurs_border_set(3X)can_change_colorβcurs_color(3X)cbreakβcurs_inopts(3X)chgatβcurs_attr(3X)clearβcurs_clear(3X)clearokβcurs_outopts(3X)clrtobotβcurs_clear(3X)clrtoeolβcurs_clear(3X)color_contentβcurs_color(3X)color_setβcurs_attr(3X)copywinβcurs_overlay(3X)curs_setβcurs_kernel(3X)curses_traceβcurs_trace(3X)*curses_versionβcurs_extend(3X)*def_prog_modeβcurs_kernel(3X)def_shell_modeβcurs_kernel(3X)define_keyβdefine_key(3X)*del_curtermβcurs_terminfo(3X)delay_outputβcurs_util(3X)delchβcurs_delch(3X)deletelnβcurs_deleteln(3X)delscreenβcurs_initscr(3X)delwinβcurs_window(3X)derwinβcurs_window(3X)doupdateβcurs_refresh(3X)dupwinβcurs_window(3X)echoβcurs_inopts(3X)echo_wcharβcurs_add_wch(3X)echocharβcurs_addch(3X)endwinβcurs_initscr(3X)eraseβcurs_clear(3X)erasecharβcurs_termattrs(3X)erasewcharβcurs_termattrs(3X)exit_cursesβcurs_memleaks(3X)*exit_terminfoβcurs_memleaks(3X)*extended_color_contentβcurs_color(3X)*extended_pair_contentβcurs_color(3X)*extended_slk_colorβcurs_slk(3X)*filterβcurs_util(3X)find_pairβnew_pair(3X)*flashβcurs_beep(3X)flushinpβcurs_util(3X)free_pairβnew_pair(3X)*get_escdelayβcurs_threads(3X)*get_wchβcurs_get_wch(3X)get_wstrβcurs_get_wstr(3X)getattrsβcurs_attr(3X)getbegxβcurs_legacy(3X)*getbegyβcurs_legacy(3X)*getbegyxβcurs_getyx(3X)getbkgdβcurs_bkgd(3X)getbkgrndβcurs_bkgrnd(3X)getccharβcurs_getcchar(3X)getchβcurs_getch(3X)getcurxβcurs_legacy(3X)*getcuryβcurs_legacy(3X)*getmaxxβcurs_legacy(3X)*getmaxyβcurs_legacy(3X)*getmaxyxβcurs_getyx(3X)getmouseβcurs_mouse(3X)*getn_wstrβcurs_get_wstr(3X)getnstrβcurs_getstr(3X)getparxβcurs_legacy(3X)*getparyβcurs_legacy(3X)*getparyxβcurs_getyx(3X)getstrβcurs_getstr(3X)getsyxβcurs_kernel(3X)getwinβcurs_util(3X)getyxβcurs_getyx(3X)halfdelayβcurs_inopts(3X)has_colorsβcurs_color(3X)has_icβcurs_termattrs(3X)has_ilβcurs_termattrs(3X)has_keyβcurs_getch(3X)*has_mouseβcurs_mouse(3X)*hlineβcurs_border(3X)hline_setβcurs_border_set(3X)idcokβcurs_outopts(3X)idlokβcurs_outopts(3X)immedokβcurs_outopts(3X)in_wchβcurs_in_wch(3X)in_wchnstrβcurs_in_wchstr(3X)in_wchstrβcurs_in_wchstr(3X)inchβcurs_inch(3X)inchnstrβcurs_inchstr(3X)inchstrβcurs_inchstr(3X)init_colorβcurs_color(3X)init_extended_colorβcurs_color(3X)*init_extended_pairβcurs_color(3X)*init_pairβcurs_color(3X)initscrβcurs_initscr(3X)innstrβcurs_instr(3X)innwstrβcurs_inwstr(3X)ins_nwstrβcurs_ins_wstr(3X)ins_wchβcurs_ins_wch(3X)ins_wstrβcurs_ins_wstr(3X)inschβcurs_insch(3X)insdellnβcurs_deleteln(3X)insertlnβcurs_deleteln(3X)insnstrβcurs_insstr(3X)insstrβcurs_insstr(3X)instrβcurs_instr(3X)intrflushβcurs_inopts(3X)inwstrβcurs_inwstr(3X)is_cbreakβcurs_inopts(3X)*is_clearedβcurs_opaque(3X)*is_echoβcurs_inopts(3X)*is_idcokβcurs_opaque(3X)*is_idlokβcurs_opaque(3X)*is_immedokβcurs_opaque(3X)*is_keypadβcurs_opaque(3X)*is_leaveokβcurs_opaque(3X)*is_linetouchedβcurs_touch(3X)is_nlβcurs_inopts(3X)*is_nodelayβcurs_opaque(3X)*is_notimeoutβcurs_opaque(3X)*is_padβcurs_opaque(3X)*is_rawβcurs_inopts(3X)*is_scrollokβcurs_opaque(3X)*is_subwinβcurs_opaque(3X)*is_syncokβcurs_opaque(3X)*is_term_resizedβresizeterm(3X)*is_wintouchedβcurs_touch(3X)isendwinβcurs_initscr(3X)key_definedβkey_defined(3X)*key_nameβcurs_util(3X)keyboundβkeybound(3X)*keynameβcurs_util(3X)keyokβkeyok(3X)*keypadβcurs_inopts(3X)killcharβcurs_termattrs(3X)killwcharβcurs_termattrs(3X)leaveokβcurs_outopts(3X)longnameβcurs_termattrs(3X)mcprintβcurs_print(3X)*metaβcurs_inopts(3X)mouse_trafoβcurs_mouse(3X)*mouseintervalβcurs_mouse(3X)*mousemaskβcurs_mouse(3X)*moveβcurs_move(3X)mvadd_wchβcurs_add_wch(3X)mvadd_wchnstrβcurs_add_wchstr(3X)mvadd_wchstrβcurs_add_wchstr(3X)mvaddchβcurs_addch(3X)mvaddchnstrβcurs_addchstr(3X)mvaddchstrβcurs_addchstr(3X)mvaddnstrβcurs_addstr(3X)mvaddnwstrβcurs_addwstr(3X)mvaddstrβcurs_addstr(3X)mvaddwstrβcurs_addwstr(3X)mvchgatβcurs_attr(3X)mvcurβcurs_kernel(3X)mvdelchβcurs_delch(3X)mvderwinβcurs_window(3X)mvget_wchβcurs_get_wch(3X)mvget_wstrβcurs_get_wstr(3X)mvgetchβcurs_getch(3X)mvgetn_wstrβcurs_get_wstr(3X)mvgetnstrβcurs_getstr(3X)
and yes, the mv-prefixed ones are all pointing at the same page as their non-mv siblings β the directory just lists them out one by one because it's being thorough like that π«Ά we're only partway through the alphabet rn, so don't close the tab, more letters are loading πβ¨
okay bestie we're back in the big ol' directory of names β every function in the library, pointing you at the page it actually lives on π still alphabetical, still nothing skipped, no cap.
mvgetstrβcurs_getstr(3X)mvhlineβcurs_border(3X)mvhline_setβcurs_border_set(3X)mvin_wchβcurs_in_wch(3X)mvin_wchnstrβcurs_in_wchstr(3X)mvin_wchstrβcurs_in_wchstr(3X)mvinchβcurs_inch(3X)mvinchnstrβcurs_inchstr(3X)mvinchstrβcurs_inchstr(3X)mvinnstrβcurs_instr(3X)mvinnwstrβcurs_inwstr(3X)mvins_nwstrβcurs_ins_wstr(3X)mvins_wchβcurs_ins_wch(3X)mvins_wstrβcurs_ins_wstr(3X)mvinschβcurs_insch(3X)mvinsnstrβcurs_insstr(3X)mvinsstrβcurs_insstr(3X)mvinstrβcurs_instr(3X)mvinwstrβcurs_inwstr(3X)mvprintwβcurs_printw(3X)mvscanwβcurs_scanw(3X)mvvlineβcurs_border(3X)mvvline_setβcurs_border_set(3X)mvwadd_wchβcurs_add_wch(3X)mvwadd_wchnstrβcurs_add_wchstr(3X)mvwadd_wchstrβcurs_add_wchstr(3X)mvwaddchβcurs_addch(3X)mvwaddchnstrβcurs_addchstr(3X)mvwaddchstrβcurs_addchstr(3X)mvwaddnstrβcurs_addstr(3X)mvwaddnwstrβcurs_addwstr(3X)mvwaddstrβcurs_addstr(3X)mvwaddwstrβcurs_addwstr(3X)mvwchgatβcurs_attr(3X)mvwdelchβcurs_delch(3X)mvwget_wchβcurs_get_wch(3X)mvwget_wstrβcurs_get_wstr(3X)mvwgetchβcurs_getch(3X)mvwgetn_wstrβcurs_get_wstr(3X)mvwgetnstrβcurs_getstr(3X)mvwgetstrβcurs_getstr(3X)mvwhlineβcurs_border(3X)mvwhline_setβcurs_border_set(3X)mvwinβcurs_window(3X)mvwin_wchβcurs_in_wch(3X)mvwin_wchnstrβcurs_in_wchstr(3X)mvwin_wchstrβcurs_in_wchstr(3X)mvwinchβcurs_inch(3X)mvwinchnstrβcurs_inchstr(3X)mvwinchstrβcurs_inchstr(3X)mvwinnstrβcurs_instr(3X)mvwinnwstrβcurs_inwstr(3X)mvwins_nwstrβcurs_ins_wstr(3X)mvwins_wchβcurs_ins_wch(3X)mvwins_wstrβcurs_ins_wstr(3X)mvwinschβcurs_insch(3X)mvwinsnstrβcurs_insstr(3X)mvwinsstrβcurs_insstr(3X)mvwinstrβcurs_instr(3X)mvwinwstrβcurs_inwstr(3X)mvwprintwβcurs_printw(3X)mvwscanwβcurs_scanw(3X)mvwvlineβcurs_border(3X)mvwvline_setβcurs_border_set(3X)
and that's the ENTIRE mv-flavored squad, bestie, we survived ππ«Ά
okay next up, the ns. iconic behaviour honestly β¨
napmsβcurs_kernel(3X)newpadβcurs_pad(3X)newtermβcurs_initscr(3X)newwinβcurs_window(3X)nlβcurs_inopts(3X)nocbreakβcurs_inopts(3X)nodelayβcurs_inopts(3X)noechoβcurs_inopts(3X)nofilterβcurs_util(3X)*nonlβcurs_inopts(3X)noqiflushβcurs_inopts(3X)norawβcurs_inopts(3X)notimeoutβcurs_inopts(3X)
(yes the lil * is literally part of how it's written there β don't strip it, it's part of the fit π
)
overlayβcurs_overlay(3X)overwriteβcurs_overlay(3X)
the ps now, and there are SO many good ones πΈ
pair_contentβcurs_color(3X)pecho_wcharβcurs_pad(3X)pechocharβcurs_pad(3X)pnoutrefreshβcurs_pad(3X)prefreshβcurs_pad(3X)printwβcurs_printw(3X)putpβcurs_terminfo(3X)putwinβcurs_util(3X)qiflushβcurs_inopts(3X)rawβcurs_inopts(3X)redrawwinβcurs_refresh(3X)refreshβcurs_refresh(3X)
refresh is literally the main character of this whole library, we love her π
reset_color_pairsβcurs_color(3X)*reset_prog_modeβcurs_kernel(3X)reset_shell_modeβcurs_kernel(3X)resettyβcurs_kernel(3X)resize_termβresizeterm(3X)*resizetermβresizeterm(3X)*restarttermβcurs_terminfo(3X)ripofflineβcurs_kernel(3X)savettyβcurs_kernel(3X)scanwβcurs_scanw(3X)scr_dumpβcurs_scr_dump(3X)scr_initβcurs_scr_dump(3X)scr_restoreβcurs_scr_dump(3X)scr_setβcurs_scr_dump(3X)scrlβcurs_scroll(3X)scrollβcurs_scroll(3X)scrollokβcurs_outopts(3X)set_curtermβcurs_terminfo(3X)set_escdelayβcurs_threads(3X)*set_tabsizeβcurs_threads(3X)*set_termβcurs_initscr(3X)setccharβcurs_getcchar(3X)setscrregβcurs_outopts(3X)setsyxβcurs_kernel(3X)setuptermβcurs_terminfo(3X)
okay the slk_ block is coming and it's giving "whole soft-key menu situation", brace yourself π
slk_attrβcurs_slk(3X)*slk_attr_offβcurs_slk(3X)slk_attr_onβcurs_slk(3X)slk_attr_setβcurs_slk(3X)slk_attroffβcurs_slk(3X)slk_attronβcurs_slk(3X)slk_attrsetβcurs_slk(3X)slk_clearβcurs_slk(3X)slk_colorβcurs_slk(3X)slk_initβcurs_slk(3X)slk_labelβcurs_slk(3X)slk_noutrefreshβcurs_slk(3X)slk_refreshβcurs_slk(3X)slk_restoreβcurs_slk(3X)slk_setβcurs_slk(3X)slk_touchβcurs_slk(3X)slk_wsetβcurs_slk(3X)
look at that, all seventeen of them, accounted for, no strays π
standendβcurs_attr(3X)standoutβcurs_attr(3X)start_colorβcurs_color(3X)subpadβcurs_pad(3X)subwinβcurs_window(3X)syncokβcurs_window(3X)
and the ts β this is where the terminal-geek lore lives, iykyk π
term_attrsβcurs_termattrs(3X)termattrsβcurs_termattrs(3X)termnameβcurs_termattrs(3X)tgetentβcurs_termcap(3X)tgetflagβcurs_termcap(3X)tgetnumβcurs_termcap(3X)tgetstrβcurs_termcap(3X)tgotoβcurs_termcap(3X)tigetflagβcurs_terminfo(3X)tigetnumβcurs_terminfo(3X)tigetstrβcurs_terminfo(3X)timeoutβcurs_inopts(3X)tiparmβcurs_terminfo(3X)tiparm_sβcurs_terminfo(3X)*tiscan_sβcurs_terminfo(3X)*touchlineβcurs_touch(3X)touchwinβcurs_touch(3X)tparmβcurs_terminfo(3X)
and bestie, look β tputs is listed TWICE, with two different homes. that's not a typo on my end, both are real:
tputsβcurs_termcap(3X)tputsβcurs_terminfo(3X)traceβcurs_trace(3X)*typeaheadβcurs_inopts(3X)
u and v, short and sweet π¦
unctrlβcurs_util(3X)unget_wchβcurs_get_wch(3X)ungetchβcurs_getch(3X)ungetmouseβcurs_mouse(3X)*untouchwinβcurs_touch(3X)use_default_colorsβdefault_colors(3X)*use_envβcurs_util(3X)use_extended_namesβcurs_extend(3X)*use_legacy_codingβlegacy_coding(3X)*use_screenβcurs_threads(3X)*use_tioctlβcurs_util(3X)*use_windowβcurs_threads(3X)*vid_attrβcurs_terminfo(3X)vid_putsβcurs_terminfo(3X)vidattrβcurs_terminfo(3X)vidputsβcurs_terminfo(3X)vlineβcurs_border(3X)vline_setβcurs_border_set(3X)vw_printwβcurs_printw(3X)vw_scanwβcurs_scanw(3X)vwprintwβcurs_printw(3X)vwscanwβcurs_scanw(3X)
and finally the w squad β the window girlies, the ones who do the actual work tbh π
wadd_wchβcurs_add_wch(3X)wadd_wchnstrβcurs_add_wchstr(3X)wadd_wchstrβcurs_add_wchstr(3X)waddchβcurs_addch(3X)waddchnstrβcurs_addchstr(3X)waddchstrβcurs_addchstr(3X)waddnstrβcurs_addstr(3X)waddnwstrβcurs_addwstr(3X)waddstrβcurs_addstr(3X)waddwstrβcurs_addwstr(3X)wattr_getβcurs_attr(3X)wattr_offβcurs_attr(3X)wattr_onβcurs_attr(3X)wattr_setβcurs_attr(3X)wattroffβcurs_attr(3X)wattronβcurs_attr(3X)wattrsetβcurs_attr(3X)wbkgdβcurs_bkgd(3X)wbkgdsetβcurs_bkgd(3X)wbkgrndβcurs_bkgrnd(3X)wbkgrndsetβcurs_bkgrnd(3X)wborderβcurs_border(3X)wborder_setβcurs_border_set(3X)wchgatβcurs_attr(3X)wclearβcurs_clear(3X)wclrtobotβcurs_clear(3X)wclrtoeolβcurs_clear(3X)wcolor_setβcurs_attr(3X)wcursyncupβcurs_window(3X)wdelchβcurs_delch(3X)wdeletelnβcurs_deleteln(3X)wecho_wcharβcurs_add_wch(3X)wechocharβcurs_addch(3X)wencloseβcurs_mouse(3X)*weraseβcurs_clear(3X)wget_wchβcurs_get_wch(3X)wget_wstrβcurs_get_wstr(3X)wgetbkgrndβcurs_bkgrnd(3X)wgetchβcurs_getch(3X)wgetdelayβcurs_opaque(3X)*wgetn_wstrβcurs_get_wstr(3X)wgetnstrβcurs_getstr(3X)wgetparentβcurs_opaque(3X)*wgetscrregβcurs_opaque(3X)*wgetstrβcurs_getstr(3X)whlineβcurs_border(3X)whline_setβcurs_border_set(3X)win_wchβcurs_in_wch(3X)win_wchnstrβcurs_in_wchstr(3X)win_wchstrβcurs_in_wchstr(3X)winchβcurs_inch(3X)winchnstrβcurs_inchstr(3X)winchstrβcurs_inchstr(3X)winnstrβcurs_instr(3X)winnwstrβcurs_inwstr(3X)wins_nwstrβcurs_ins_wstr(3X)wins_wchβcurs_ins_wch(3X)wins_wstrβcurs_ins_wstr(3X)winschβcurs_insch(3X)winsdellnβcurs_deleteln(3X)winsertlnβcurs_deleteln(3X)winsnstrβcurs_insstr(3X)winsstrβcurs_insstr(3X)winstrβcurs_instr(3X)winwstrβcurs_inwstr(3X)wmouse_trafoβcurs_mouse(3X)*wmoveβcurs_move(3X)wnoutrefreshβcurs_refresh(3X)wprintwβcurs_printw(3X)wredrawlnβcurs_refresh(3X)wrefreshβcurs_refresh(3X)wresizeβwresize(3X)*wscanwβcurs_scanw(3X)wscrlβcurs_scroll(3X)wsetscrregβcurs_outopts(3X)wstandendβcurs_attr(3X)wstandoutβcurs_attr(3X)wsyncdownβcurs_window(3X)wsyncupβcurs_window(3X)wtimeoutβcurs_inopts(3X)wtouchlnβcurs_touch(3X)wunctrlβcurs_util(3X)wvlineβcurs_border(3X)wvline_setβcurs_border_set(3X)
And yeah bestie, some of those are rocking a lil * at the end β that's literally how they show up on the original page, so we are not touching them. π
ncurses's screen-pointer extension adds extra functions that correspond to a whole bunch of the ones above, and every single one of them has an _sp suffix. Go peek at curs_sp_funcs(3X) if you're curious. β¨
Also, heads up: whether you even get some of the extensions depends on how ncurses was compiled. Look at the sections βALTERNATE CONFIGURATIONSβ and βEXTENSIONSβ down below for that tea. π«
π RETURN VALUE π
Unless the page says otherwise: functions that return integers give you the constant OK when things go well and ERR when they don't β go read curs_variables(3X) for that. Functions that return pointers hand back a null pointer when they fail. π
And like, as a general vibe: ncurses treats a null pointer you pass in as a function parameter as a failure too. Noted. π
Functions with the mv prefix do a little two-step β first they move the cursor, and if the position (y, x) is outside the window boundaries, they fail. Periodt. π«
πΈ ENVIRONMENT πΈ
These are the symbols from the process environment that customize how ncurses applications behave at runtime. Lowkey important: the library can be configured to disregard the variables TERMINFO, TERMINFO_DIRS, TERMPATH, and HOME β if the user is the superuser (root), or if the application uses setuid(2) or setgid(2). π
π’ BAUDRATE
The debugging library checks this variable whenever the application has redirected output to a file. ncurses reads its integral value as the terminal's line speed, in bits per second. If that value is missing or just not valid, ncurses falls back to 9600. It's giving "let developers build repeatable test cases" energy, because those test cases need to account for optimization decisions that depend on the terminal's line speed. π§ͺ
β¨οΈ CC (command character)
When this one's set, the command_character (cmdch) capability value of loaded terminfo entries changes to whatever this variable holds. Fr fr, very few terminfo entries even provide this feature. π
And here's the funny part β because CC is also used in development environments to store the C compiler's name, ncurses straight up ignores its value unless it's exactly one character long. one (1) character. that's the whole rule. π
π COLUMNS
This variable sets the width of the screen, measured in character cells. Apps running inside a windowing environment can usually suss out the width of the window they're executing in. ncurses caps things at an upper limit of 512 when it reads the value. If COLUMNS isn't defined and the terminal's screen size isn't coming from the terminal driver, ncurses uses the size given by the columns (cols) capability of the terminal type's entry in the terminfo database β if there is one. π
Okay this next bit matters: it's important that your application use the correct screen size. Automatic detection of it is not always possible, because an application may be running on a host that does not honor NAWS (Negotiations About Window Size), or it may be running as a different user ID than the owner of the terminal device file. SettingCOLUMNSand/orLINESoverrides the library's use of the screen size it got from the operating system. β οΈ
COLUMNS and LINES can each be specified independently, which is genuinely so useful for working around the misfeatures of legacy terminal type descriptions β xterm(1) descriptions specifying 65 lines were once notorious for this. For best results, avoid specifying cols and lines capability codes in terminfo descriptions of terminal emulators. π
use_env(3X) can disable use of the process environment when determining screen size. use_tioctl(3X) can update COLUMNS and LINES to match the screen size obtained from system calls or the terminal database. π¦
β±οΈ ESCDELAY
So here's the situation: for curses to tell apart the ESC character that comes from a user pressing the Escape key on the input device, versus an ESC that's actually beginning an escape sequence (the kind function keys love to produce), it waits after receiving the escape character β just for a sec β to see if more characters show up on the input stream within a short interval. π
A global variable ESCDELAY stores that interval, in milliseconds. The default is 1000 (one whole second), which is honestly adequate for most uses. This environment variable overrides it, and ncurses enforces an upper limit of 30,000 (that's 30 seconds) when reading the value. β³
The most common time you'd wanna change this is when you're working with a remote host over a slow communication channel. If the host running a curses application doesn't receive the characters of an escape sequence in a timely manner, the library can interpret them as multiple separate key stroke events. And conversely β a fast typist on a low-latency connection who happens to input an ESC followed by characters that match an escape sequence may experience confusing application behavior. π΅βπ«
xterm(1) mouse events are a form of escape sequence, so if your application makes heavy use of multiple-clicking, you may wish to lengthen the default value β because the delay applies to the composite multi-click event as well as the individual clicks. π±οΈ
Portable applications should not rely on ESCDELAY being present in either form, but setting the environment variable rather than the global variable does not create problems when compiling an application. π«Ά
And if keypad(3X) is disabled for the curses window receiving input, then ESCDELAY is irrelevant and a program has to disambiguate escape sequences all by itself. main character energy, honestly. π
π HOME
ncurses may read and write auxiliary terminal descriptions in .termcap and .terminfo files inside the user's home directory. π‘
π LINES
This is the counterpart to COLUMNS β it specifies the height of the screen in characters. The corresponding terminfo capability and code is lines. Go read the description of the COLUMNS variable above, it's the same story. β¬οΈ
π±οΈ MOUSE_BUTTONS_123
(OS/2 EMX port only β yeah, that's the whole vibe here.) OS/2 numbers a three-button mouse inconsistently with other platforms, in a way where 1 is the left button, 2 is the right, and 3 is the middle. This variable customizes the mouse button numbering. Its value must be three digits 1-3 in any order. By default, ncurses assumes a numbering of β132β. π
π¨ NCURSES_ASSUMED_COLORS
If set, this variable overrides the ncurses library's compiled-in assumption that the terminal's default colors are white on black β see default_colors(3X). Set the foreground and background color values with this environment variable by assigning it two integer values separated by a comma, indicating foreground and background color numbers, respectively. ποΈ
So like, for example: to tell ncurses not to assume anything about the colors, use a value of β-1,-1β. To make the default color scheme green on black on a terminal that uses ANSI X3.64/ECMA-48/ISO 6429 color assignments, use β2,0β. ncurses accepts integral values from -1 up to the value of the terminfo max_colors (colors) capability for the selected terminal type. π
π₯οΈ NCURSES_CONSOLE2 π₯οΈ
Okay so this one is MinGW port only, bestie. The Console2 program defectively handles the Microsoft Console API call CreateConsoleScreenBuffer β and any app that uses it will hang. π But you can simulate the action of this call by mapping coordinates and explicitly saving and restoring the original screen contents. Setting the environment variable NCGDB has the same effect. π«Ά
π§ NCURSES_GPM_TERMS π§
Linux only, okay? When ncurses is configured to use the GPM interface, this variable may list one or more terminal type names, delimited by vertical bars (|) or colons (:), against which the TERM variable (see below) is matched. An empty value disables the GPM interface, using ncurses's built-in support for xterm(1) mouse protocols instead. If the variable is absent, ncurses attempts to open GPM if TERM contains βlinuxβ. β¨
π NCURSES_NO_HARD_TABS π
ncurses may use tab characters in cursor movement optimization. In some cases, your terminal driver may not handle them properly. Set this environment variable to any value to disable the feature. You can also adjust your stty(1) settings to avoid the problem. π
π NCURSES_NO_MAGIC_COOKIE π
Many terminals store video attributes as properties of a character cell, as curses does. Historically, some recorded changes in video attributes as data that logically (but invisibly) occupied character cells on the display, switching attributes on or off, similarly to tags in a markup language, which then had to be overprinted to depict the cells' desired contents; these are termed βmagic cookiesβ. πͺ If the terminfo entry for your terminal type does not adequately describe its handling of magic cookies, set this variable to any value to instruct ncurses to disable attributes entirely. π
π NCURSES_NO_PADDING π
Most terminal type descriptions in the terminfo database detail hardware devices. Many people use curses-based applications in terminal emulator programs that run in a windowing environment. These programs can duplicate all of the important features of a hardware terminal, but often lack their limitations. Chief among these absent drawbacks is the problem of data flow management; that is, limiting the speed of communication to what the hardware could handle. Unless a hardware terminal is interfaced into a terminal concentrator (which does flow control), an application must manage flow itself to prevent overruns and data loss. π
A solution that comes at no hardware cost is for an application to pause transmission after directing a terminal to execute an operation that it performs slowly, such as clearing the display. Many terminal type descriptions, including that for the VT100, embed delay specifications in capabilities. You may wish to use these terminal descriptions without paying the performance penalty. Set NCURSES_NO_PADDING to any value to disable all but mandatory padding. Mandatory padding is used by such terminal capabilities as flash_screen (flash). β
π NCURSES_NO_SETBUF π
(Obsolete) Prior to internal changes developed in ncurses 5.9 (patches 20120825 through 20130126), the library used setbuf(3) to enable fully buffered output when initializing the terminal. This was done, as in SVr4 curses, to increase performance. For testing purposes, both of ncurses and of certain applications, this feature was made optional. Setting this variable disabled output buffering, leaving the output stream in the original (usually line-buffered) mode.
Nowadays, ncurses performs its own buffering and does not require this workaround; it does not modify the buffering of the standard output stream. This approach makes the library's handling of keyboard-initiated signals more robust. A drawback is that certain unconventional programs mixed stdio(3) calls with ncurses calls and (usually) got the behavior they expected. This is no longer the case; ncurses does not write to the standard output file descriptor through a stdio-buffered stream. π
As a special case, low-level API calls such as putp(3X) still use the standard output stream. High-level curses calls such as printw(3X) do not. β¨
π¦ NCURSES_NO_UTF8_ACS π¦
At initialization, ncurses inspects the TERM environment variable for special cases where VT100 forms-drawing characters (and the corresponding alternate character set terminfo capabilities) are known to be unsupported by terminal types that otherwise claim VT100 compatibility. Specifically, when running in a UTF-8 locale, the Linux virtual console device and the GNU screen(1) program ignore them. Set this variable to a nonzero value to instruct ncurses that the terminal's ACS support is broken; the library then outputs Unicode code points that correspond to the forms-drawing characters. Set it to zero (or a non-integer) to disable the special check for terminal type names matching βlinuxβ or βscreenβ, directing ncurses to assume that the ACS feature works if the terminal type description advertises it.
As an alternative to use of this variable, ncurses checks for an extended terminfo numeric capability U8 that can be compiled using tic -x. Examples follow. π
# linux console, if patched to provide working
# VT100 shift-in/shift-out, with corresponding font.
linux-vt100|linux console with VT100 line-graphics,
U8#0, use=linux,
# uxterm with vt100Graphics resource set to false
xterm-utf8|xterm relying on UTF-8 line-graphics,
U8#1, use=xterm,
The two-character name U8 was chosen to permit its use via ncurses's termcap interface. π
π₯ NCURSES_TRACE π₯
At initialization, ncurses (in its debugging configuration) checks for this variable's presence. If defined with an integral value, the library calls curses_trace(3X) with that value as the argument. π
π TERM π
The TERM variable denotes the terminal type. Each is distinct, though many are similar. It is commonly set by terminal emulators to help applications find a workable terminal description. Some choose a popular approximation such as βansiβ, βvt100β, or βxtermβ rather than an exact fit to their capabilities. Not infrequently, an application will have problems with that approach; for example, a key stroke may not operate correctly, or produce no effect but seeming garbage characters on the screen. π
Setting TERM has no effect on hardware operation; it affects the way applications communicate with the terminal. Likewise, as a general rule (xterm(1) being a rare exception), terminal emulators that allow you to specify TERM as a parameter or configuration value do not change their behavior to match that setting. π
π TERMCAP π
If ncurses is configured with termcap support, it checks for a terminal type description in termcap format if one in terminfo format is not available. Setting this variable directs ncurses to ignore the usual termcap database location, /etc/termcap; see TERMPATH below. TERMCAP should contain either a terminal description (with newlines stripped out), or a file name indicating where the information required by the TERM environment variable is stored. β¨
π TERMINFO π
ncurses can be configured to read terminal type description databases in various locations using different formats. This variable overrides the default location.
- Descriptions in terminfo format are normally stored in a directory tree using subdirectories named for the common first letters of the terminal types named therein. System V used this scheme.
- If ncurses is configured to use hashed databases, then
TERMINFOmay name its location, such as/usr/share/terminfo.db, rather than/usr/share/terminfo/.
The hashed database uses less disk space and is a little faster than the directory tree. However, some applications assume the existence of the directory tree and read it directly, ignoring the terminfo API.
- If ncurses is configured with termcap support, this variable may contain the location of a termcap file.
- If the value of
TERMINFObegins with βhex:β or βb64:β, ncurses uses the remainder of the value as a compiled terminfo description. You might produce the base64 format usinginfocmp(1M).
TERMINFO=$(infocmp -0 -Q2 -q)
export TERMINFO
ncurses uses the compiled description only if it corresponds to the terminal type identified by TERM.
Setting TERMINFO is the simplest, but not the only, way to direct ncurses to a terminal database. The search path is as follows.
- the last terminal database to which the running ncurses application wrote, if any
- the location specified by the
TERMINFOenvironment variable $HOME/.terminfo- locations listed in the
TERMINFO_DIRSenvironment variable - location(s) configured and compiled into ncurses
@TERMINFO_DIRS@/usr/share/misc/terminfo
πΈ TERMINFO_DIRS πΈ
This variable specifies a list of locations, akin to PATH, in which ncurses searches for the terminal type descriptions described by TERMINFO above. The list items are separated by colons on Unix and semicolons on OS/2 EMX. System V terminfo lacks a corresponding feature; TERMINFO_DIRS is an ncurses extension. β¨
π TERMPATH π
If TERMCAP does not hold a terminal type description or file name, then ncurses checks the contents of TERMPATH, a list of locations, akin to PATH, in which it searches for termcap terminal type descriptions. The list items are separated by colons on Unix and semicolons on OS/2 EMX.
If both TERMCAP and TERMPATH are unset or invalid, ncurses searches for the files /etc/termcap, /usr/share/misc/termcap, and $HOME/.termcap, in that order. π«Ά
β¨ ALTERNATE CONFIGURATIONS β¨
okay so ncurses can be built in so many different configurations, and it all comes down to the options you hand the configure script when you build the library. Run that script with the --help option to peruse every single one. A few of them are especially significant to you, the application developer employing ncurses. π
π --disable-overwrite π
This one avoids file name conflicts between ncurses and an existing curses installation already sitting on the system. The standard C preprocessor inclusion for the curses library is:
#include <curses.h>
If ncurses is installed with overwrite disabled, it puts its header files in a subdirectory instead. Example:
#include <ncurses/curses.h>
With --disable-overwrite, installation also omits a symbolic link that would otherwise cause the compilerβs -lcurses option to link object files with ncurses instead of the system curses library. The directory used by this configuration of ncurses is shown in section βSYNOPSISβ above. π«Ά
π --enable-widec π
(default for ABI 6+ since 2023-10-21) This enables support for wide characters. The configure script renames the ncurses library (and the tinfo library, if --with-termlib is also specified), appending w. An application that wants wide-character support then uses -lncursesw (or -ltinfow) instead of -lncurses (or -ltinfo) as its linker option. The ncurses++, panel, form, and menu libraries are renamed similarly. β¨
An application must also define certain C preprocessor symbols to enable wide-character features in curses header files, so it can use the extended (wide-character) functions. The symbol that enables these features has changed since X/Open Curses Issue 4. π
- Originally, the wide-character feature required the symbol
_XOPEN_SOURCE_EXTENDED, but that was valid only for XPG4 (1996). - Later, that was deemed conflicting with an
_XOPEN_SOURCEvalue of500. - As of mid-2018, no ncurses feature requires a
_XOPEN_SOURCEvalue greater than600. However, X/Open Curses Issue 7 (2009) recommends defining it to700. - Alternatively, you can enable the feature by defining
NCURSES_WIDECHARwith the caveat that some header file other thancurses.hmay require a specific value for_XOPEN_SOURCE(or a system-specific symbol).
The curses.h header file installed for the wide-character library is designed to be compatible with the non-wide libraryβs header. Only the size of the WINDOW structure differs; few applications require more than pointers to WINDOW. π¦
If ncursesβs header files are installed allowing overwrite (the default, but see --disable-overwrite above), the wide-character libraryβs headers should be installed last by packaging systems and similar, to allow applications to be built using either library from the same set of headers. π
π --with-pthread π
This enables support for multi-threaded applications. The configure script renames the ncurses library (and the tinfo library, if --with-termlib is also specified), appending t (before any w added by --enable-widec). An application that wants support for multiple threads of execution then uses, for example, -lncursest (or -ltinfot) instead of -lncurses (or -ltinfo) as its linker option. The ncurses++, panel, form, and menu libraries are renamed similarly.
ncursest and ncursestw replace global variables such as LINES with macros allowing read-only access. At the same time, they provide functions to set these values. Very few applications require changes to work with this convention. no cap. π
π --with-shared, --with-normal, --with-debug, --with-profile π
These mandate compilation of the ncurses library (and the tinfo library, if --with-termlib is also specified) in the specified forms.
--with-sharedβ build the shared-library form.--with-normalβ build the normal (static) form.--with-debugβ build the debugging form.--with-profileβ build the profiling form.
The shared and normal (static) library names differ by their suffixes, as with libncurses.so and libncurses.a. The debugging and profiling libraries add a _g and a _p to the roots of these respective names, forming libncurses_g.so and libncurses_p.a, for example. The ncurses++, panel, form, and menu libraries are made available similarly. πΈ
π§ --with-termlib π§
This provides ncursesβs lower-level terminal interface functions (those that do not depend on the SCREEN and WINDOW abstractions) in a library named tinfo. This arrangement reduces an applicationβs linking and/or loading times when it does not require cursesβs higher-level features. β
The following pages document curses functions provided by tinfo.
curs_extend(3X)β miscellaneous ncurses extensionscurs_inopts(3X)β curses input optionscurs_kernel(3X)β low-level curses routinescurs_termattrs(3X)β curses environment query routinescurs_termcap(3X)β curses emulation of termcapcurs_terminfo(3X)β curses interface to terminfo databasecurs_util(3X)β miscellaneous curses utility routines
π --with-trace π
This exposes the curses_trace(3X) function in the ncurses(w) shared and static libraries. Normally, it is available only in the debugging library. (If --with-termlib is also specified, tinfo(w) rather than ncurses(w) supplies the deprecated trace(3X) function.) An applicationβs configuration script should check for the functionβs existence rather than assuming its confinement to the debugging library. π₯
π FILES π
/usr/share/tabsetβ tab stop initialization database/usr/share/misc/terminfoβ compiled terminal capability database
π NOTES π
X/Open Curses permits most functions it specifies to be made available as macros as well. ncurses does so:
- for functions that return values via their parameters,
- to support obsolete features,
- to reuse functions (for example, those that move the cursor before another operation), and
- in a few special cases.
If the standard output file descriptor of an ncurses program is redirected to something that is not a terminal device, the library writes screen updates to the standard error file descriptor. This was an undocumented feature of SVr3 curses. π
See subsection βHeader Filesβ below regarding symbols exposed by inclusion of curses.h. π«Ά
π EXTENSIONS π
ncurses enables an application to capture mouse events from certain terminals, including xterm(1); see curs_mouse(3X). π
ncurses provides a means of responding to window resizing events, as when running in a GUI terminal emulator application such as xterm; see resizeterm(3X) and wresize(3X). π¦
ncurses allows an application to query the terminal for the presence of a wide variety of special keys; see has_key(3X). β¨
ncurses extends the fixed set of function key capabilities specified by X/Open Curses by allowing the application programmer to define additional key events at runtime; see define_key(3X), key_defined(3X), keybound(3X), and keyok(3X). π
ncurses can exploit the capabilities of terminals implementing ISO 6429/ECMA-48 SGR 39 and SGR 49 sequences, which allow an application to reset the terminal to its original foreground and background colors. From a userβs perspective, the application is able to draw colored text on a background whose color is set independently, providing better control over color contrasts. See default_colors(3X). π
An ncurses application can eschew knowledge of SCREEN and WINDOW structure internals, instead using accessor functions such as is_cbreak(3X) and is_scrollok(3X). π
ncurses enables an application to direct its output to a printer attached to the terminal device; see curs_print(3X). π¨οΈ
ncurses offers slk_attr(3X) as a counterpart of attr_get(3X) for soft-label key lines, and extended_slk_color(3X) as a form of slk_color(3X) that can gather color information from them when many colors are supported. π
ncurses permits modification of unctrl(3X)βs behavior; see use_legacy_coding(3X). π§
Rudimentary support for multi-threaded applications may be available; see curs_threads(3X). π
Functions that ease the management of multiple screens can be exposed; see curs_sp_funcs(3X). πΈ
To aid applications to debug their memory usage, ncurses optionally offers functions to more aggressively free memory it dynamically allocates itself; see curs_memleaks(3X). π
The library facilitates auditing and troubleshooting of its behavior; see curs_trace(3X). π₯
Compiling ncurses with the option-DUSE_GETCAPcauses it to fall back to reading/etc/termcapif the terminal setup code cannot find a terminfo entry corresponding toTERM. Use of this feature is not recommended, as it essentially includes an entire termcap compiler in the ncurses startup code, at a cost in memory usage and application launch latency. π
PDCurses and NetBSD curses incorporate some ncurses extensions. Individual man pages indicate where this is the case. π«Ά
π PORTABILITY π
Okay bestie, portability tea time β. X/Open Curses defines two levels of conformance: βbaseβ and βenhancedβ β¨. The enhanced level includes several additional features, such as wide-character and color support. ncurses intends base-level conformance with X/Open Curses, and supports all features of its enhanced level except the untic utility. The differences between X/Open Curses and ncurses are documented in the βPORTABILITYβ sections of the applicable man pages. Periodt π
.
π Error Checking π
In many cases, X/Open Curses is vague about error conditions, omitting some of the SVr4 documentation.
Unlike other implementations, ncurses checks pointer parameters, such as those to WINDOW structures, to ensure that they are not null. This is done primarily to guard against programmer error. The standard interface does not provide a way for the library to tell an application which of several possible errors occurred. An application that relies on ncurses to check its function parameters for validity limits its portability and robustness. No cap π«Ά.
π§Έ Padding Differences π§Έ
In historical curses implementations, delays embedded in the terminfo capabilities carriage_return (cr), scroll_forward (ind), cursor_left (cub1), form_feed (ff), and tab (ht) activated corresponding delay bits in the Unix terminal driver. ncurses performs all padding by sending NUL bytes to the device. This method is slightly more expensive, but narrows the interface to the Unix kernel significantly and correspondingly increases the package's portability. It's giving βrespect the kernel's boundariesβ energy πΈ.
π Header Files π
The header file curses.h itself includes the header files stdio.h and unctrl.h.
X/Open Curses has more to say,
The inclusion ofcurses.hmay make visible all symbols from the headersstdio.h,term.h,termios.h, andwchar.h.
but does not finish the story. A more complete account follows π.
- The first
curses, in 4BSD, provided acurses.hfile. BSD curses code includedcurses.handunctrl.hfrom an internal header filecurses.ext, where βextβ abbreviated βexternsβ. The implementations ofprintwandscanwused undocumented internal functions of the standard I/O library (_doprntand_doscan), but nothing incurses.hitself relied uponstdio.h. SVr2curses addednewterm, which relies uponstdio.hbecause its function prototype employs theFILEtype.SVr4curses addedputwinandgetwin, which also usestdio.h. X/Open Curses specifies all three of these functions.SVr4curses and X/Open Curses do not require the developer to includestdio.hbeforecurses.h. Both document use of curses as requiring onlycurses.h. As a result, standardcurses.halways includesstdio.h.- X/Open Curses and
SVr4curses are inconsistent with respect tounctrl.h. As noted incurs_util(3X),ncursesincludesunctrl.hfromcurses.h(asSVr4does). - X/Open Curses's comments about
term.handtermios.hmay refer to HP-UX and AIX. HP-UX curses includesterm.hfromcurses.hto declaresetuptermincurses.h, butncursesand Solaris curses do not. AIX curses includesterm.handtermios.h. Again,ncursesand Solaris curses do not. - X/Open Curses says that
curses.hmay includeterm.h, but does not require it to do so. Some programs use functions declared in bothcurses.handterm.h, and must include both header files in the same translation unit. The header files supplied byncursesinclude the standard library headers required for its declarations, soncurses's own header files can be included in any order. For portability even to old AIX systems, includecurses.hbeforeterm.h. - X/Open Curses says βmay make visibleβ because including a header file does not necessarily make visible all of the symbols in it (consider
#ifdefand similar). For instance,ncurses'scurses.hmay includewchar.hif the proper symbol is defined, and ifncursesis configured for wide-character support. Ifwchar.his included, its symbols may be made visible depending on the value of the_XOPEN_SOURCEfeature test macro. - X/Open Curses mandates an application's inclusion of one standard C library header in a special case:
stdarg.hbeforecurses.hto prototype the functionsvw_printwandvw_scanw(as well as the obsoletevwprintwandvwscanw). Each of these takes a variadic argument list, ava_listparameter, like that ofprintf(3).SVr3curses introduced the two obsolete functions, and X/Open Curses the others. In between,SVr4curses provided for the possibility that an application might include eithervarargs.horstdarg.h. These represented contrasting approaches to handling variadic argument lists. The older interface,varargs.h, used a pointer tocharfor variadic functions'va_listparameter. Later, the list acquired its own standard data type,va_list, defined instdarg.h, empowering the compiler to check the types of a function call's actual parameters against the formal ones declared in its prototype. No conforming implementations of X/Open Curses require an application to includestdarg.hbeforecurses.hbecause they either have allowed for a special type, or, likencurses, they includestdarg.hthemselves to provide a portable interface.
π AUTHORS π
Zeyd M. Ben-Halim, Eric S. Raymond, Thomas E. Dickey. Based on pcurses by Pavel Curtis. Legends only π₯.
π SEE ALSO π
curs_variables(3X), terminfo(5), user_caps(5)
And that's the whole entire vibe check, bestie π«Άπ This iconic page is from ncurses 6.6, dated 2025-11-11, and the manual page is ncurses(3X). Go forth and be portable! π
β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2015,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms