threads(3NCURSES)
β¨ threads(3NCURSES) β¨
okay bestie, welcome to the threads page from the 3NCURSES manual π this one's a whole trilogy so buckle up, we're doing part one rn π
πΈ NAME πΈ
curs_threads β curses thread support
π¦ SYNOPSIS π¦
#include <curses.h>
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 π
so this implementation can be configured to give you rudimentary support for multi-threaded apps π§΅β¨. that means a different set of libraries, like libncursest, because the binary interfaces are different, periodt.
instead of going around and changing every single interface to pass a thread specifier to each function (imagine the chaos π), it just adds a few functions that work in any configuration. these lil guys hide the mutexes you'd need to stop concurrent use of the global variables when you're configured for threading π
on top of forcing access to members of the WINDOW structure to go through functions (peep opaque(3NCURSES) for that tea π«), it also turns the common global variables into functions β like COLORS, COLOR_PAIRS, COLS, ESCDELAY, LINES, TABSIZE, curscr, newscr and ttytype π. those variables are maintained as read-only values, stored inside the SCREEN structure. no cap.
and even that isn't enough to make a thread-safe app using curses, bestie π. a multi-threaded application would be expected to have threads updating separate windows (within the same device), or updating on separate screens (on different devices). also, a few of the global variables are considered writable by some applications π. the functions described here are the ones that address these special situations.
the ESCDELAY and TABSIZE global variables get modified by some applications. to modify them in any configuration, use the set_escdelay or set_tabsize functions β. other global variables are not modifiable, sorry babes.
the get_escdelay function returns the value for ESCDELAY π.
the use_window and use_screen functions provide coarse granularity mutexes for their respective WINDOW and SCREEN parameters, and call a user-supplied function, passing it a data parameter, and returning the value from the user-supplied function back to the application π₯.
π USAGE π
all of the ncurses library functions assume that the locale is not altered during operation. plus, they use data that's maintained within a hierarchy of scopes π:
- global data, e.g., used in the low-level terminfo or termcap interfaces.
- terminal data, e.g., associated with a call to
set_curterm. the terminal data are initialized when screens are created. - screen data, e.g., associated with a call to
newtermorinitscr. - window data, e.g., associated with a call to
newwinorsubwin. windows are associated with screens. pads are not necessarily associated with a particular screen.- most curses applications operate on one or more windows within a single screen.
- reentrant, i.e., it uses only the data passed as parameters.
more parts coming bestie, don't go anywhere π«Άβ¨
Okay so bestie, this table lists the scope of data used for each symbol in the ncurses library when it's configured to support threading. It's literally the "who owns what" cheat sheet, and you know we love a good org chart. π
For each symbol, here's its scope:
BCβ globalCOLORSβ screen (readonly)COLOR_PAIRβ reentrantCOLOR_PAIRSβ screen (readonly)COLSβ screen (readonly)ESCDELAYβ screen (readonly, seeset_escdelay)LINESβ screen (readonly)PAIR_NUMBERβ reentrantPCβ globalSPβ globalTABSIZEβ screen (readonly)UPβ globalacs_mapβ screen (readonly)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β screenbkgdβ window (stdscr)bkgdsetβ window (stdscr)bkgrndβ window (stdscr)bkgrndsetβ window (stdscr)boolcodesβ global (readonly)boolfnamesβ global (readonly)boolnamesβ global (readonly)borderβ window (stdscr)border_setβ window (stdscr)boxβ window (stdscr)box_setβ window (stdscr)can_change_colorβ terminalcbreakβ screenchgatβ window (stdscr)clearβ window (stdscr)clearokβ windowclrtobotβ window (stdscr)clrtoeolβ window (stdscr)color_contentβ screencolor_setβ window (stdscr)copywinβ window locks(source,target)cur_termβ terminalcurs_setβ screencurscrβ screen (readonly)curses_versionβ global (readonly)def_prog_modeβ terminaldef_shell_modeβ terminaldefine_keyβ screendel_curtermβ screendelay_outputβ screendelchβ window (stdscr)deletelnβ window (stdscr)delscreenβ global locks(screenlist,screen)delwinβ global locks(windowlist)derwinβ screendoupdateβ screendupwinβ screen locks(window)echoβ screenecho_wcharβ window (stdscr)echocharβ window (stdscr)endwinβ screeneraseβ window (stdscr)erasecharβ window (stdscr)erasewcharβ window (stdscr)filterβ globalflashβ terminalflushinpβ screenget_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β screenhas_colorsβ terminalhas_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(screenlist)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β windowkillcharβ terminalkillwcharβ terminalleaveokβ windowlongnameβ screenmcprintβ terminalmetaβ screenmouse_trafoβ window (stdscr)mouseintervalβ screenmousemaskβ screenmoveβ 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β screenmvdelchβ 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(she naps, she's safe, iconic π€)newpadβglobal locks(windowlist)newscrβscreen (readonly)newtermβglobal locks(screenlist)newwinβglobal locks(windowlist)nlβscreennocbreakβscreennodelayβwindownoechoβscreennofilterβglobalnonlβscreennoqiflushβterminalnorawβscreennotimeoutβwindownumcodesβglobal (readonly)numfnamesβglobal (readonly)numnamesβglobal (readonly)ospeedβglobaloverlayβwindow locks(source, target)overwriteβwindow locks(source, target)pair_contentβscreenpecho_wcharβscreenpechocharβscreenpnoutrefreshβscreenprefreshβscreenprintwβwindowputpβglobalputwinβwindowqiflushβterminalrawβscreenredrawwinβwindowrefreshβscreen(the main character fr π )reset_prog_modeβscreenreset_shell_modeβscreenresettyβterminalresize_termβscreen locks(windowlist)resizetermβscreenrestarttermβscreenripofflineβglobal (static data)savettyβterminalscanwβscreenscr_dumpβscreenscr_initβscreenscr_restoreβscreenscr_setβscreenscrlβwindow (stdscr)scrollβwindowscrollokβwindowset_curtermβscreenset_escdelayβscreenset_tabsizeβscreenset_termβglobal locks(screenlist, screen)setccharβreentrantsetscrregβwindow (stdscr)setuptermβglobalslk_attrβscreenslk_attr_offβscreenslk_attr_onβscreenslk_attr_setβscreenslk_attroffβscreenslk_attronβscreenslk_attrsetβscreenslk_clearβscreenslk_colorβscreenslk_initβscreenslk_labelβscreenslk_noutrefreshβscreenslk_refreshβscreenslk_restoreβscreenslk_setβscreenslk_touchβscreenslk_wsetβscreenstandendβwindowstandoutβwindowstart_colorβscreenstdscrβscreen (readonly)strcodesβglobal (readonly)strfnamesβglobal (readonly)strnamesβglobal (readonly)subpadβwindowsubwinβwindowsyncokβwindowterm_attrsβscreentermattrsβscreentermnameβterminaltgetentβglobaltgetflagβglobaltgetnumβglobaltgetstrβglobaltgotoβglobaltigetflagβterminaltigetnumβterminaltigetstrβterminaltimeoutβwindow (stdscr)touchlineβwindowtouchwinβwindowtparmβglobal (static data)tputsβscreentraceβglobal (static data)ttytypeβscreen (readonly)typeaheadβscreenunctrlβscreenunget_wchβscreen (input-operation)ungetchβscreen (input-operation)ungetmouseβscreen (input-operation)untouchwinβwindowuse_default_colorsβscreenuse_envβglobal (static data)use_extended_namesβglobal (static data)use_legacy_codingβscreenuse_screenβglobal locks(screenlist, screen)use_windowβglobal locks(windowlist, window)vid_attrβscreenvid_putsβscreenvidattrβscreenvidputsβscreenvlineβwindow (stdscr)vline_setβwindow (stdscr)vw_printwβwindowvw_scanwβscreenvwprintwβwindowvwscanwβscreenwadd_wchβwindowwadd_wchnstrβwindowwadd_wchstrβwindowwaddchβwindowwaddchnstrβwindowwaddchstrβwindowwaddnstrβwindowwaddnwstrβwindowwaddstrβwindowwaddwstrβwindowwattr_getβwindowwattr_offβwindowwattr_onβwindowwattr_setβwindowwattroffβwindowwattronβwindowwattrsetβwindowwbkgdβwindowwbkgdsetβwindowwbkgrndβwindowwbkgrndsetβwindowwborderβwindowwborder_setβwindowwchgatβwindowwclearβwindowwclrtobotβwindowwclrtoeolβwindowwcolor_setβwindowwcursyncupβscreen (affects window plus parents)wdelchβwindowwdeletelnβwindowwecho_wcharβwindowwechocharβwindowwencloseβwindowweraseβwindowwget_wchβscreen (input-operation)wget_wstrβscreen (input-operation)wgetbkgrndβwindowwgetchβscreen (input-operation)wgetdelayβwindowwgetn_wstrβscreen (input-operation)wgetnstrβscreen (input-operation)wgetparentβwindowwgetscrregβwindowwgetstrβscreen (input-operation)whlineβwindowwhline_setβwindowwin_wchβwindowwin_wchnstrβwindowwin_wchstrβwindowwinchβwindowwinchnstrβwindowwinchstrβwindowwinnstrβwindowwinnwstrβwindowwins_nwstrβwindowwins_wchβwindowwins_wstrβwindowwinschβwindowwinsdellnβwindowwinsertlnβwindowwinsnstrβwindowwinsstrβwindowwinstrβwindowwinwstrβwindowwmouse_trafoβwindowwmoveβwindowwnoutrefreshβscreenwprintwβwindowwredrawlnβwindowwrefreshβscreenwresizeβwindow locks(windowlist)wscanwβscreenwscrlβwindowwsetscrregβwindowwstandendβwindowwstandoutβwindowwsyncdownβscreen (affects window plus parents)wsyncupβscreen (affects window plus parents)wtimeoutβwindowwtouchlnβwindowwunctrlβglobal (static data)wvlineβwindowwvline_setβwindow
okay bestie, that's the ENTIRE roster, no skips, no shortcuts, every single name accounted for π«Ά take a breath, hydrate, you ate that.
π RETURN VALUE π
Every one of these bad boys returns TRUE or FALSE β that's the whole personality β except the ones that say otherwise up in the notes. no cap.
π NOTES π
For each and every name listed here, you get both a macro and a function. two for one, lowkey generous of them π
π§³ PORTABILITY π§³
so here's the tea β these routines are ncurses-specific. like, they're ncurses originals. they were not supported on Version 7, BSD or System V implementations. not a vibe on those old systems, they simply weren't invited.
It is recommended that any code depending on ncurses extensions be conditioned using NCURSES_VERSION. like, wrap it, gate it, protect it β do not just rawdog these calls into portable code bestie π
π SEE ALSO π
ncurses(3NCURSES)opaque(3NCURSES)curses_variables(3NCURSES)
and that's a wrap on threads(3NCURSES) π that's the page name sitting pretty in the footer, and fr fr you just read the whole thing β main character energy, no notes, go forth and thread safely β¨π
π¦ where this page comes from
- debian bookworm: ncurses-doc 6.4-4 Β· MIT/X11
- Copyright 2021,2022 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