curs_bkgd(3X)
β¨ curs_bkgd β the bkgdset / wbkgdset / bkgd / wbkgd / getbkgd manual, but make it make sense β¨
okay bestie, so this is curs_bkgd from the ncurses 6.6 library calls section, and it's literally all about messing with the background of a curses window of characters. that's the whole vibe. five functions, one very specific job. let's get into it π
πΈ SYNOPSIS πΈ
#include <curses.h>
int bkgd(chtype ch);
int wbkgd(WINDOW *win, chtype ch);
void bkgdset(chtype ch);
void wbkgdset(WINDOW *win, chtype ch);
chtype getbkgd(WINDOW *win);
look at those signatures. three return things, two return nothing, and every single one of them is obsessed with chtype. iconic behavior honestly π«Ά
π¦ DESCRIPTION π¦
so every curses window has a lil thing called a background character property. in the library's non-wide-character configuration, it's a curses character (chtype) that squishes together a set of attributes β and, if colors are enabled, a color pair identifier β plus a character code. when curses is erasing (parts of) a window, it replaces the erased cells with that background character. simple as that β¨
curses also uses the background character when writing characters to a populated window. like, it's not just for erasing, bestie.
- the attribute part of the background character combines with all the non-blank character cells in the window, as populated by the
waddch(3X)andwinsch(3X)families of functions (and those that call them). - 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 moves with it through any scrolling and insert/delete line/character operations. it's got main character energy and it travels π«. 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.
π bkgd, wbkgd π
bkgd and wbkgd set the background property of stdscr or the specified window and then apply this setting to every character cell in that window. no skipping, no shortcuts, every cell gets the treatment.
- 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, non-color attributes, and color pair selection. the library applies the following procedure to each cell in the window, whether or not it is blank. yes, whether or not it is blank. no cap.
- 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 (for example, if it's a control character), ncurses retains the existing background character, except for one special case: ncurses treats a background character code of zero (0) as a space. noted π
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. color? never heard of her.
π bkgdset, wbkgdset π
bkgdset and wbkgdset manipulate the background of the applicable window, without updating the character cells the way bkgd and wbkgd do; only future writes reflect the updated background. so it's the chill, low-effort version. setting the vibe now, letting it kick in later β¨
β getbkgd β
getbkgd returns the given window's background character, attributes, and color pair as a chtype. that's it, that's the function. give it a WINDOW and it hands you back the whole bundle π«Ά
π RETURN VALUE π
bkgdset and wbkgdset do not return a value. they're above the whole returning-things grindset.
functions returning an int return ERR upon failure and OK upon success. in ncurses, failure occurs if
- the curses screen has not been initialized, or
winisNULL.
getbkgd's return value is as described above. (go read the getbkgd bit again if you skipped it, i see you π)
π NOTES π
unusually, there is no wgetbkgd function; getbkgd behaves as one would expect wgetbkgd to, accepting a WINDOW pointer argument. the naming committee was feeling quirky that day, we don't ask questions.
bkgd and bkgdset may be implemented as macros. so don't go taking their address or anything weird, bestie.
X/Open Curses mentions that the character part of the background must be a single-byte value. ncurses, like SVr4 curses, checks to ensure that it is, and retains the existing background character if the check fails. it's giving strict parent energy and honestly? fair π
π§ PORTABILITY π§
X/Open Curses Issue 4 describes these functions. it indicates that bkgd, wbkgd, and getbkgd return ERR on failure (in the case of the last, this value is cast to chtype), but specifies no error conditions for them.
SVr4 documentation says that bkgd and wbkgd return OK βor a non-negative integer if immedok() is setβ, referring to the return value from wrefresh, which in SVr4 returns a count of characters written to the window if its immedok property is set; in ncurses, it does not. so if you read the SVr4 docs and got confused, that's why. not your fault π«Ά
neither X/Open Curses nor the SVr4 manual pages detail how the rendition of characters in the window updates when bkgd or wbkgd changes the background character. ncurses, like SVr4 curses, does not (in its non-wide-character configuration) store the background and window attribute contributions to each character cell separately. it's all mixed together, that's just the lore.
π HISTORY π
SVr3.1 (1987) introduced these functions. absolute legends, ahead of their time, we stan π
πΈ SEE ALSO πΈ
curs_bkgrnd(3X) describes the corresponding functions in the wide configuration of ncurses. if you're doing wide-character stuff, that's your girl.
curses(3X), curs_addch(3X), curs_attr(3X)
okay that's the whole page, you're officially a background-character expert, slay π β¨
this has been the ncurses 6.6 version of curs_bkgd(3X), dated 2025-08-23 β go forth and set some backgrounds, bestie, and remember: the vibe changes, the facts do not ππ¦
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-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