curs_getcchar(3X)
π curs_getcchar β library calls π
okay bestie, we're in the ncurses section of the manual (that's the 3X part, iykyk) and this page is ALL about the getcchar and setcchar girlies. let's go π«Ά
β¨ NAME β¨
getcchar, setcchar β convert between a wide-character string and a curses complex character
πΈ SYNOPSIS πΈ
#include <curses.h>
int getcchar(const cchar_t * wch, wchar_t * wc,
attr_t * attrs, short * pair, void * opts);
int setcchar(cchar_t * wch, const wchar_t * wc,
const attr_t attrs, short pair, const void * opts);
π DESCRIPTION π
so the curses complex character data type, cchar_t, is a structure type that's literally three things holding hands: a wide-character string, a set of attributes, and a color pair identifier. π
π¨ real talk: the cchar_t structure is opaque. do NOT go poking at its members directly, bestie, that's not the vibe. the library hands you functions to manipulate this type instead. periodt.
π getcchar
getcchar destructures a cchar_t into its components. like un-building a lewk into its individual pieces β¨
if wc is not a null pointer, getcchar:
- stores the wide-character string in the curses complex character
wchintowc; - stores the attributes in
attrs; and - stores the color pair identifier in
pair.
if wc is a null pointer, getcchar counts the wchar_t wide characters in wch, returns that value, and leaves attrs and pair completely unchanged. no touchy. π
π¦ setcchar
setcchar constructs a curses complex character wch out of the components wc, attrs, and pair. it's giving assembly line, honestly.
the wide-character string wch must be terminated with a null wide character L'\0' and must contain at most one spacing character β which, if it's there at all, has to be the first wide character in the string. π
up to CCHARW_MAX - 1 non-spacing characters may follow (peep curs_variables(3X) for that). ncurses ignores any additional non-spacing characters. it simply does not see them, bestie.
the string may contain a single control character instead. but in that case? no non-spacing characters allowed. none. zero. that's the rule π
β RETURN VALUE β
if getcchar is passed a null pointer as its wc argument, it returns the number of wide characters for a given wch that it would store in wc, counting a trailing null wide character.
if getcchar is not passed a null pointer as its wc argument, it returns OK on success and ERR on failure.
in ncurses, getcchar returns ERR if either attrs or pair is a null pointer and wc is not.
setcchar returns OK on success and ERR on failure.
in ncurses, setcchar returns ERR if:
wchis a null pointer,wcstarts with a (wide) control character and contains any other wide characters, orpairhas a negative value.
π NOTES π
wch may be a value stored by setcchar or another curses function with a writable cchar_t argument. but if wch was constructed by any other means, the library's behavior is unspecified. so likeβ¦ don't. π«£
π EXTENSIONS π
X/Open Curses documents the opts argument as reserved for future use, saying that it must be a null pointer. the ncurses 6 ABI uses it with functions that have a color pair parameter to support extended color pairs. iconic behavior, honestly.
- in functions that assign colors, such as
setcchar, ifoptsis not a null pointer, ncurses treats it as a pointer toint, and interprets it instead of theshort pairparameter as a color pair identifier. - in functions that retrieve colors, such as
getcchar, ifoptsis not a null pointer, ncurses treats it as a pointer toint, and stores the retrieved color pair identifier there as well as in theshort pairparameter (which may therefore undergo a narrowing conversion). π
π PORTABILITY π
apps employing ncurses extensions should condition their use on the visibility of the NCURSES_VERSION preprocessor macro. that's the vibe check for "am i actually on ncurses rn".
these functions are described in X/Open Curses Issue 4. it specifies no error conditions for them.
X/Open Curses does not detail the layout of the cchar_t structure, describing only its minimal required contents:
- a spacing wide character (
wchar_t), - at least five non-spacing wide characters (
wchar_t; see below), - attributes (at least 15 bits' worth, inferred from the count of specified
WA_constants), - a color pair identifier (at least 16 bits, inferred from the
shorttype used to encode it).
non-spacing characters are optional, in the sense that zero or more may be stored in a cchar_t. XOpen/Curses specifies a limit:
Implementations may limit the number of non-spacing characters that can be associated with a spacing character, provided any limit is at least 5.
then-contemporary Unix implementations adhered to that limit. history lesson time, bestie π
- AIX 4 and OSF/1 4 used the same declaration with a single spacing wide character
cand an array of 5 non-spacing wide charactersz. - HP-UX 10 used an opaque structure of 28 bytes, large enough for 6
wchar_tvalues. - Solaris xcurses uses a single array of 6
wchar_tvalues.
ncurses defined its cchar_t in 1995 using 5 as the total of spacing and non-spacing characters (CCHARW_MAX). that was probably due to a misreading of the AIX 4 header files, because the X/Open Curses document was not generally available at that time. later (in 2002), this detail was overlooked when work began to implement the functions using the structure. π the way that a tiny slip-up echoes through the decadesβ¦
in practice, a mere four non-spacing characters may seem adequate. X/Open Curses documents possible applications of non-spacing characters, including their use as ligatures (a feature apparently not supported by any curses implementation). Unicode does not limit the (analogous) number of combining characters in a grapheme cluster; some applications may be affected. ncurses can be compiled with a different CCHARW_MAX value β but doing so alters the library's ABI. so, like, don't do that casually. π¨
π₯ HISTORY π₯
X/Open Curses Issue 4 (1995) initially specified these functions.
π SEE ALSO π
curses(3X), curs_attr(3X), curs_color(3X), wcwidth(3)
and that's the whole page, bestie π this one came from ncurses 6.6, dated 2025-02-23, and it's the curs_getcchar(3X) manual page. go forth and destructure responsibly π«Άβ¨π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright 2019-2024,2025 Thomas E. Dickey
- Copyright 2001-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