curs_get_wstr(3X)
curs_get_wstr(3X) π
okay bestie, this is a page from the Library calls corner of the manual β it's all about reading a wide-character string off the curses terminal keyboard. let's get into it π«Ά
β¨ NAME β¨
get_wstr, getn_wstr, wget_wstr, wgetn_wstr, mvget_wstr, mvgetn_wstr, mvwget_wstr, mvwgetn_wstr β read a wide-character string from a curses terminal keyboard πΈ
β¨ SYNOPSIS β¨
#include <curses.h>
int get_wstr(wint_t * wstr);
int wget_wstr(WINDOW * win, wint_t * wstr);
int mvget_wstr(int y, int x, wint_t * wstr);
int mvwget_wstr(WINDOW * win, int y, int x, wint_t * wstr);
int getn_wstr(wint_t * wstr, int n);
int wgetn_wstr(WINDOW * win, wint_t * wstr, int n);
int mvgetn_wstr(int y, int x, wint_t * wstr, int n);
int mvwgetn_wstr(WINDOW * win, int y, int x, wint_t * wstr, int n);
π DESCRIPTION π
so wget_wstr fills up a wide-character string buffer wstr that you supply β it just keeps calling wget_wch(3X) with the win argument over and over until a line feed or carriage return character comes in. periodt. and here's what this function actually does, bestie:
- it does not copy the terminating character into
wstr; - it populates
wstrwithWEOF(as defined inwchar.h) if an end-of-file condition happens on the input; - it always terminates the string with a null wide character (after any
WEOF); - it interprets the screen's wide erase and wide kill characters (peep
erasewchar(3X)andkillwchar(3X)); - it only recognizes function keys if the screen's keypad option is enabled (see
keypad(3X)); - it treats the function keys
KEY_LEFTandKEY_BACKSPACEthe same as the wide erase character; and - it discards function key inputs other than the ones it treats as the wide erase or wide kill characters, and calls
beep(3X)while doing it. π
the wide erase character swaps the character at the end of the buffer for a null wide character, and the wide kill character does the exact same thing but for the entire buffer. slay.
if the screen's echo option is enabled (see echo(3X)), then wget_wstr updates win with wadd_wch(3X). and also:
- the wide erase character and its function key synonyms move the cursor to the left, and
- the wide kill character returns the cursor to where it was chillin' when
wget_wstrwas called. π
wgetn_wstr is the same vibe, except it reads at most n wide characters, which helps the application avoid overrunning the buffer that wstr points to. curses ignores any attempt to input more than n wide characters (other than the terminating line feed or carriage return) and calls beep(3X) at you. if n is negative, wgetn_wstr reads up to LINE_MAX wide characters (see sysconf(3)).
ncurses(3X) describes the variants of these functions, iykyk.
π RETURN VALUE π
these functions return OK on success and ERR on failure. simple as that.
in ncurses, these functions fail if:
- the curses screen has not been initialized,
- (for functions taking a
WINDOWpointer argument)winis a null pointer, wstris a null pointer, or- an internal
wget_wch(3X)call fails.
functions prefixed with βmvβ first perform cursor movement, and they fail if the position (y, x) is outside the window boundaries. π¦
π§ NOTES π§
all of these functions except wgetn_wstr may be implemented as macros. (yes really. π)
reading input that overruns the buffer pointed to bywstrcauses undefined results. use then-infixed functions, and allocate sufficient storage forwstrβ at leastn+1timessizeof(wchar_t). no cap, do this. π
these functions cannot store a KEY_ value in wstr because there is no way to distinguish it from a valid wchar_t value.
and here's a fun lil behind-the-scenes fact: while these functions conceptually implement a series of calls to wget_wch, they also temporarily change properties of the curses screen so you can do simple editing of the input buffer. each function saves the screen's state, calls nl(3X), and, if the screen was in canonical (βcookedβ) mode, cbreak(3X). before returning, it restores the saved screen state. other implementations differ in detail, which affects which control characters they can accept in the buffer β see the βPORTABILITYβ section below. π
unlike getstr(3X) and related functions of ncurses's non-wide API, these functions do not return KEY_RESIZE if a SIGWINCH event interrupts the function.
β EXTENSIONS β
getn_wstr, wgetn_wstr, mvgetn_wstr, and mvwgetn_wstr's handling of negative n values is an ncurses extension. π
πΈ PORTABILITY πΈ
applications employing ncurses extensions should condition their use on the visibility of the NCURSES_VERSION preprocessor macro.
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them.
Issue 4 documented these functions as passing an array of wchar_t, but that was an error β it conflicted with the following language in the standard.
The effect of get_wstr() is as though a series of calls to get_wch() were made, until a newline character, end-of-line character, or end-of-file character is processed.
get_wch can return a negative value (WEOF), but wchar_t is a unsigned type. all of the vendors implement these functions using wint_t, following the Issue 7 standard. β¨
X/Open Curses Issue 7 is unclear whether the terminating null wide character counts toward the length parameter n. a similar issue affected wgetnstr in Issue 4, Version 2; Issue 7 revised that function's description to address the issue, but not that of wget_nwstr, leaving it ambiguous. ncurses counts the terminator in the length. π
X/Open Curses does not specify what happens if the length n is negative.
- For consistency with
wgetnstr, ncurses 6.2 uses a limit based onLINE_MAX. - Some other implementations (such as Solaris xcurses) do the same, while others (PDCurses) do not permit a negative
n. - NetBSD 7 curses imitates ncurses 6.1 and earlier, treating a negative
nas an unbounded count of wide characters.
implementations vary in their handling of input control characters. π
- While they may enable the screen's echo option, some do not take it out of raw mode, and may take cbreak mode into account when deciding whether to handle echoing within
wgetn_wstror to rely on it as a side effect of callingwget_wch.
Since 1995, ncurses has provided handlers for SIGINTR and SIGQUIT events, which are typically generated at the keyboard with ^C and ^\ respectively. in cbreak mode, those handlers catch a signal and stop the program, whereas other implementations write those characters into the buffer.
- Starting with ncurses 6.3 (2021),
wgetn_wstrpreserves raw mode if the screen was already in that state, allowing one to enter the characters the terminal interprets as interrupt and quit events into the buffer, for consistency with SVr4 curses'swgetnstr.
π HISTORY π
X/Open Curses Issue 4 (1995) initially specified these functions. the System V Interface Definition Version 4 of the same year specified functions named wgetwstr and wgetnwstr (and the usual variants). these were later additions to SVr4.x, not appearing in the first SVr4 (1989). except in name, their declarations did not differ from X/Open's later wget_wstr and wgetn_wstr until X/Open Curses Issue 7 (2009) eventually changed the type of the buffer argument to a pointer to wint_t. iconic behavior fr fr. π
π SEE ALSO π
curs_getstr(3X) describes comparable functions of the ncurses library in its non-wide-character configuration.
curses(3X), curs_get_wch(3X)
and that's the whole page bestie!! this was curs_get_wstr(3X) from ncurses 6.6, dated 2025-10-20 π go forth and read them wide chars, you've got this πβ¨π¦
π¦ 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 2002-2012,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