curs_threads(3X)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

✨ NAME ✨

okay so bestie, this is the curs_threads(3X) page from the Library calls section, and it's all about curses support for multi-threaded applications. The whole squad is NCURSES_WINDOW_CB, NCURSES_SCREEN_CB, get_escdelay, set_escdelay, set_tabsize, use_screen, and use_window. πŸ’–


✨ 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 tea: the ncurses library can be configured to support multi-threaded applications in a rudimentary way. That configuration produces a different set of libraries β€” named libncursest, for example β€” since doing so alters ncurses's application binary interface (ABI). periodt.

Instead of modifying the programming interface (API) to make ncurses functions expect an additional argument specifying a thread, the library adds functions, usable in any configuration, that hide the mutexes (mutual exclusion locks) needed to prevent concurrent access to variables shared by multiple threads of execution. no cap, it's giving lock magic. πŸ”’

ncurses threading support requires the use of functions to access members of the WINDOW structure (see curs_opaque(3X)). 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. obsessed with this level of organization.

Even this is not enough to make an application using curses thread-safe. 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. main character energy for real.

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. 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. so handy, honestly.

πŸ¦‹ Usage πŸ¦‹

All ncurses library functions assume that the locale is not altered during operation. In addition, they use data that is maintained within a hierarchy of scopes. vibe check: here's the hierarchy.

  • global data used in the low-level terminfo or termcap interfaces
  • terminal data associated with a call to set_curterm(3X) Terminal data are initialized when screens are created.
  • screen data associated with a call to newterm(3X) or initscr(3X)
  • window data associated with a call to newwin(3X) or subwin(3X) 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 bestie, deep breath, because this is THE LIST πŸ’… every single symbol in this entire API, plus the scope it lives in. it's giving seating chart for the most unhinged group project of all time: some of these are global, some are out here living on a screen, some are window girlies, some belong to the terminal, and a few are reentrant because they're just built different ✨

we are going through every last one. no skipping, no shortcuts, no "eh, you get the idea". you WILL know exactly where every symbol lives. periodt.

  • 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 β€” she goes beep πŸ””
  • 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) β€” locks BOTH of them, no sneaking in πŸ”’
  • 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) β€” two locks at once, thorough queen πŸ‘‘
  • delwin β€” global (locks window list)
  • derwin β€” screen
  • doupdate β€” screen
  • dupwin β€” screen (locks window)
  • echo β€” screen
  • echo_wchar β€” window (stdscr)
  • echochar β€” window (stdscr)
  • endwin β€” screen β€” and scene 🎬
  • erase β€” window (stdscr)
  • erasechar β€” window (stdscr)
  • erasewchar β€” window (stdscr)
  • filter β€” global
  • flash β€” terminal β€” she goes flash ⚑
  • 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) β€” the main character herself, obviously πŸ‘‘
  • 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) β€” static data, so mind your business πŸ™ˆ
  • 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 β€” nap time bestie, love that for her 😴
  • 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) β€” double lock again, she's not playing πŸ”’
  • overwrite β€” window (locks source, target)
  • pair_content β€” screen
  • pecho_wchar β€” screen
  • pechochar β€” screen
  • pnoutrefresh β€” screen
  • prefresh β€” screen
  • printw β€” window

…and the list keeps going, bestie, we're not even close to done yet πŸ’…

  • 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

✨ RETURN VALUE ✨

Okay so here's what you actually get back, bestie πŸŽ€

  • get_escdelay hands you the value of ESCDELAY. that's it, that's the whole vibe.
  • set_escdelay and set_tabsize give you ERR if it flops and OK if it ate and left no crumbs βœ…
  • use_screen and use_window return the int that the user-supplied function you passed them gives back β€” so like, whatever your lil callback returns, that's what comes out. no middleman behavior, no cap 🫢

πŸ“ NOTES πŸ“

Real talk for a sec: ncurses gives you both a C function and a preprocessor macro for every single function documented on this page. two for the price of one, we love a generous queen πŸ‘‘


🌍 PORTABILITY 🌍

Heads up, bestie β€” these routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations.

So if your code is leaning on these ncurses extensions, the move is to condition it using NCURSES_VERSION. protect your peace (and your portability) fr fr 🧚


πŸ‘€ SEE ALSO πŸ‘€

  • curses(3X)
  • curs_opaque(3X)
  • curs_variables(3X)

And that's a wrap on the whole page, babes πŸ’– this was ncurses 6.6, dated 2025-02-15, and the manual section is curs_threads(3X). go forth and thread safely, my icon πŸ‘‘βœ¨

πŸ“¦ where this page comes from