]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_getstr.3x
ncurses 6.3 - patch 20220212
[ncurses.git] / man / curs_getstr.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2021,2022 Thomas E. Dickey                                *
3 .\" Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
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:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
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.                               *
23 .\"                                                                          *
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       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_getstr.3x,v 1.36 2022/02/12 20:07:29 tom Exp $
31 .TH curs_getstr 3X ""
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de bP
37 .ie n  .IP \(bu 4
38 .el    .IP \(bu 2
39 ..
40 .na
41 .hy 0
42 .SH NAME
43 \fBgetstr\fP,
44 \fBgetnstr\fP,
45 \fBwgetstr\fP,
46 \fBwgetnstr\fP,
47 \fBmvgetstr\fP,
48 \fBmvgetnstr\fP,
49 \fBmvwgetstr\fP,
50 \fBmvwgetnstr\fP \- accept character strings from \fBcurses\fP terminal keyboard
51 .ad
52 .hy
53 .SH SYNOPSIS
54 \fB#include <curses.h>\fP
55 .sp
56 \fBint getstr(char *\fIstr\fB);\fR
57 .br
58 \fBint getnstr(char *\fIstr\fB, int \fIn\fB);\fR
59 .br
60 \fBint wgetstr(WINDOW *\fIwin\fB, char *\fIstr\fB);\fR
61 .br
62 \fBint wgetnstr(WINDOW *\fIwin\fB, char *\fIstr\fB, int \fIn\fB);\fR
63 .sp
64 \fBint mvgetstr(int \fIy\fB, int \fIx\fB, char *\fIstr\fB);\fR
65 .br
66 \fBint mvwgetstr(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB, char *\fIstr\fB);\fR
67 .br
68 \fBint mvgetnstr(int \fIy\fB, int \fIx\fB, char *\fIstr\fB, int \fIn\fB);\fR
69 .br
70 \fBint mvwgetnstr(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB, char *\fIstr\fB, int \fIn\fB);\fR
71 .br
72 .SH DESCRIPTION
73 The function \fBgetstr\fP is equivalent to a series of calls to \fBgetch\fP,
74 until a newline or carriage return is received (the terminating character is
75 not included in the returned string).
76 .\" X/Open says also until EOf
77 .\" X/Open says then an EOS is added to the result
78 .\" X/Open doesn't mention n<0
79 The resulting value is placed in the
80 area pointed to by the character pointer \fIstr\fP,
81 followed by a NUL.
82 .PP
83 The \fBgetnstr\fP function reads
84 from the \fIstdscr\fP default window.
85 The other functions, such as \fBwgetnstr\fP,
86 read from the window given as a parameter.
87 .PP
88 \fBgetnstr\fP reads at most \fIn\fP characters, thus preventing a possible
89 overflow of the input buffer.
90 Any attempt to enter more characters (other
91 than the terminating newline or carriage return) causes a beep.
92 Function
93 keys also cause a beep and are ignored.
94 .PP
95 The user's \fIerase\fP and \fIkill\fP characters are interpreted:
96 .bP
97 The \fIerase\fP character (e.g., \fB^H\fP) erases the character
98 at the end of the buffer, moving the cursor to the left.
99 .IP
100 If \fIkeypad\fP mode is on for the window,
101 \fBKEY_LEFT\fP and \fBKEY_BACKSPACE\fP
102 are both considered equivalent to the user's erase character.
103 .bP
104 The \fIkill\fP character (e.g., \fB^U\fP) erases the entire buffer,
105 leaving the cursor at the beginning of the buffer.
106 .PP
107 Characters input are echoed only if \fBecho\fP is currently on.
108 In that case,
109 backspace is echoed as deletion of the previous character (typically a left
110 motion).
111 .SH RETURN VALUE
112 All routines return the integer \fBERR\fP upon failure and an \fBOK\fP (SVr4
113 specifies only \*(``an integer value other than \fBERR\fP\*('') upon successful
114 completion.
115 .PP
116 X/Open defines no error conditions.
117 .PP
118 In this implementation,
119 these functions return an error
120 if the window pointer is null, or
121 if its timeout expires without having any data.
122 .PP
123 This implementation provides an extension as well.
124 If a \fBSIGWINCH\fP interrupts the function, it will return \fBKEY_RESIZE\fP
125 rather than \fBOK\fP or \fBERR\fP.
126 .PP
127 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
128 \fBwmove\fP, and return an error if the position is outside the window,
129 or if the window pointer is null.
130 .SH NOTES
131 Note that \fBgetstr\fP, \fBmvgetstr\fP, and \fBmvwgetstr\fP may be macros.
132 .SH PORTABILITY
133 These functions are described in the XSI Curses standard, Issue 4.
134 They read single-byte characters only.
135 The standard does not define any error conditions.
136 This implementation returns \fBERR\fP if the window pointer is null,
137 or if the lower-level \fBwgetch\fP(3X) call returns an \fBERR\fP.
138 .PP
139 SVr3 and early SVr4 curses implementations did not reject function keys;
140 the SVr4.0 documentation claimed that \*(``special keys\*(''
141 (such as function keys,
142 \*(``home\*('' key,
143 \*(``clear\*('' key,
144 \fIetc\fP.) are \*(``interpreted\*('',
145 without giving details.
146 It lied.
147 In fact, the \*(``character\*('' value appended to the
148 string by those implementations was predictable but not useful
149 (being, in fact, the low-order eight bits of the key's KEY_ value).
150 .PP
151 The functions \fBgetnstr\fP, \fBmvgetnstr\fP, and \fBmvwgetnstr\fP were
152 present but not documented in SVr4.
153 .PP
154 X/Open Curses, Issue 5 (2007) stated that these functions
155 \*(``read at most \fIn\fP bytes\*(''
156 but did not state whether the terminating NUL is counted in that limit.
157 X/Open Curses, Issue 7 (2009) changed that to say they
158 \*(``read at most \fIn\fP\-1 bytes\*(''
159 to allow for the terminating NUL.
160 As of 2018, some implementations do, some do not count it:
161 .bP
162 ncurses 6.1 and PDCurses do not count the NUL in the given limit, while
163 .bP
164 Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
165 .bP
166 Solaris xcurses provides both:
167 its wide-character \fBwget_nstr\fP reserves a NUL,
168 but its \fBwgetnstr\fP does not count the NUL consistently.
169 .PP
170 In SVr4 curses,
171 a negative value of \fIn\fP tells \fBwgetnstr\fP to assume that the
172 caller's buffer is large enough to hold the result,
173 i.e., to act like \fBwgetstr\fP.
174 X/Open Curses does not mention this
175 (or anything related to negative or zero values of \fIn\fP),
176 however most implementations
177 use the feature, with different limits:
178 .bP
179 Solaris SVr4 curses and PDCurses limit the result to 255 bytes.
180 Other Unix systems than Solaris are likely to use the same limit.
181 .bP
182 Solaris xcurses limits the result to \fBLINE_MAX\fP bytes.
183 .bP
184 NetBSD 7 assumes no particular limit for the result from \fBwgetstr\fP.
185 However, it limits the \fBwgetnstr\fP parameter \fIn\fP to ensure
186 that it is greater than zero.
187 .IP
188 A comment in NetBSD's source code states that this is specified in SUSv2.
189 .bP
190 ncurses (before 6.2) assumes no particular limit for the result
191 from \fBwgetstr\fP, and treats the \fIn\fP parameter of \fBwgetnstr\fP
192 like SVr4 curses.
193 .bP
194 ncurses 6.2 uses \fBLINE_MAX\fP,
195 or a larger (system-dependent) value
196 which the \fBsysconf\fP function may provide.
197 If neither \fBLINE_MAX\fP or \fBsysconf\fP is available,
198 ncurses uses the POSIX value for \fBLINE_MAX\fP (a 2048 byte limit).
199 In either case, it reserves a byte for the terminating NUL.
200 .PP
201 Although \fBgetnstr\fP is equivalent to a series of calls to \fBgetch\fP,
202 it also makes changes to the curses modes to allow simple editing of
203 the input buffer:
204 .bP
205 \fBgetnstr\fP saves the current value of the \fBnl\fP, \fBecho\fP,
206 \fBraw\fP and \fBcbreak\fP modes, and sets
207 \fBnl\fP,
208 \fBnoecho\fP,
209 \fBnoraw\fP, and
210 \fBcbreak\fP.
211 .IP
212 \fBgetnstr\fP handles the echoing of characters,
213 rather than relying on the caller to set an appropriate mode.
214 .bP
215 It also obtains the \fIerase\fP and \fIkill\fP characters
216 from \fBerasechar\fP and \fBkillchar\fP, respectively.
217 .bP
218 On return, \fBgetnstr\fP restores the modes to their previous values.
219 .PP
220 Other implementations differ in their treatment of special characters:
221 .bP
222 While they may set the \fIecho\fP mode,
223 other implementations do not modify the \fIraw\fP mode,
224 They may take the \fIcbreak\fP
225 mode set by the caller into account when deciding whether to handle
226 echoing within \fBgetnstr\fP or as a side-effect of the \fBgetch\fP calls.
227 .bP
228 The original ncurses (as \fIpcurses\fP in 1986) set \fBnoraw\fP and \fBcbreak\fP
229 when accepting input for \fBgetnstr\fP.
230 That may have been done to make function- and cursor-keys work;
231 it is not necessary with ncurses.
232 .IP
233 Since 1995, ncurses has provided signal handlers for INTR and QUIT
234 (e.g., \fB^C\fP or \fB^\\\fP).
235 With the \fBnoraw\fP and \fBcbreak\fP settings,
236 those may catch a signal and stop the program,
237 where other implementations allow one to enter those characters in the buffer.
238 .bP
239 Starting in 2021 (ncurses 6.3), \fBgetnstr\fP sets \fBraw\fP,
240 rather than \fBnoraw\fP and \fBcbreak\fP for better compatibility with
241 SVr4-curses, e.g., allowing one to enter a \fB^C\fP into the buffer.
242 .SH SEE ALSO
243 \fBcurses\fP(3X),
244 \fBcurs_getch\fP(3X),
245 \fBcurs_termattrs\fP(3X),
246 \fBcurs_variables\fP(3X).