curs_bkgrnd(3X)

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

✨ 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) and wins_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,
  • win is NULL, or
  • wch is NULL.
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