1 .\"***************************************************************************
2 .\" Copyright 2018-2023,2024 Thomas E. Dickey *
3 .\" Copyright 1998-2010,2017 Free Software Foundation, Inc. *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a *
6 .\" copy of this software and associated documentation files (the *
7 .\" "Software"), to deal in the Software without restriction, including *
8 .\" without limitation the rights to use, copy, modify, merge, publish, *
9 .\" distribute, distribute with modifications, sublicense, and/or sell *
10 .\" copies of the Software, and to permit persons to whom the Software is *
11 .\" furnished to do so, subject to the following conditions: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 .\" Except as contained in this notice, the name(s) of the above copyright *
25 .\" holders shall not be used in advertising or otherwise to promote the *
26 .\" sale, use or other dealings in this Software without prior written *
28 .\"***************************************************************************
30 .\" $Id: curs_getstr.3x,v 1.67 2024/06/22 22:20:56 tom Exp $
31 .TH curs_getstr 3X 2024-06-22 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
58 accept character strings from \fIcurses\fR terminal keyboard
61 \fB#include <curses.h>
63 \fBint getstr(char * \fIstr\fP);
64 \fBint wgetstr(WINDOW * \fIwin\fP, char * \fIstr\fP);
65 \fBint mvgetstr(int \fIy\fP, int \fIx\fP, char * \fIstr\fP);
66 \fBint mvwgetstr(WINDOW * \fIwin\fP, int \fIy\fP, int \fIx\fP, char * \fIstr\fP);
68 \fBint getnstr(char * \fIstr\fP, int \fIn\fP);
69 \fBint wgetnstr(WINDOW * \fIwin\fP, char * \fIstr\fP, int \fIn\fP);
70 \fBint mvgetnstr(int \fIy\fP, int \fIx\fP, char * \fIstr\fP, int \fIn\fP);
71 \fBint mvwgetnstr(WINDOW * \fIwin\fP, int \fIy\fP, int \fIx\fP, char * \fIstr\fP, int \fIn\fP);
75 populates a user-supplied string buffer
77 by repeatedly calling \fBwgetch\fP(3X)
81 until a line feed or carriage return character is input.
82 .\" Of the two, because wgetnstr() calls nl(), only a line feed (\n)
83 .\" will ever be returned by wgetch().
86 does not copy the terminating character to
91 with a null character;
93 interprets the screen's erase and kill characters
94 (see \fB\%erasechar\fP(3X) and \fB\%killchar\fP(3X));
96 recognizes function keys only if the screen's keypad option is enabled
97 (see \fB\%keypad\fP(3X));
99 treats the function keys
103 the same as the erase character;
106 discards function key inputs other than those treated as the erase
108 calling \fBbeep\fP(3X).
110 The erase character replaces the character at the end of the buffer with
112 while the kill character does the same for the entire buffer.
114 If the screen's echo option is enabled
115 (see \fBecho\fP(3X)),
119 with \fB\%wechochar\fP(3X).
123 and its function key synonyms
124 move the cursor to the left,
127 the kill character returns the cursor to where it was located when
136 aiding the application to avoid overrunning the buffer to which
139 An attempt to input more than
142 (other than the terminating line feed or carriage return)
143 is ignored with a beep.
145 \fB\%ncurses\fP(3X) describes the variants of these functions.
147 These functions return
171 these functions return
175 event interrupts the function.
177 Functions prefixed with \*(``mv\*('' first perform cursor movement and
181 is outside the window boundaries.
183 All of these functions except
185 may be implemented as macros.
194 overruns the buffer pointed to by
196 causes undefined results.
199 counterpart functions instead.
203 is conceptually a series of calls to
205 it also temporarily changes properties of the
207 screen to permit simple editing of the input buffer.
208 It saves the screen's state and then calls \fBnl\fP(3X) and,
209 if the screen was in normal (\*(``cooked\*('') mode,
212 it restores the saved screen state.
213 Other implementations differ in detail,
214 affecting which control characters they can accept in the buffer;
215 see section \*(``PORTABILITY\*('' below.
223 Applications employing
225 extensions should condition their use on the visibility of the
229 X/Open Curses Issue 4 describes these functions.
230 It specifies no error conditions for them,
233 and its variants read
234 \*(``the entire multi-byte sequence associated with a character\*(''
235 and \*(``fail\*('' if
239 together do not describe a buffer
240 \*(``large enough to contain any complete characters\*(''.
245 reads only single-byte characters,
246 so this scenario does not arise.
247 .\" You can pass ncurses wgetnstr n=0 and it will beep at you with each
252 describes a successful return value only as
253 \*(``an integer value other than
258 implementations did not reject function keys;
259 the SVr4 documentation asserted that,
260 like the screen's erase and kill characters,
265 as well as any special keys
266 (such as function keys,
270 .\" SVID 4, Volume 3, p. 495
273 without further detail.
276 the \*(``character\*('' value
277 appended to the string
278 by those implementations
279 was predictable but not useful \(em
282 the low-order eight bits of the key code's
286 unchanged except for styling,
287 survived into X/Open Curses Issue 4, \" p. 94 (PDF 114)
288 but disappeared from Issue 7.) \" p. 105 (PDF 119)
290 X/Open Curses Issue 5 (2007) stated that these functions
294 but did not state whether the terminating null character
295 counted toward that limit.
296 X/Open Curses Issue 7 (2009) changed that to say they
300 to allow for the terminating null character.
302 some implementations count it,
308 do not count the null character toward the limit,
309 while Solaris and NetBSD
315 offers both behaviors:
318 reserves room for a wide null character,
321 does not consistently count a null character toward the limit.
329 to assume that the caller's buffer
330 is large enough to hold the result;
332 the function then acts like
334 X/Open Curses does not mention this behavior
335 (or anything related to nonpositive
340 libraries implement it.
341 Most implementations nevertheless enforce an upper limit
342 on the count of bytes they write to the destination buffer
354 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4BSD/usr/src/lib/\
355 .\" libcurses/getstr.c
356 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/src/lib/\
357 .\" libcurses/getstr.c
359 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/sysvr2-vax/\
360 .\" src/lib/libcurses/screen/getstr.c
369 limit both functions to writing 256 bytes.
370 Other System\ V-based platforms likely use the same limit.
371 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/\
372 .\" sysvr3/31/usr/src/lib/libcurses/screen/wgetstr.c#L10
373 .\" sysvr4/svr4/lib/xlibcurses/screen/wgetstr.c#L12
383 imposes no particular limit on the length of the write,
386 to ensure that it is greater than zero.
387 A comment in NetBSD's source code asserts that SUSv2 specifies this.
391 imposes no limit on the length of the write,
402 or a larger (system-dependent) value
403 provided by \fI\%sysconf\fP(3).
410 uses the POSIX minimum value for
412 (2048). \" _POSIX2_LINE_MAX
414 it reserves a byte for the terminating null character.
416 Implementations vary in their handling of input control characters.
418 While they may enable the screen's echo option,
419 some do not take it out of raw mode,
420 and may take cbreak mode into account
421 when deciding whether to handle echoing within
423 or to rely on it as a side effect of calling
436 before accepting input.
437 That may have been done to make function keys work;
438 it is not necessary with modern
443 has provided handlers for
448 which are typically generated at the keyboard with
454 those handlers catch a signal and stop the program,
455 whereas other implementations write those characters into the buffer.
461 preserves raw mode if the screen was already in that state,
462 allowing one to enter the characters the terminal interprets
463 as interrupt and quit events
465 for better compatibility with SVr4
472 along with its variants.
477 but none of its variants.
479 X/Open Curses Issue 4 (1995) specified
485 \fB\%curs_get_wstr\fP(3X) describes comparable functions of the
487 library in its wide-character configuration
491 \fB\%curs_addch\fP(3X),
492 \fB\%curs_getch\fP(3X),
493 \fB\%curs_inopts\fP(3X), \" echo(), keypad()
494 \fB\%curs_termattrs\fP(3X), \" erasechar(), killchar()