curs_bkgrnd(3X)
β¨ curs_bkgrnd(3X) β the wide-char background glow-up β¨
okay bestie, this is a Library calls page from the wide-character corner of the curses universe, and it's all about making your windows have a vibe underneath everything. π
πΈ NAME πΈ
bkgrnd, wbkgrnd, bkgrndset, wbkgrndset, getbkgrnd, wgetbkgrnd β manipulate the background of a curses window of wide characters. yes that's six whole functions, they're a friend group π«Ά
β¨ SYNOPSIS β¨
#include <curses.h>
int bkgrnd(const cchar_t *wch);
int wbkgrnd(WINDOW *win, const cchar_t *wch);
void bkgrndset(const cchar_t *wch);
void wbkgrndset(WINDOW *win, const cchar_t *wch);
int getbkgrnd(cchar_t *wch);
int wgetbkgrnd(WINDOW *win, cchar_t *wch);
π DESCRIPTION π
So like. Every curses window has a background character property, right? And in the library's wide configuration, that property is a curses complex character (cchar_t) that's literally two things fused together: a set of attributes (plus, if colors are enabled, a color pair identifier) AND a character code. it's giving layered. π
When curses erases (parts of) a window, it replaces those erased cells with the background character. no cap.
curses also whips out the background character when it's writing characters into a window that already has stuff in it. π
- The attribute part of the background character combines with all the non-blank character cells in the window β like, the ones populated by the
wadd_wch(3X)andwins_wch(3X)families of functions (and everything that calls them). it's a whole family tree fr fr. - Both the character code and the attributes of the background character combine with the blank character cells in the window.
The background character's set of attributes becomes a property of the character cell, and it moves with it through any scrolling and insert/delete line/character operations. icon behavior honestly. To the extent possible on the terminal type, curses displays the attributes of the background character as the graphic rendition of a character cell on the display. β¨
π¦ bkgrnd, wbkgrnd π¦
bkgrnd and wbkgrnd set the background property of stdscr or the window you specify, and then they apply that setting to every single character cell in that window. every. one. main character energy for real.
- The rendition of every character in the window changes to the new background rendition.
- Wherever the former background character appears, it changes to the new background character.
ncurses updates the rendition of each character cell by comparing the character, the non-color attributes, and the color pair selection. The library applies the following procedure to each cell in the window β whether or not it's blank. π
- ncurses first compares the cell's character to the previously specified background character; if they match, ncurses writes the new background character to the cell.
- ncurses then checks whether the cell uses color; that is, its color pair value is nonzero. If not, it simply replaces the attributes and color pair in the cell with those from the new background character.
- If the cell uses color, and its background color matches that of the current window background, ncurses removes attributes that may have come from the current background and adds those from the new background. It finishes by setting the cell's background to use the new window background color.
- If the cell uses color, and its background color does not match that of the current window background, ncurses updates only the non-color attributes β first removing those that may have come from the current background, and then adding attributes from the new background.
If the new background's character is non-spacing, ncurses reuses the old background character β with one special case: ncurses treats a background character code of zero (0) as a space. π (yes, 0 means space here. we don't make the rules.)
If the terminal does not support color, or if color has not been initialized with start_color(3X), ncurses ignores the new background character's color pair selection. no color, no problem, it just moves on. π
π§ bkgrndset, wbkgrndset π§
bkgrndset and wbkgrndset manipulate the background of the applicable window without updating the character cells the way bkgrnd and wbkgrnd do. only future writes reflect the updated background. it's a "we'll deal with it later" situation and honestly relatable. πΈ
π getbkgrnd, wgetbkgrnd π
getbkgrnd and wgetbkgrnd respectively obtain stdscr's or the given window's background character, attributes, and color pair, and store it in their wch argument. get you a function that can do both. π
π₯ RETURN VALUE π₯
bkgrndset and wbkgrndset do not return a value. they just do their thing and leave. π«
Functions returning an int return ERR upon failure and OK upon success. In ncurses, failure occurs if:
- the curses screen has not been initialized,
winisNULL, orwchisNULL.
bestie please check your pointers. ncurses is not going to hold your hand on this one. π
π NOTES π
bkgrnd, bkgrndset, and getbkgrnd may be implemented as macros. plot twist but okay.
Unlike their counterparts in the non-wide-character configuration of ncurses, getbkgrnd and wgetbkgrnd store the background character in a modifiable cchar_t parameter, rather than supplying it as the return value. so you pass in where you want it to land. periodt.
π PORTABILITY π
X/Open Curses Issue 4 describes these functions. It specifies no error conditions for them. π
X/Open Curses does not provide details of how the rendition is updated. ncurses follows the approach used in SVr4 curses's non-wide functions for manipulating the window background. so it's giving historically accurate, iykyk. β
π HISTORY π
X/Open Curses Issue 4 (1995) initially specified these functions. old money. vintage. iconic. π
π¦ SEE ALSO π¦
curs_bkgd(3X)describes the corresponding functions in the non-wide-character configuration of ncurses. β the skinny version of this page basically πcurses(3X),curs_add_wch(3X),curs_attr(3X)β go read these, bestie, they're the whole ecosystem β¨
and that's the page!! this one shipped in ncurses 6.6, dated 2025-08-23 β so yeah, freshly dated, slay, go make your windows' backgrounds immaculate π«Άπ πΈ
π¦ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 2002-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