ncurses(3NCURSES)
โจ NAME โจ
okay so welcome to ncurses(3NCURSES) โ Library calls, bestie ๐ โ which is literally the character-cell terminal interface with optimized output. that's the whole vibe: draw on a terminal, read keys, don't be slow about it ๐
๐ SYNOPSIS ๐
#include <curses.h>
that's it. that's the entry fee. slay ๐
๐ DESCRIPTION ๐
so the "new curses" library hands you โ yes you, the programmer โ a terminal-independent way of reading keyboard and mouse input and writing to character-cell displays, with output optimized so the screen updates stay as minimal as possible. no cap. ๐ธ
ncurses replaces the curses libraries from System V Release 4 Unix (โSVr4โ) and 4.4BSD Unix, and bestie, development on those ceased in the 1990s ๐ญ. this document describes ncurses version 6.6 (patch 20260608). ๐
so what can it even do? glad you asked:
- control the terminal screen's contents ๐ฅ๏ธ
- abstract and subdivide those contents with windows and pads ๐ช
- acquire keyboard and mouse events ๐ญ
- select color and rendering attributes (like bold or underline) โจ
- define and use soft label keys ๐ท๏ธ
- access the
terminfoterminal capability database ๐ - a termcap compatibility interface ๐
- an abstraction of the system's API for manipulating the terminal (like
termios(3)) ๐ง
ncurses implements the interface described by X/Open Curses Issue 7. and in all those behavioral details that X/Open didn't standardize? ncurses emulates the curses library of SVr4 and throws in a whole bunch of useful extensions. periodt. ๐
๐๏ธ how these man pages are organized (the section lineup)
ncurses man pages use several sections to clear up matters of usage and interoperability with other curses implementations. let me put you on:
- โNOTESโ describes issues and caveats that any user of the
ncursesAPI should be aware of โ like limitations on the size of an underlying integral type, or whether something exists as a preprocessor macro instead of a function definition (which means you can't take its address, rip ๐). this section also covers implementation details that matter to the programmer but that aren't standardized. - โEXTENSIONSโ presents
ncursesinnovations beyond the X/Open Curses standard and/or the SVr4 curses implementation. they're called extensions to signal that you can't implement them purely with the library API โ they require access to the library's internal state. iykyk ๐ฅ - โPORTABILITYโ discusses matters โ beyond just exercising extensions โ that you should think about when writing to a curses standard, or for multiple implementations. โ๏ธ
- โHISTORYโ examines points of detail in
ncursesand other curses implementations across the decades of their development, especially where precedent or inertia frustrated better design (and, in a few cases, where such inertia actually got overcome ๐).
๐ linking, because a curses app must be linked with the library
use the -lncurses option for your compiler or linker. ๐ ๏ธ
a debugging version of the library may be available; if it is, link with it using -lncurses_g. (your system integrator may have installed these libraries so you can use the options -lcurses and -lcurses_g, respectively. so nice of them ๐ซถ)
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, so setlocale(3) prepares it for curses library calls:
setlocale(LC_ALL, "");
if the locale isn't initialized this way, the library assumes characters are printable as in ISO 8859-1, so that it works with certain legacy programs. but bestie, you should initialize the locale โ do not expect consistent behavior from the library when the locale hasn't been set up. that's not a vibe check you want to fail ๐
initscr(3NCURSES) or newterm(3NCURSES) must be called to initialize curses before you use any functions that access or manipulate windows or screens. mandatory, fr fr.
to get character-at-a-time input without echoing โ and yes, most interactive, screen-oriented programs want exactly this โ use the following sequence:
initscr(); cbreak(); noecho();
most applications would do further setup like this:
noqiflush();
keypad(stdscr, TRUE);
a curses program then often enters an event-handling loop. ๐ call endwin(3NCURSES) before exiting. don't just dip, say goodbye properly. ๐
๐ 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(3NCURSES). โญ
a curses library does not manage overlapping windows (but see below ๐). so you've got two paths:
- use
stdscrto manage one screen-filling window, or - tile the screen into non-overlapping windows and not use
stdscrat all.
mixing the two approaches will result in unpredictable and undesired effects. โ ๏ธ pick a lane, bestie.
functions let you manipulate a window and the cursor identifying the cell within it where the next operation will occur. among those, the most basic are move(3NCURSES) and addch(3NCURSES): they place the cursor within stdscr and write a character to stdscr, respectively. iconic duo ๐
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(3NCURSES) 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 โ and the management of that information is the province of the terminfo(3NCURSES) 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 pad(3NCURSES). ๐๏ธ
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 color(3NCURSES) and attr(3NCURSES). ๐
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(3NCURSES). ๐ผ๏ธ
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(3NCURSES) and getch(3NCURSES). โจ๏ธ
ncurses provides reimplementations of the SVr4 panel(3NCURSES), form(3FORM), and menu(3MENU) libraries; they permit overlapping windows and ease construction of user interfaces with curses. ๐งฉ
๐ 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 from there overrides that obtained by terminfo. ๐ an ncurses extension supports resizable terminal displays; see wresize(3NCURSES).
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 /etc/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. here's the decoder ring ๐ฎ:
- prefixed with โwโ โ requires a
WINDOWpointer argument - prefixed with โmvโ โ first performs cursor movement using
wmove(3NCURSES) - prefixed with โmvwโ โ both of the above, together โจ
the โwโ function is typically the elemental one; removing that prefix usually means it operates 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โ 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 achtypedatum, which is often an alias ofint. a string of curses characters is similar to a Ccharstring; achtypestring ends with an integral0, 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're 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. ๐
ncursesw is the library in its โwideโ configuration โ the one that handles character encodings too chonky for char (a byte-sized type) to represent. ๐ It brings extra functions that complement the ones in the non-wide library wherever the size of the underlying character type is actually a big deal.
Okay so the naming convention? Lowkey iconic. If a non-wide function name contains ch or str, you prefix it with _w to get its wide counterpart. So waddch becomes wadd_wch. โจ And there's an exception, bestie: ins_nwstr (and its variants) is spelled exactly like that instead of insn_wstr. (The exceptions that only add a w are addwstr, inwstr, and their variants.) ๐
No cap, that convention just doesn't apply to some non-wide function names, so the wide configuration does other transformations instead: the window background management function bkgd becomes bkgrnd; the window border-drawing and -clearing functions get _set tacked on the end; and character attribute manipulation functions like attron become attr_on. ๐
cchar_tโ a curses complex character, and it's the wide config's answer tochtypefrom the non-wide-character configuration. It's a structure type because it needs way more storage than a standard scalar type can give it, fr fr. A character code might not even be representable as achar, and on top of that, more than one character can occupy a single cell (think accent marks and other diacritics). Each character is of typewchar_t; a complex character contains one spacing character and zero or more non-spacing characters (see below). A string of complex characters ends with acchar_twhosewchar_tmember is the null wide character. Attributes and a color pair identifier live in separate fields of the structure โ they are not combined into an integer the way they are inchtype. ๐ซถ
ncurses stores each cell of a WINDOW as a cchar_t. setcchar(3NCURSES) and getcchar(3NCURSES) are the ones that store and retrieve cchar_t data. ๐
The wide library API of ncurses depends on two data types standardized by ISO C95.
wchar_tโ stores a wide character. Likechtype, it may be an alias ofint. Depending on the character encoding, a wide character can be:- spacing โ meaning it occupies a character cell by itself and typically comes with cursor advancement, or
- non-spacing</se> โ 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. ๐ธ
โจ Function Name Index โจ
The table below lists all the curses functions provided in the non-wide and wide APIs, plus the corresponding man pages that describe them. ๐ Any of them flagged with * are ncurses-specific โ neither described by X/Open Curses nor present in SVr4. ๐
(the table itself is pulling up, bestie โ keep scrolling ๐ฆ)
okay so here's the master roster ๐ every single function name in the whole curses universe, plus the exact page you gotta go bother for it. the ones with a * got the little sparkle marker. don't skip, bestie, i'm not writing this twice:
COLOR_PAIRโcolor(3NCURSES)PAIR_NUMBERโcolor(3NCURSES)add_wchโadd_wch(3NCURSES)add_wchnstrโadd_wchstr(3NCURSES)add_wchstrโadd_wchstr(3NCURSES)addchโaddch(3NCURSES)addchnstrโaddchstr(3NCURSES)addchstrโaddchstr(3NCURSES)addnstrโaddstr(3NCURSES)addnwstrโaddwstr(3NCURSES)addstrโaddstr(3NCURSES)addwstrโaddwstr(3NCURSES)
that's the entire add family, we survived ๐ซถ
alloc_pairโnew_pair(3NCURSES)*assume_default_colorsโdefault_colors(3NCURSES)*attr_getโattr(3NCURSES)attr_offโattr(3NCURSES)attr_onโattr(3NCURSES)attr_setโattr(3NCURSES)attroffโattr(3NCURSES)attronโattr(3NCURSES)attrsetโattr(3NCURSES)baudrateโtermattrs(3NCURSES)beepโbeep(3NCURSES)bkgdโbkgd(3NCURSES)bkgdsetโbkgd(3NCURSES)bkgrndโbkgrnd(3NCURSES)bkgrndsetโbkgrnd(3NCURSES)borderโborder(3NCURSES)border_setโborder_set(3NCURSES)boxโborder(3NCURSES)box_setโborder_set(3NCURSES)
borders and boxes, the aesthetic queens ๐
can_change_colorโcolor(3NCURSES)cbreakโinopts(3NCURSES)chgatโattr(3NCURSES)clearโclear(3NCURSES)clearokโoutopts(3NCURSES)clrtobotโclear(3NCURSES)clrtoeolโclear(3NCURSES)color_contentโcolor(3NCURSES)color_setโattr(3NCURSES)copywinโoverlay(3NCURSES)curs_setโkernel(3NCURSES)curses_traceโtrace(3NCURSES)*curses_versionโextensions(3NCURSES)*def_prog_modeโkernel(3NCURSES)def_shell_modeโkernel(3NCURSES)define_keyโdefine_key(3NCURSES)*del_curtermโterminfo(3NCURSES)delay_outputโutil(3NCURSES)delchโdelch(3NCURSES)deletelnโdeleteln(3NCURSES)delscreenโinitscr(3NCURSES)delwinโwindow(3NCURSES)derwinโwindow(3NCURSES)doupdateโrefresh(3NCURSES)dupwinโwindow(3NCURSES)echoโinopts(3NCURSES)echo_wcharโadd_wch(3NCURSES)echocharโaddch(3NCURSES)endwinโinitscr(3NCURSES)eraseโclear(3NCURSES)erasecharโtermattrs(3NCURSES)erasewcharโtermattrs(3NCURSES)exit_cursesโmemleaks(3NCURSES)*exit_terminfoโmemleaks(3NCURSES)*extended_color_contentโcolor(3NCURSES)*extended_pair_contentโcolor(3NCURSES)*extended_slk_colorโslk(3NCURSES)*filterโutil(3NCURSES)find_pairโnew_pair(3NCURSES)*flashโbeep(3NCURSES)flushinpโutil(3NCURSES)free_pairโnew_pair(3NCURSES)*get_escdelayโthreads(3NCURSES)*get_wchโget_wch(3NCURSES)get_wstrโget_wstr(3NCURSES)getattrsโattr(3NCURSES)getbegxโlegacy(3NCURSES)*getbegyโlegacy(3NCURSES)*getbegyxโgetyx(3NCURSES)getbkgdโbkgd(3NCURSES)getbkgrndโbkgrnd(3NCURSES)getccharโgetcchar(3NCURSES)getchโgetch(3NCURSES)getcurxโlegacy(3NCURSES)*getcuryโlegacy(3NCURSES)*getmaxxโlegacy(3NCURSES)*getmaxyโlegacy(3NCURSES)*getmaxyxโgetyx(3NCURSES)getmouseโmouse(3NCURSES)*getn_wstrโget_wstr(3NCURSES)getnstrโgetstr(3NCURSES)getparxโlegacy(3NCURSES)*getparyโlegacy(3NCURSES)*getparyxโgetyx(3NCURSES)getstrโgetstr(3NCURSES)getsyxโkernel(3NCURSES)getwinโutil(3NCURSES)getyxโgetyx(3NCURSES)halfdelayโinopts(3NCURSES)has_colorsโcolor(3NCURSES)has_icโtermattrs(3NCURSES)has_ilโtermattrs(3NCURSES)has_keyโgetch(3NCURSES)*has_mouseโmouse(3NCURSES)*hlineโborder(3NCURSES)hline_setโborder_set(3NCURSES)idcokโoutopts(3NCURSES)idlokโoutopts(3NCURSES)immedokโoutopts(3NCURSES)in_wchโin_wch(3NCURSES)in_wchnstrโin_wchstr(3NCURSES)in_wchstrโin_wchstr(3NCURSES)inchโinch(3NCURSES)inchnstrโinchstr(3NCURSES)inchstrโinchstr(3NCURSES)init_colorโcolor(3NCURSES)init_extended_colorโcolor(3NCURSES)*init_extended_pairโcolor(3NCURSES)*init_pairโcolor(3NCURSES)initscrโinitscr(3NCURSES)
^ the main character, lowkey obsessed โจ
innstrโinstr(3NCURSES)innwstrโinwstr(3NCURSES)ins_nwstrโins_wstr(3NCURSES)ins_wchโins_wch(3NCURSES)ins_wstrโins_wstr(3NCURSES)inschโinsch(3NCURSES)insdellnโdeleteln(3NCURSES)insertlnโdeleteln(3NCURSES)insnstrโinsstr(3NCURSES)insstrโinsstr(3NCURSES)instrโinstr(3NCURSES)intrflushโinopts(3NCURSES)inwstrโinwstr(3NCURSES)is_cbreakโinopts(3NCURSES)*is_clearedโopaque(3NCURSES)*is_echoโinopts(3NCURSES)*is_idcokโopaque(3NCURSES)*is_idlokโopaque(3NCURSES)*is_immedokโopaque(3NCURSES)*is_keypadโopaque(3NCURSES)*is_leaveokโopaque(3NCURSES)*is_linetouchedโtouch(3NCURSES)is_nlโinopts(3NCURSES)*is_nodelayโopaque(3NCURSES)*is_notimeoutโopaque(3NCURSES)*is_padโopaque(3NCURSES)*is_rawโinopts(3NCURSES)*is_scrollokโopaque(3NCURSES)*is_subwinโopaque(3NCURSES)*is_syncokโopaque(3NCURSES)*is_term_resizedโresizeterm(3NCURSES)*is_wintouchedโtouch(3NCURSES)isendwinโinitscr(3NCURSES)
the whole is_ cinematic universe, truly a saga ๐ฆ
key_definedโkey_defined(3NCURSES)*key_nameโutil(3NCURSES)keyboundโkeybound(3NCURSES)*keynameโutil(3NCURSES)keyokโkeyok(3NCURSES)*keypadโinopts(3NCURSES)killcharโtermattrs(3NCURSES)killwcharโtermattrs(3NCURSES)leaveokโoutopts(3NCURSES)longnameโtermattrs(3NCURSES)mcprintโprint(3NCURSES)*metaโinopts(3NCURSES)mouse_trafoโmouse(3NCURSES)*mouseintervalโmouse(3NCURSES)*mousemaskโmouse(3NCURSES)*moveโmove(3NCURSES)mvadd_wchโadd_wch(3NCURSES)mvadd_wchnstrโadd_wchstr(3NCURSES)mvadd_wchstrโadd_wchstr(3NCURSES)mvaddchโaddch(3NCURSES)mvaddchnstrโaddchstr(3NCURSES)mvaddchstrโaddchstr(3NCURSES)mvaddnstrโaddstr(3NCURSES)mvaddnwstrโaddwstr(3NCURSES)mvaddstrโaddstr(3NCURSES)mvaddwstrโaddwstr(3NCURSES)mvchgatโattr(3NCURSES)mvcurโkernel(3NCURSES)mvdelchโdelch(3NCURSES)mvderwinโwindow(3NCURSES)mvget_wchโget_wch(3NCURSES)mvget_wstrโget_wstr(3NCURSES)mvgetchโgetch(3NCURSES)mvgetn_wstrโget_wstr(3NCURSES)mvgetnstrโgetstr(3NCURSES)mvgetstrโgetstr(3NCURSES)mvhlineโborder(3NCURSES)mvhline_setโborder_set(3NCURSES)mvin_wchโin_wch(3NCURSES)mvin_wchnstrโin_wchstr(3NCURSES)
โฆand the list just KEEPS going, bestie, because ncurses has more aliases than your fave has unreleased demos ๐
. Same deal as up top: the name on the left is what you actually type, the page on the right is where the real โจloreโจ lives, and a * means it's one of the special-edition girlies (you clocked that legend earlier ๐).
mvin_wchstrโin_wchstr(3NCURSES)mvinchโinch(3NCURSES)mvinchnstrโinchstr(3NCURSES)mvinchstrโinchstr(3NCURSES)mvinnstrโinstr(3NCURSES)mvinnwstrโinwstr(3NCURSES)mvins_nwstrโins_wstr(3NCURSES)mvins_wchโins_wch(3NCURSES)mvins_wstrโins_wstr(3NCURSES)mvinschโinsch(3NCURSES)mvinsnstrโinsstr(3NCURSES)mvinsstrโinsstr(3NCURSES)mvinstrโinstr(3NCURSES)mvinwstrโinwstr(3NCURSES)mvprintwโprintw(3NCURSES)mvscanwโscanw(3NCURSES)mvvlineโborder(3NCURSES)mvvline_setโborder_set(3NCURSES)
okay that whole mv-and-then-yank-a-line block is giving "move cursor, then do the thing" energy and honestly? consistent queen behavior ๐.
mvwadd_wchโadd_wch(3NCURSES)mvwadd_wchnstrโadd_wchstr(3NCURSES)mvwadd_wchstrโadd_wchstr(3NCURSES)mvwaddchโaddch(3NCURSES)mvwaddchnstrโaddchstr(3NCURSES)mvwaddchstrโaddchstr(3NCURSES)mvwaddnstrโaddstr(3NCURSES)mvwaddnwstrโaddwstr(3NCURSES)mvwaddstrโaddstr(3NCURSES)mvwaddwstrโaddwstr(3NCURSES)mvwchgatโattr(3NCURSES)mvwdelchโdelch(3NCURSES)mvwget_wchโget_wch(3NCURSES)mvwget_wstrโget_wstr(3NCURSES)mvwgetchโgetch(3NCURSES)mvwgetn_wstrโget_wstr(3NCURSES)mvwgetnstrโgetstr(3NCURSES)mvwgetstrโgetstr(3NCURSES)mvwhlineโborder(3NCURSES)mvwhline_setโborder_set(3NCURSES)mvwinโwindow(3NCURSES)mvwin_wchโin_wch(3NCURSES)mvwin_wchnstrโin_wchstr(3NCURSES)mvwin_wchstrโin_wchstr(3NCURSES)mvwinchโinch(3NCURSES)mvwinchnstrโinchstr(3NCURSES)mvwinchstrโinchstr(3NCURSES)mvwinnstrโinstr(3NCURSES)mvwinnwstrโinwstr(3NCURSES)mvwins_nwstrโins_wstr(3NCURSES)mvwins_wchโins_wch(3NCURSES)mvwins_wstrโins_wstr(3NCURSES)mvwinschโinsch(3NCURSES)mvwinsnstrโinsstr(3NCURSES)mvwinsstrโinsstr(3NCURSES)mvwinstrโinstr(3NCURSES)mvwinwstrโinwstr(3NCURSES)mvwprintwโprintw(3NCURSES)mvwscanwโscanw(3NCURSES)mvwvlineโborder(3NCURSES)mvwvline_setโborder_set(3NCURSES)
not the mvw prefix showing up like it pays rent here ๐ญ move + window + do-the-thing, the trio that ate and left no crumbs ๐.
napmsโkernel(3NCURSES)newpadโpad(3NCURSES)newtermโinitscr(3NCURSES)newwinโwindow(3NCURSES)
the four new* girlies: making pads, terms and windows out of thin air, main character energy fr fr โจ.
nlโinopts(3NCURSES)nocbreakโinopts(3NCURSES)nodelayโinopts(3NCURSES)noechoโinopts(3NCURSES)nofilterโutil(3NCURSES)*nonlโinopts(3NCURSES)noqiflushโinopts(3NCURSES)norawโinopts(3NCURSES)notimeoutโinopts(3NCURSES)
the no-squad ๐ literally the "turn that setting OFF bestie" clique, and almost all of them clocked in at inopts(3NCURSES) except nofilter, who went solo to util(3NCURSES) with a lil star, because she's built different ๐.
overlayโoverlay(3NCURSES)overwriteโoverlay(3NCURSES)pair_contentโcolor(3NCURSES)pecho_wcharโpad(3NCURSES)pechocharโpad(3NCURSES)pnoutrefreshโpad(3NCURSES)prefreshโpad(3NCURSES)printwโprintw(3NCURSES)putpโterminfo(3NCURSES)putwinโutil(3NCURSES)
printw documenting itself is so self-referential and honestly iconic of her ๐. and the p* pad girlies (pecho_wchar, pechochar, pnoutrefresh, prefresh) all filed under pad(3NCURSES) โ obsessed with the consistency.
qiflushโinopts(3NCURSES)rawโinopts(3NCURSES)redrawwinโrefresh(3NCURSES)refreshโrefresh(3NCURSES)reset_color_pairsโcolor(3NCURSES)*reset_prog_modeโkernel(3NCURSES)reset_shell_modeโkernel(3NCURSES)resettyโkernel(3NCURSES)resize_termโresizeterm(3NCURSES)*resizetermโresizeterm(3NCURSES)*restarttermโterminfo(3NCURSES)ripofflineโkernel(3NCURSES)
qiflush is the un-no twin of noqiflush and they both live at inopts(3NCURSES) like the lil duo they are ๐ซถ. meanwhile the reset* crew split up: kernel(3NCURSES) got three of them, color(3NCURSES) got one (starry โจ), and the resize* besties both made it to resizeterm(3NCURSES) โญ.
savettyโkernel(3NCURSES)scanwโscanw(3NCURSES)scr_dumpโscr_dump(3NCURSES)scr_initโscr_dump(3NCURSES)scr_restoreโscr_dump(3NCURSES)scr_setโscr_dump(3NCURSES)scrlโscroll(3NCURSES)scrollโscroll(3NCURSES)scrollokโoutopts(3NCURSES)set_curtermโterminfo(3NCURSES)set_escdelayโthreads(3NCURSES)*set_tabsizeโthreads(3NCURSES)*set_termโinitscr(3NCURSES)setccharโgetcchar(3NCURSES)setscrregโoutopts(3NCURSES)setsyxโkernel(3NCURSES)setuptermโterminfo(3NCURSES)
the whole scr_* family went to scr_dump(3NCURSES) together like a carpool, no cap ๐. and set_escdelay + set_tabsize are giving "why are you two in threads(3NCURSES)?" energy, but they're both starry so you know they're fancy ๐.
slk_attrโslk(3NCURSES)*slk_attr_offโslk(3NCURSES)slk_attr_onโslk(3NCURSES)slk_attr_setโslk(3NCURSES)slk_attroffโslk(3NCURSES)slk_attronโslk(3NCURSES)slk_attrsetโslk(3NCURSES)slk_clearโslk(3NCURSES)slk_colorโslk(3NCURSES)slk_initโslk(3NCURSES)slk_labelโslk(3NCURSES)slk_noutrefreshโslk(3NCURSES)slk_refreshโslk(3NCURSES)slk_restoreโslk(3NCURSES)slk_setโslk(3NCURSES)slk_touchโslk(3NCURSES)slk_wsetโslk(3NCURSES)standendโattr(3NCURSES)standoutโattr(3NCURSES)start_colorโcolor(3NCURSES)subpadโpad(3NCURSES)subwinโwindow(3NCURSES)syncokโwindow(3NCURSES)
the ENTIRE slk_ roster pulling up to slk(3NCURSES) in matching outfits is the biggest slay of this whole list, periodt ๐ (only slk_attr brought her lil star โจ).
term_attrsโtermattrs(3NCURSES)termattrsโtermattrs(3NCURSES)termnameโtermattrs(3NCURSES)tgetentโtermcap(3NCURSES)tgetflagโtermcap(3NCURSES)tgetnumโtermcap(3NCURSES)tgetstrโtermcap(3NCURSES)tgotoโtermcap(3NCURSES)tigetflagโterminfo(3NCURSES)tigetnumโterminfo(3NCURSES)tigetstrโterminfo(3NCURSES)timeoutโinopts(3NCURSES)tiparmโterminfo(3NCURSES)tiparm_sโterminfo(3NCURSES)*tiscan_sโterminfo(3NCURSES)*touchlineโtouch(3NCURSES)touchwinโtouch(3NCURSES)tparmโterminfo(3NCURSES)tputsโtermcap(3NCURSES)tputsโterminfo(3NCURSES)traceโtrace(3NCURSES)*typeaheadโinopts(3NCURSES)
so the tget* and tiget* besties are literally the same energy in two different friend groups โ termcap(3NCURSES) vs terminfo(3NCURSES) โ and honestly? the way tputs is listed TWICE, once for each page, is such a poly icon move ๐ฆ. and yes, trace documents trace, we love a self-titled era ๐.
unctrlโutil(3NCURSES)unget_wchโget_wch(3NCURSES)ungetchโgetch(3NCURSES)ungetmouseโmouse(3NCURSES)*untouchwinโtouch(3NCURSES)use_default_colorsโdefault_colors(3NCURSES)*use_envโutil(3NCURSES)use_extended_namesโextensions(3NCURSES)*use_legacy_codingโlegacy_coding(3NCURSES)*use_screenโthreads(3NCURSES)*use_tioctlโutil(3NCURSES)*use_windowโthreads(3NCURSES)*
the un* squad undoing everything like the cleanup crew they are ๐ญ and use_window + use_screen both ran off to threads(3NCURSES) together, starry and unbothered โญ.
vid_attrโterminfo(3NCURSES)vid_putsโterminfo(3NCURSES)vidattrโterminfo(3NCURSES)vidputsโterminfo(3NCURSES)vlineโborder(3NCURSES)vline_setโborder_set(3NCURSES)vw_printwโprintw(3NCURSES)vw_scanwโscanw(3NCURSES)vwprintwโprintw(3NCURSES)vwscanwโscanw(3NCURSES)
no notes, the vid* four went to terminfo(3NCURSES) as a unit ๐ซถ and the vw_ vs vw naming duality is exactly the kind of chaos this library serves daily ๐.
wadd_wchโadd_wch(3NCURSES)wadd_wchnstrโadd_wchstr(3NCURSES)wadd_wchstrโadd_wchstr(3NCURSES)waddchโaddch(3NCURSES)waddchnstrโaddchstr(3NCURSES)waddchstrโaddchstr(3NCURSES)waddnstrโaddstr(3NCURSES)waddnwstrโaddwstr(3NCURSES)waddstrโaddstr(3NCURSES)waddwstrโaddwstr(3NCURSES)wattr_getโattr(3NCURSES)wattr_offโattr(3NCURSES)wattr_onโattr(3NCURSES)wattr_setโattr(3NCURSES)wattroffโattr(3NCURSES)wattronโattr(3NCURSES)wattrsetโattr(3NCURSES)wbkgdโbkgd(3NCURSES)wbkgdsetโbkgd(3NCURSES)wbkgrndโbkgrnd(3NCURSES)wbkgrndsetโbkgrnd(3NCURSES)wborderโborder(3NCURSES)wborder_setโborder_set(3NCURSES)wchgatโattr(3NCURSES)wclearโclear(3NCURSES)wclrtobotโclear(3NCURSES)wclrtoeolโclear(3NCURSES)wcolor_setโattr(3NCURSES)wcursyncupโwindow(3NCURSES)wdelchโdelch(3NCURSES)wdeletelnโdeleteln(3NCURSES)wecho_wcharโadd_wch(3NCURSES)wechocharโaddch(3NCURSES)wencloseโmouse(3NCURSES)*weraseโclear(3NCURSES)wget_wchโget_wch(3NCURSES)wget_wstrโget_wstr(3NCURSES)wgetbkgrndโbkgrnd(3NCURSES)wgetchโgetch(3NCURSES)wgetdelayโopaque(3NCURSES)*wgetn_wstrโget_wstr(3NCURSES)wgetnstrโgetstr(3NCURSES)wgetparentโopaque(3NCURSES)*wgetscrregโopaque(3NCURSES)*wgetstrโgetstr(3NCURSES)whlineโborder(3NCURSES)whline_setโborder_set(3NCURSES)win_wchโin_wch(3NCURSES)win_wchnstrโin_wchstr(3NCURSES)win_wchstrโin_wchstr(3NCURSES)winchโinch(3NCURSES)winchnstrโinchstr(3NCURSES)winchstrโinchstr(3NCURSES)winnstrโinstr(3NCURSES)winnwstrโinwstr(3NCURSES)wins_nwstrโins_wstr(3NCURSES)wins_wchโins_wch(3NCURSES)wins_wstrโins_wstr(3NCURSES)winschโinsch(3NCURSES)winsdellnโdeleteln(3NCURSES)winsertlnโdeleteln(3NCURSES)winsnstrโinsstr(3NCURSES)winsstrโinsstr(3NCURSES)winstrโinstr(3NCURSES)winwstrโinwstr(3NCURSES)wmouse_trafoโmouse(3NCURSES)*wmoveโmove(3NCURSES)wnoutrefreshโrefresh(3NCURSES)wprintwโprintw(3NCURSES)wredrawlnโrefresh(3NCURSES)wrefreshโrefresh(3NCURSES)wresizeโwresize(3NCURSES)*wscanwโscanw(3NCURSES)wscrlโscroll(3NCURSES)wsetscrregโoutopts(3NCURSES)wstandendโattr(3NCURSES)wstandoutโattr(3NCURSES)wsyncdownโwindow(3NCURSES)wsyncupโwindow(3NCURSES)wtimeoutโinopts(3NCURSES)wtouchlnโtouch(3NCURSES)wunctrlโutil(3NCURSES)wvlineโborder(3NCURSES)wvline_setโborder_set(3NCURSES)
okay so ncurses has this screen-pointer extension that adds extra functions matching a lot of the ones above, each one rocking an _sp suffix; peep sp_funcs(3NCURSES) for the deets. ๐
and lowkey, whether you get some of these extensions depends on how ncurses was compiled โ check the sections โALTERNATE CONFIGURATIONSโ and โEXTENSIONSโ down below. ๐ ๏ธ
๐ฏ RETURN VALUE
okay so unless the manpage says otherwise, functions that return integers give you OK when things are slay and ERR when they're a flop โ check curses_variables(3NCURSES) for the receipts. functions that return pointers? they hand you a null pointer on failure. and bestie, ncurses usually treats a null pointer passed as a parameter as a big ol' failure too. also, any function starting with mv does cursor movement first, and it'll fail if the position (y, x) is outside the window boundaries. no cap. ๐ฏ
๐ ENVIRONMENT
these process environment symbols let you customize how ncurses apps act at runtime. but heads up: the library can be configured to ignore TERMINFO, TERMINFO_DIRS, TERMPATH, and HOME if you're the superuser (root), or if the app uses setuid(2) or setgid(2). so yeah, security vibes. ๐
๐ข BAUDRATE
when the app has redirected output to a file, the debugging library peeks at this variable. ncurses takes its integral value as the terminal's line speed in bits per second. if that value is missing or just plain wrong, ncurses falls back to 9600. this lets devs build repeatable test cases that account for optimization choices based on the terminal's line speed. iykyk. ๐
โจ๏ธ CC (command character)
when you set this, the command_character (cmdch) capability value of any loaded terminfo entries changes to whatever this variable is. honestly, like, very few terminfo entries even have this feature.
and because this name is also used in dev environments to store the C compiler's name, ncurses straight up ignores its value if it's not exactly one character long. so don't try to put gcc in there. ๐
๐ COLUMNS
this variable is the screen width in character cells. apps running in a windowing environment can usually just grab the width of their window, but ncurses enforces an upper limit of 512 when reading the value. if COLUMNS isn't defined and the terminal's screen size isn't available from the terminal driver, ncurses uses the size from the columns (cols) capability of the terminal type's terminfo entry, if there is one.
it's super important that your app uses the correct screen size. automatic detection isn't always possible because the app might be running on a host that doesn't honor NAWS (Negotiations About Window Size), or as a different user ID than the owner of the terminal device file. setting COLUMNS and/or LINES overrides the library's use of the screen size from the operating system.
and you can set COLUMNS and LINES independently! that's clutch for dodging the weird quirks of legacy terminal type descriptions โ like, xterm(1) descriptions that said 65 lines were once totally notorious. for best results, don't put cols and lines capability codes in terminfo descriptions of terminal emulators. periodt.
use_env(3NCURSES) can turn off using the process environment for determining screen size. use_tioctl(3NCURSES) can update COLUMNS and LINES to match the screen size from system calls or the terminal database. ๐
โณ ESCDELAY
so for curses to tell the difference between an ESC character from you pressing the โEscapeโ key and one that's the start of an escape sequence (like function keys make), it waits after getting that escape character to see if more characters show up on the input stream within a short interval. there's a global variable ESCDELAY that stores this interval in milliseconds. the default 1000 (one second) is fine for most uses, but this environment variable overrides it. ncurses enforces an upper limit of 30,000 (30 seconds) when reading the value.
the most common reason you'd wanna change this is when you're working with a remote host over a slow connection. if the host running the curses app doesn't get the characters of an escape sequence in time, the library might think they're separate key presses. and on the flip side, a fast typist on a low-latency connection who hits ESC followed by characters that match an escape sequence might get super confusing app behavior. ๐ญ
also, xterm(1) mouse events are a type of escape sequence, so if your app does a lot of multiple-clicking, you might wanna lengthen the default value โ because the delay applies to the whole multi-click event, not just individual clicks. ๐ฑ๏ธ
portable apps shouldn't rely on ESCDELAY existing in either form, but setting the environment variable instead of the global variable won't cause problems when compiling. and if keypad(3NCURSES) is disabled for the curses window getting input, ESCDELAY is irrelevant and your program has to disambiguate escape sequences all by itself. good luck bestie. ๐
๐ HOME
ncurses might read and write extra terminal descriptions in .termcap and .terminfo files in the user's home directory. so like, keep an eye on those. ๐ก
๐ LINES
this is the counterpart to COLUMNS โ it sets the screen height in characters. the matching terminfo capability and code is lines. peep the COLUMNS description above for the full tea. โ
๐ฑ๏ธ MOUSE_BUTTONS_123
(OS/2 EMX port only, bestie) OS/2 numbers a three-button mouse weirdly compared to other platforms: 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 you set this, it overrides ncurses's compiled-in assumption that the terminal's default colors are white on black. check default_colors(3NCURSES) for more. set the foreground and background color values with this environment variable by giving it two integer values separated by a comma โ first is foreground, second is background.
for example, to tell ncurses not to assume anything about 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
(MinGW port only) the Console2 program has a defective handling of the Microsoft Console API call CreateConsoleScreenBuffer. apps that use it will hang. ๐ฑ but you can simulate what that call does by mapping coordinates, explicitly saving and restoring the original screen contents. setting the environment variable NCGDB has the same effect. so yeah, hack the planet. ๐ ๏ธ
๐ง NCURSES_GPM_TERMS
(Linux only) when ncurses is set up to use the GPM interface, this variable can list one or more terminal type names, separated by vertical bars (|) or colons (:), and it'll match against the TERM variable (see below). an empty value disables the GPM interface, so ncurses uses its built-in support for xterm(1) mouse protocols instead. if the variable isn't there at all, ncurses tries to open GPM if TERM contains โlinuxโ. ๐ญ
๐ NCURSES_NO_HARD_TABS
okay so bestie, sometimes ncurses is gonna use tab characters in its cursor movement optimization. efficient, iconic, we love her. BUT โ in some cases your terminal driver just does not handle tabs properly, and it all falls apart. ๐ so if that's happening to you, set this environment variable to any value at all and the feature gets disabled. you can also go tweak your stty(1) settings if you'd rather fix it that way. both are valid, you do you.
๐ NCURSES_NO_MAGIC_COOKIE
so like, a lot of terminals store video attributes as properties of a character cell โ which is literally what curses does too. but historically? some terminals recorded attribute changes as data that logically (but invisibly!!) occupied character cells on the display, flipping attributes on and off like tags in a markup language. and then those cells had to be overprinted to show the actual contents you wanted. these are what we call "magic cookies" ๐ชโจ
if the terminfo entry for your terminal type doesn't adequately describe how it handles magic cookies, set this variable to any value and ncurses will be instructed to disable attributes entirely. yes, entirely. she's dramatic like that.
๐ธ NCURSES_NO_PADDING
most of the terminal type descriptions in the terminfo database are describing actual hardware devices. but plenty of us are running curses-based apps inside terminal emulator programs chillin' in a windowing environment. those programs can duplicate all the important features of a hardware terminal โ highkey slay โ but they often lack the limitations.
and the biggest missing drawback? data flow management. that's the whole "limiting the speed of communication to what the hardware could handle" situation. unless a hardware terminal is interfaced into a terminal concentrator (which does flow control for you), an application has to manage flow itself to prevent overruns and data loss.
so here's a solution that costs zero hardware: an application just pauses transmission after telling the terminal to do something slow โ like clearing the display. and a ton of terminal type descriptions (including the one for the VT100) embed delay specifications right there in the capabilities. so you might wanna use those descriptions without paying the performance penalty. set NCURSES_NO_PADDING to any value to disable all but mandatory padding. and mandatory padding is what such terminal capabilities as flash_screen (flash) use. ๐ซถ
๐ NCURSES_NO_SETBUF
(Obsolete) so before the internal changes developed in ncurses 5.9 (patches 20120825 through 20130126), the library used setbuf(3) to enable fully buffered output when it initialized the terminal. it did this, just like in SVr4 curses, to boost performance. and 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.
these days though? ncurses does its own buffering and doesn't need this workaround at all; it does not modify the buffering of the standard output stream. this approach makes the library's handling of keyboard-initiated signals way more robust. one drawback: certain unconventional programs mixed stdio(3) calls with ncurses calls and (usually) got the behavior they expected. that is no longer the case โ ncurses does not write to the standard output file descriptor through a stdio-buffered stream.
as a special case though, low-level API calls such as putp(3NCURSES) still use the standard output stream. high-level curses calls such as printw(3NCURSES) do not. iykyk ๐
๐ฆ NCURSES_NO_UTF8_ACS
at initialization, ncurses inspects the TERM environment variable looking 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 just ignore them. ๐ญ
set this variable to a nonzero value to tell 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" โ which directs ncurses to assume the ACS feature works if the terminal type description advertises it.
as an alternative to using 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. little detail, big brain move. ๐
โญ NCURSES_TRACE
at initialization, ncurses (in its debugging configuration) checks for this variable's presence. if it's defined with an integral value, the library calls curses_trace(3NCURSES) with that value as the argument. that's it, that's the whole thing.
๐ TERM
the TERM variable denotes the terminal type. each one is distinct, though lots of them are similar. it's commonly set by terminal emulators to help applications find a workable terminal description. some of them choose a popular approximation like "ansi", "vt100", or "xterm" rather than an exact fit for their capabilities. and not infrequently, an application will have problems with that approach โ like maybe a keystroke doesn't operate correctly, or it does nothing except spew what looks like 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 let you specify TERM as a parameter or configuration value do not change their behavior to match that setting. so don't expect them to shapeshift, bestie.
๐ TERMCAP
if ncurses is configured with termcap support, it checks for a terminal type description in termcap format whenever one in terminfo format isn't 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
terminfoformat 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. rude, honestly.
- 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 compiledterminfodescription. you might produce the base64 format usinginfocmp(1).
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
/etc/terminfo:/lib/terminfo:/usr/share/terminfo/etc/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, so heads up: 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.
and 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. no skipping, no vibes-based ordering, just that order. ๐
โจ ALTERNATE CONFIGURATIONS โจ
okay so bestie, here's the tea โ โ there are so many different ncurses configurations possible, and they're all determined by the options you hand to the configure script when you're building the library. Run the script with the --help option to peruse them all ๐. A few of them are particularly significant to the application developer employing ncurses, so let's get into those ones.
๐ซ --disable-overwrite
Avoid file name conflicts between ncurses and an existing curses installation on the system. The standard C preprocessor inclusion for the curses library is as follows:
#include <curses.h>
If ncurses is installed disabling overwrite, it puts its header files in a subdirectory. Here's an example:
#include <ncurses/curses.h>
With --disable-overwrite, installation also omits a symbolic link that would 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) Enable 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 desirous of 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 to 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 of 500. - As of mid-2018, no ncurses feature requires an
_XOPEN_SOURCEvalue greater than 600. However, X/Open Curses Issue 7 (2009) recommends defining it to 700. - 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
Enable 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 desirous of 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.
๐ฆ --with-shared, --with-normal, --with-debug, --with-profile
Mandate compilation of the ncurses library (and the tinfo library, if --with-termlib is also specified) in the specified forms. 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
Provide 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.
extensions(3NCURSES)- miscellaneous ncurses extensionsinopts(3NCURSES)- curses input optionskernel(3NCURSES)- low-level curses routinestermattrs(3NCURSES)- curses environment query routinestermcap(3NCURSES)- curses emulation of termcapterminfo(3NCURSES)- curses interface to terminfo databaseutil(3NCURSES)- miscellaneous curses utility routines
๐ต๏ธ --with-trace
Expose the curses_trace(3NCURSES) 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(3NCURSES) 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/etc/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 mouse(3NCURSES). ๐ญ
ncurses provides a means of responding to window resizing events, as when running in a GUI terminal emulator application such as xterm; see resizeterm(3NCURSES) and wresize(3NCURSES).
ncurses allows an application to query the terminal for the presence of a wide variety of special keys; see has_key(3NCURSES).
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(3NCURSES), key_defined(3NCURSES), keybound(3NCURSES), and keyok(3NCURSES). โจ๏ธ
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(3NCURSES). ๐จ
An ncurses application can eschew knowledge of SCREEN and WINDOW structure internals, instead using accessor functions such as is_cbreak(3NCURSES) and is_scrollok(3NCURSES).
ncurses enables an application to direct its output to a printer attached to the terminal device; see print(3NCURSES). ๐จ๏ธ
ncurses offers slk_attr(3NCURSES) as a counterpart of attr_get(3NCURSES) for soft-label key lines, and extended_slk_color(3NCURSES) as a form of slk_color(3NCURSES) that can gather color information from them when many colors are supported.
ncurses permits modification of unctrl(3NCURSES)'s behavior; see use_legacy_coding(3NCURSES).
Rudimentary support for multi-threaded applications may be available; see threads(3NCURSES). ๐งต
Functions that ease the management of multiple screens can be exposed; see sp_funcs(3NCURSES).
To aid applications to debug their memory usage, ncurses optionally offers functions to more aggressively free memory it dynamically allocates itself; see memleaks(3NCURSES).
The library facilitates auditing and troubleshooting of its behavior; see trace(3NCURSES).
Compiling ncurses with the option -DUSE_GETCAP causes it to fall back to reading /etc/termcap if the terminal setup code cannot find a terminfo entry corresponding to TERM.
โ ๏ธ 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. like, it works, but at what cost bestie ๐ญ
PDCurses and NetBSD curses incorporate some ncurses extensions. Individual man pages indicate where this is the case. ๐
๐ PORTABILITY ๐
okay so X/Open Curses defines two levels of conformance, and they're called โbaseโ and โenhancedโ. the enhanced one comes with extra features like wide-character support and color support, cute. ncurses is aiming for base-level conformance with X/Open Curses, and it supports all the features of the enhanced level except the untic utility (yeah, that one didn't make the cut bestie).
all the differences between X/Open Curses and ncurses are documented in the โPORTABILITYโ sections of the applicable man pages. yes, they each have their own receipts โจ
๐ซถ Error Checking
in many cases, X/Open Curses is vague about error conditions and straight-up omits some of the SVr4 documentation. iconic of them honestly.
unlike other implementations, ncurses checks pointer parameters, like the ones to WINDOW structures, to make sure they're not null. it does this mainly to guard against programmer error (protecting you from yourself, bestie ๐). the standard interface doesn't give the library a way to tell an application which of several possible errors happened, so heads up: if an application relies on ncurses to check its function parameters for validity, that limits its portability and robustness. no cap.
๐ Padding Differences
back in historical curses implementations, the delays embedded in these terminfo capabilities activated corresponding delay bits in the Unix terminal driver:
carriage_return(cr)scroll_forward(ind)cursor_left(cub1)form_feed(ff)tab(ht)
ncurses does all padding by sending NUL bytes to the device. this method is slightly more expensive, yeah, but it narrows the interface to the Unix kernel significantly and correspondingly increases the package's portability. glow-up for the whole package fr fr ๐
๐ฆ Header Files
the header file curses.h itself includes the header files stdio.h and unctrl.h. periodt.
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 bestie that does not finish the story. here's the full lore:
- the first curses, in 4BSD, provided a
curses.hfile.- BSD curses code included
curses.handunctrl.hfrom an internal header filecurses.ext, where โextโ abbreviated โexternsโ. - the implementations of
printwandscanwused undocumented internal functions of the standard I/O library (_doprntand_doscan), but nothing incurses.hitself relied uponstdio.h.
- BSD curses code included
- SVr2 curses added
newterm, which relies uponstdio.hbecause its function prototype employs theFILEtype.- SVr4 curses added
putwinandgetwin, which also usestdio.h. - X/Open Curses specifies all three of these functions.
- SVr4 curses and X/Open Curses do not require the developer to include
stdio.hbeforecurses.h. both document use of curses as requiring onlycurses.h. - as a result, standard
curses.halways includesstdio.h. slay.
- SVr4 curses added
- X/Open Curses and SVr4 curses are inconsistent with respect to
unctrl.h.- as noted in
util(3NCURSES), ncurses includesunctrl.hfromcurses.h(as SVr4 does).
- as noted in
- X/Open Curses's comments about
term.handtermios.hmay refer to HP-UX and AIX.- HP-UX curses includes
term.hfromcurses.hto declaresetuptermincurses.h, but ncurses and Solaris curses do not. - AIX curses includes
term.handtermios.h. again, ncurses and Solaris curses do not.
- HP-UX curses includes
- X/Open Curses says that
curses.hmay includeterm.h, but does not require it to do so.- some programs use functions declared in both
curses.handterm.h, and must include both header files in the same translation unit. - the header files supplied by ncurses include the standard library headers required for its declarations, so ncurses's own header files can be included in any order ๐
- for portability even to old AIX systems, include
curses.hbeforeterm.h.
- some programs use functions declared in both
- 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's
curses.hmay includewchar.hif the proper symbol is defined, and if ncurses is configured for wide-character support. - if
wchar.his included, its symbols may be made visible depending on the value of the_XOPEN_SOURCEfeature test macro.
- for instance, ncurses's
- 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).- SVr3 curses introduced the two obsolete functions, and X/Open Curses the others.
- in between, SVr4 curses provided for the possibility that an application might include either
varargs.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. the compiler said โi got you bestie, type-checkedโ ๐ฅ - no conforming implementations of X/Open Curses require an application to include
stdarg.hbeforecurses.h, because they either have allowed for a special type, or, like ncurses, they includestdarg.hthemselves to provide a portable interface. she's self-sufficient ๐
๐ AUTHORS ๐
the icons behind all of this:
- Zeyd M. Ben-Halim
- Eric S. Raymond
- Thomas E. Dickey
based on pcurses by Pavel Curtis. legends only ๐
๐ SEE ALSO ๐
curses_variables(3NCURSES)terminfo(5)user_caps(5)
and that's the whole page bestie!! ๐ซถ this was ncurses 6.6, dated 2025-11-11 โ go forth and write some absolutely iconic terminal code, you ate ๐โจ๐
๐ฆ where this page comes from
- ubuntu stonking: ncurses-doc 6.6+20260608-2 ยท MIT/X11
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2015,2017 Free Software Foundation, Inc
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms