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 wstr with WEOF (as defined in wchar.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) and killwchar(3X));
  • it only recognizes function keys if the screen's keypad option is enabled (see keypad(3X));
  • it treats the function keys KEY_LEFT and KEY_BACKSPACE the 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_wstr was 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 WINDOW pointer argument) win is a null pointer,
  • wstr is 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 by wstr causes undefined results. use the n-infixed functions, and allocate sufficient storage for wstr β€” at least n+1 times sizeof(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 on LINE_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 n as 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_wstr or to rely on it as a side effect of calling wget_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_wstr preserves 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's wgetnstr.

πŸ‘‘ 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