threads(3NCURSES)
threads(3NCURSES) π§΅β¨
okay bestie, this is the manual page for threads(3NCURSES) β it's a long one so it comes in three parts, and this is part one. buckle up π
πΈ NAME πΈ
NCURSES_WINDOW_CB, NCURSES_SCREEN_CB, get_escdelay, set_escdelay, set_tabsize, use_screen, use_window β curses support for multi-threaded applications
β¨ SYNOPSIS β¨
#include <curses.h>
/* data types */
typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);
typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);
int get_escdelay(void);
int set_escdelay(int ms);
int set_tabsize(int cols);
int use_screen(SCREEN *scr, NCURSES_SCREEN_CB func, void *data);
int use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data);
π DESCRIPTION π
okay so. the ncurses library can be configured to support multi-threaded applications in a rudimentary way. like, it's giving "we did the thing but we kept it lowkey" π. such a configuration produces a different set of libraries, named libncursest for example, since doing that alters ncurses's application binary interface (ABI). so yes bestie, that's a whole different ABI, not just a vibe change π«Ά
instead of modifying the programming interface (API) so that ncurses functions would expect an extra argument specifying a thread, the library adds functions β usable in any configuration β that hide the mutexes (mutual exclusion locks) you need to prevent concurrent access to variables shared by multiple threads of execution. so the locks are just... hidden behind the curtain, doing their thing, iconic behavior honestly π
ncurses threading support requires the use of functions to access members of the WINDOW structure (see opaque(3NCURSES)). and it further makes functions of the common global variables COLORS, COLOR_PAIRS, COLS, ESCDELAY, LINES, TABSIZE, curscr, newscr, and ttytype β maintaining them as read-only values in the SCREEN structure.
but even this is not enough to make an application using curses thread-safe. not me thinking we were done π
we would expect a multi-threaded application to have threads updating separate windows (on the same device), and separate screens (on different devices). further, applications expect a few of the global variables to be writable. the functions described here address these special situations. slay, problem solved π
the ESCDELAY and TABSIZE global variables are modified by some applications. to modify them in any configuration, use the set_escdelay or set_tabsize functions. other global variables are not modifiable. periodt, they said what they said π
get_escdelay retrieves ESCDELAY's value.
the use_window and use_screen functions provide coarse-grained mutexes for their respective WINDOW and SCREEN parameters; they call a user-supplied function, pass it a data parameter, and return the value from the user-supplied function to the application. like a lil relay race but make it locking πβοΈ
π Usage π
all ncurses library functions assume that the locale is not altered during operation. no mid-run glow-ups allowed bestie. in addition, they use data that is maintained within a hierarchy of scopes. it's giving nesting dolls πͺ
- global data used in the low-level
terminfoortermcapinterfaces - terminal data associated with a call to
set_curterm(3NCURSES)
terminal data are initialized when screens are created.
- screen data associated with a call to
newterm(3NCURSES)orinitscr(3NCURSES) - window data associated with a call to
newwin(3NCURSES)orsubwin(3NCURSES)
windows are associated with screens. pads are not necessarily associated with any particular screen. π
most curses applications operate on one or more windows within a single screen.
- reentrant data associated with βpureβ functions that alter no shared variables β¨
the following table lists the scope of each symbol in the ncurses library when configured to support multi-threaded applications.
π okay that's part 1 bestie, the table is coming in the next part, don't go anywhere π
okay bestie we're deep in it now π this next bit is the big master list β every single symbol this page is about, plus exactly what scope it lives in. it's giving phonebook but make it iconic. symbol β scope, alphabetical, zero skips. screenshot it, bookmark it, tattoo it idk. π«Ά
BCβ global πCOLORSβ screen (read-only)COLOR_PAIRβ reentrantCOLOR_PAIRSβ screen (read-only)COLSβ screen (read-only)ESCDELAYβ screen (read-only; see set_escdelay) β±οΈLINESβ screen (read-only)PAIR_NUMBERβ reentrantPCβ globalSPβ globalTABSIZEβ screen (read-only; see set_tabsize)UPβ globalacs_mapβ screen (read-only)add_wchβ window (stdscr)add_wchnstrβ window (stdscr)add_wchstrβ window (stdscr)addchβ window (stdscr) β¨addchnstrβ window (stdscr)addchstrβ window (stdscr)addnstrβ window (stdscr)addnwstrβ window (stdscr)addstrβ window (stdscr)addwstrβ window (stdscr)assume_default_colorsβ screenattr_getβ window (stdscr)attr_offβ window (stdscr)attr_onβ window (stdscr)attr_setβ window (stdscr)attroffβ window (stdscr)attronβ window (stdscr) πattrsetβ window (stdscr)baudrateβ screenbeepβ screen πbkgdβ window (stdscr) π¨bkgdsetβ window (stdscr)bkgrndβ window (stdscr)bkgrndsetβ window (stdscr)boolcodesβ global (read-only)boolfnamesβ global (read-only)boolnamesβ global (read-only)borderβ window (stdscr)border_setβ window (stdscr)boxβ window (stdscr) π¦box_setβ window (stdscr)can_change_colorβ terminal π¨cbreakβ screen β‘chgatβ window (stdscr)clearβ window (stdscr) π§Ήclearokβ windowclrtobotβ window (stdscr)clrtoeolβ window (stdscr)color_contentβ screen πcolor_setβ window (stdscr)copywinβ window (locks source, target) πcur_termβ terminal π»curs_setβ screen π±οΈcurscrβ screen (read-only)curses_versionβ global (read-only) π·οΈdef_prog_modeβ terminaldef_shell_modeβ terminaldefine_keyβ screendel_curtermβ screendelay_outputβ screendelchβ window (stdscr)deletelnβ window (stdscr)delscreenβ global (locks screen list, screen) ποΈdelwinβ global (locks window list) ποΈderwinβ screendoupdateβ screen πdupwinβ screen (locks window)echoβ screen π£echo_wcharβ window (stdscr)echocharβ window (stdscr)endwinβ screen πeraseβ window (stdscr) π§½erasecharβ window (stdscr)erasewcharβ window (stdscr)filterβ global π«§flashβ terminal β‘flushinpβ screen π°get_wchβ screen (input operation)get_wstrβ screen (input operation)getattrsβ windowgetbegxβ windowgetbegyβ windowgetbkgdβ windowgetbkgrndβ windowgetccharβ reentrantgetchβ screen (input operation) β¨οΈgetcurxβ windowgetcuryβ windowgetmaxxβ windowgetmaxyβ windowgetmouseβ screen (input operation) π±οΈgetn_wstrβ screen (input operation)getnstrβ screen (input operation)getparxβ windowgetparyβ windowgetstrβ screen (input operation)getwinβ screen (input operation)halfdelayβ screen β³has_colorsβ terminal πhas_icβ terminalhas_ilβ terminalhas_keyβ screenhlineβ window (stdscr)hline_setβ window (stdscr)idcokβ windowidlokβ windowimmedokβ windowin_wchβ window (stdscr)in_wchnstrβ window (stdscr)in_wchstrβ window (stdscr)inchβ window (stdscr)inchnstrβ window (stdscr)inchstrβ window (stdscr)init_colorβ screeninit_pairβ screeninitscrβ global (locks screen list) π¬innstrβ window (stdscr)innwstrβ window (stdscr)ins_nwstrβ window (stdscr)ins_wchβ window (stdscr)ins_wstrβ window (stdscr)inschβ window (stdscr)insdellnβ window (stdscr)insertlnβ window (stdscr)insnstrβ window (stdscr)insstrβ window (stdscr)instrβ window (stdscr)intrflushβ terminalinwstrβ window (stdscr)is_clearedβ windowis_idcokβ windowis_idlokβ windowis_immedokβ windowis_keypadβ windowis_leaveokβ windowis_linetouchedβ windowis_nodelayβ windowis_notimeoutβ windowis_scrollokβ windowis_syncokβ windowis_term_resizedβ terminalis_wintouchedβ windowisendwinβ screenkey_definedβ screenkey_nameβ global (static data)keyboundβ screenkeynameβ global (static data)keyokβ screenkeypadβ window β¨οΈkillcharβ terminalkillwcharβ terminalleaveokβ windowlongnameβ screen πmcprintβ terminalmetaβ screenmouse_trafoβ window (stdscr)mouseintervalβ screenmousemaskβ screen π±οΈmoveβ window (stdscr)mvadd_wchβ window (stdscr)mvadd_wchnstrβ window (stdscr)mvadd_wchstrβ window (stdscr)mvaddchβ window (stdscr)mvaddchnstrβ window (stdscr)mvaddchstrβ window (stdscr)mvaddnstrβ window (stdscr)mvaddnwstrβ window (stdscr)mvaddstrβ window (stdscr)mvaddwstrβ window (stdscr)mvchgatβ window (stdscr)mvcurβ screen πmvdelchβ window (stdscr)mvderwinβ window (stdscr)mvget_wchβ screen (input operation)mvget_wstrβ screen (input operation)mvgetchβ screen (input operation)mvgetn_wstrβ screen (input operation)mvgetnstrβ screen (input operation)mvgetstrβ screen (input operation)mvhlineβ window (stdscr)mvhline_setβ window (stdscr)mvin_wchβ window (stdscr)mvin_wchnstrβ window (stdscr)mvin_wchstrβ window (stdscr)mvinchβ window (stdscr)mvinchnstrβ window (stdscr)mvinchstrβ window (stdscr)mvinnstrβ window (stdscr)mvinnwstrβ window (stdscr)mvins_nwstrβ window (stdscr)mvins_wchβ window (stdscr)mvins_wstrβ window (stdscr)mvinschβ window (stdscr)mvinsnstrβ window (stdscr)mvinsstrβ window (stdscr)mvinstrβ window (stdscr)mvinwstrβ window (stdscr)mvprintwβ window (stdscr)mvscanwβ screenmvvlineβ window (stdscr)mvvline_setβ window (stdscr)mvwadd_wchβ windowmvwadd_wchnstrβ windowmvwadd_wchstrβ windowmvwaddchβ windowmvwaddchnstrβ windowmvwaddchstrβ windowmvwaddnstrβ windowmvwaddnwstrβ windowmvwaddstrβ windowmvwaddwstrβ windowmvwchgatβ windowmvwdelchβ windowmvwget_wchβ screen (input operation)mvwget_wstrβ screen (input operation)mvwgetchβ screen (input operation)mvwgetn_wstrβ screen (input operation)mvwgetnstrβ screen (input operation)mvwgetstrβ screen (input operation)mvwhlineβ windowmvwhline_setβ windowmvwinβ windowmvwin_wchβ windowmvwin_wchnstrβ windowmvwin_wchstrβ windowmvwinchβ windowmvwinchnstrβ windowmvwinchstrβ windowmvwinnstrβ windowmvwinnwstrβ windowmvwins_nwstrβ windowmvwins_wchβ windowmvwins_wstrβ windowmvwinschβ windowmvwinsnstrβ windowmvwinsstrβ windowmvwinstrβ windowmvwinwstrβ windowmvwprintwβ windowmvwscanwβ screenmvwvlineβ windowmvwvline_setβ windownapmsβ reentrant π΄newpadβ global (locks window list) πnewscrβ screen (read-only) πnewtermβ global (locks screen list) π¬newwinβ global (locks window list) πͺnlβ screen β©οΈnocbreakβ screennodelayβ window β‘noechoβ screen π€«nofilterβ globalnonlβ screennoqiflushβ terminalnorawβ screennotimeoutβ windownumcodesβ global (read-only)numfnamesβ global (read-only)numnamesβ global (read-only)ospeedβ global πoverlayβ window (locks source, target) πoverwriteβ window (locks source, target) βοΈpair_contentβ screenpecho_wcharβ screenpechocharβ screenpnoutrefreshβ screenprefreshβ screenprintwβ window π¨οΈ
and bestieβ¦ that's still not the whole page. keep scrolling, we're so not done π
β¦and the roster keeps going, bestie π we're still in the middle of the function-by-function breakdown, so let's just roll straight into it. Every name on the left, every thread-safety category on the right, exactly as written β don't come for me about the alignment, that's the original's whole aesthetic β¨
putp global
putwin window
qiflush terminal
raw screen
redrawwin window
refresh screen
reset_prog_mode screen
reset_shell_mode screen
resetty terminal
resize_term screen (locks window list)
resizeterm screen
restartterm screen
ripoffline global (static data)
savetty terminal
scanw screen
scr_dump screen
scr_init screen
scr_restore screen
scr_set screen
scrl window (stdscr)
scroll window
scrollok window
set_curterm screen
set_escdelay screen
set_tabsize screen
set_term global (locks screen list, screen)
setcchar reentrant
setscrreg window (stdscr)
setupterm global
slk_attr screen
slk_attr_off screen
slk_attr_on screen
slk_attr_set screen
slk_attroff screen
slk_attron screen
slk_attrset screen
slk_clear screen
slk_color screen
slk_init screen
slk_label screen
slk_noutrefresh screen
slk_refresh screen
slk_restore screen
slk_set screen
slk_touch screen
slk_wset screen
standend window
standout window
start_color screen
stdscr screen (read-only)
strcodes global (read-only)
strfnames global (read-only)
strnames global (read-only)
subpad window
subwin window
syncok window
term_attrs screen
termattrs screen
termname terminal
tgetent global
tgetflag global
tgetnum global
tgetstr global
tgoto global
tigetflag terminal
tigetnum terminal
tigetstr terminal
timeout window (stdscr)
touchline window
touchwin window
tparm global (static data)
tputs screen
trace global (static data)
ttytype screen (read-only)
typeahead screen
unctrl screen
unget_wch screen (input operation)
ungetch screen (input operation)
ungetmouse screen (input operation)
untouchwin window
use_default_colors screen
use_env global (static data)
use_extended_names global (static data)
use_legacy_coding screen
use_screen global (locks screen list, screen)
use_window global (locks window list, window)
vid_attr screen
vid_puts screen
vidattr screen
vidputs screen
vline window (stdscr)
vline_set window (stdscr)
vw_printw window
vw_scanw screen
vwprintw window
vwscanw screen
wadd_wch window
wadd_wchnstr window
wadd_wchstr window
waddch window
waddchnstr window
waddchstr window
waddnstr window
waddnwstr window
waddstr window
waddwstr window
wattr_get window
wattr_off window
wattr_on window
wattr_set window
wattroff window
wattron window
wattrset window
wbkgd window
wbkgdset window
wbkgrnd window
wbkgrndset window
wborder window
wborder_set window
wchgat window
wclear window
wclrtobot window
wclrtoeol window
wcolor_set window
wcursyncup screen (affects window plus parents)
wdelch window
wdeleteln window
wecho_wchar window
wechochar window
wenclose window
werase window
wget_wch screen (input operation)
wget_wstr screen (input operation)
wgetbkgrnd window
wgetch screen (input operation)
wgetdelay window
wgetn_wstr screen (input operation)
wgetnstr screen (input operation)
wgetparent window
wgetscrreg window
wgetstr screen (input operation)
whline window
whline_set window
win_wch window
win_wchnstr window
win_wchstr window
winch window
winchnstr window
winchstr window
winnstr window
winnwstr window
wins_nwstr window
wins_wch window
wins_wstr window
winsch window
winsdelln window
winsertln window
winsnstr window
winsstr window
winstr window
winwstr window
wmouse_trafo window
wmove window
wnoutrefresh screen
wprintw window
wredrawln window
wrefresh screen
wresize window (locks window list)
wscanw screen
wscrl window
wsetscrreg window
wstandend window
wstandout window
wsyncdown screen (affects window plus parents)
wsyncup screen (affects window plus parents)
wtimeout window
wtouchln window
wunctrl global (static data)
wvline window
wvline_set window
Like, genuinely the whole alphabet of curses, slay π note the little side-notes in parentheses though β screen (read-only), window (locks window list), screen (affects window plus parents), global (static data), screen (input operation) β those are not decoration, they're the whole point of this page. That's the tea. π«
β¨ RETURN VALUE β¨
okay so what do these even give you back π
get_escdelayβ hands you back the value ofESCDELAY. That's it, that's the whole job πset_escdelayandset_tabsizeβ returnERRwhen they fail andOKwhen they succeed, no cap πΈuse_screenanduse_windowβ they give you back theintthat the user-supplied function they were called with returned. literally just passing the vibe along π
π NOTES π
tiny but important: ncurses gives you both a C function and a preprocessor macro for every single function documented on this page. two for one, we love to see it π
π PORTABILITY π
bestie, listen up, this one matters π¨
- These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations.
- It is recommended that any code depending on ncurses extensions be conditioned using
NCURSES_VERSION.
so if you're writing something that needs to compile on ancient BSD or System Vβ¦ girl, guard it with NCURSES_VERSION or you're gonna have a bad time π not me being dramatic, that's just the warning.
π SEE ALSO π
go read these next, fr fr π
ncurses(3NCURSES)opaque(3NCURSES)curses_variables(3NCURSES)
and that's a wrap on the whole page, bestie π¦π you made it all the way through, which is genuinely main character energy β this was ncurses 6.6, dated 2025-02-15 β go forth and thread-safely, periodt π β¨
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2021-2024,2025 Thomas E. Dickey
- Copyright 2008-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