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 terminfo or termcap interfaces
  • 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) or initscr(3NCURSES)
  • window data associated with a call to newwin(3NCURSES) or subwin(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 β€” reentrant
  • COLOR_PAIRS β€” screen (read-only)
  • COLS β€” screen (read-only)
  • ESCDELAY β€” screen (read-only; see set_escdelay) ⏱️
  • LINES β€” screen (read-only)
  • PAIR_NUMBER β€” reentrant
  • PC β€” global
  • SP β€” global
  • TABSIZE β€” screen (read-only; see set_tabsize)
  • UP β€” global
  • acs_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 β€” screen
  • attr_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 β€” screen
  • beep β€” 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 β€” window
  • clrtobot β€” 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 β€” terminal
  • def_shell_mode β€” terminal
  • define_key β€” screen
  • del_curterm β€” screen
  • delay_output β€” screen
  • delch β€” window (stdscr)
  • deleteln β€” window (stdscr)
  • delscreen β€” global (locks screen list, screen) πŸ—‘οΈ
  • delwin β€” global (locks window list) πŸ—‘οΈ
  • derwin β€” screen
  • doupdate β€” 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 β€” window
  • getbegx β€” window
  • getbegy β€” window
  • getbkgd β€” window
  • getbkgrnd β€” window
  • getcchar β€” reentrant
  • getch β€” screen (input operation) ⌨️
  • getcurx β€” window
  • getcury β€” window
  • getmaxx β€” window
  • getmaxy β€” window
  • getmouse β€” screen (input operation) πŸ–±οΈ
  • getn_wstr β€” screen (input operation)
  • getnstr β€” screen (input operation)
  • getparx β€” window
  • getpary β€” window
  • getstr β€” screen (input operation)
  • getwin β€” screen (input operation)
  • halfdelay β€” screen ⏳
  • has_colors β€” terminal 🌈
  • has_ic β€” terminal
  • has_il β€” terminal
  • has_key β€” screen
  • hline β€” window (stdscr)
  • hline_set β€” window (stdscr)
  • idcok β€” window
  • idlok β€” window
  • immedok β€” window
  • in_wch β€” window (stdscr)
  • in_wchnstr β€” window (stdscr)
  • in_wchstr β€” window (stdscr)
  • inch β€” window (stdscr)
  • inchnstr β€” window (stdscr)
  • inchstr β€” window (stdscr)
  • init_color β€” screen
  • init_pair β€” screen
  • initscr β€” 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 β€” terminal
  • inwstr β€” window (stdscr)
  • is_cleared β€” window
  • is_idcok β€” window
  • is_idlok β€” window
  • is_immedok β€” window
  • is_keypad β€” window
  • is_leaveok β€” window
  • is_linetouched β€” window
  • is_nodelay β€” window
  • is_notimeout β€” window
  • is_scrollok β€” window
  • is_syncok β€” window
  • is_term_resized β€” terminal
  • is_wintouched β€” window
  • isendwin β€” screen
  • key_defined β€” screen
  • key_name β€” global (static data)
  • keybound β€” screen
  • keyname β€” global (static data)
  • keyok β€” screen
  • keypad β€” window ⌨️
  • killchar β€” terminal
  • killwchar β€” terminal
  • leaveok β€” window
  • longname β€” screen πŸ“›
  • mcprint β€” terminal
  • meta β€” screen
  • mouse_trafo β€” window (stdscr)
  • mouseinterval β€” screen
  • mousemask β€” 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 β€” screen
  • mvvline β€” window (stdscr)
  • mvvline_set β€” window (stdscr)
  • mvwadd_wch β€” window
  • mvwadd_wchnstr β€” window
  • mvwadd_wchstr β€” window
  • mvwaddch β€” window
  • mvwaddchnstr β€” window
  • mvwaddchstr β€” window
  • mvwaddnstr β€” window
  • mvwaddnwstr β€” window
  • mvwaddstr β€” window
  • mvwaddwstr β€” window
  • mvwchgat β€” window
  • mvwdelch β€” window
  • mvwget_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 β€” window
  • mvwhline_set β€” window
  • mvwin β€” window
  • mvwin_wch β€” window
  • mvwin_wchnstr β€” window
  • mvwin_wchstr β€” window
  • mvwinch β€” window
  • mvwinchnstr β€” window
  • mvwinchstr β€” window
  • mvwinnstr β€” window
  • mvwinnwstr β€” window
  • mvwins_nwstr β€” window
  • mvwins_wch β€” window
  • mvwins_wstr β€” window
  • mvwinsch β€” window
  • mvwinsnstr β€” window
  • mvwinsstr β€” window
  • mvwinstr β€” window
  • mvwinwstr β€” window
  • mvwprintw β€” window
  • mvwscanw β€” screen
  • mvwvline β€” window
  • mvwvline_set β€” window
  • napms β€” reentrant 😴
  • newpad β€” global (locks window list) πŸ“
  • newscr β€” screen (read-only) πŸ†•
  • newterm β€” global (locks screen list) 🎬
  • newwin β€” global (locks window list) πŸͺŸ
  • nl β€” screen ↩️
  • nocbreak β€” screen
  • nodelay β€” window ⚑
  • noecho β€” screen 🀫
  • nofilter β€” global
  • nonl β€” screen
  • noqiflush β€” terminal
  • noraw β€” screen
  • notimeout β€” window
  • numcodes β€” 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 β€” screen
  • pecho_wchar β€” screen
  • pechochar β€” screen
  • pnoutrefresh β€” screen
  • prefresh β€” screen
  • printw β€” 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 of ESCDELAY. That's it, that's the whole job πŸ’…
  • set_escdelay and set_tabsize β€” return ERR when they fail and OK when they succeed, no cap 🌸
  • use_screen and use_window β€” they give you back the int that 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