]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_getstr.3x.html
ncurses 6.4 - patch 20230729
[ncurses.git] / doc / html / man / curs_getstr.3x.html
1 <!--
2   ****************************************************************************
3   * Copyright 2018-2022,2023 Thomas E. Dickey                                *
4   * Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
5   *                                                                          *
6   * Permission is hereby granted, free of charge, to any person obtaining a  *
7   * copy of this software and associated documentation files (the            *
8   * "Software"), to deal in the Software without restriction, including      *
9   * without limitation the rights to use, copy, modify, merge, publish,      *
10   * distribute, distribute with modifications, sublicense, and/or sell       *
11   * copies of the Software, and to permit persons to whom the Software is    *
12   * furnished to do so, subject to the following conditions:                 *
13   *                                                                          *
14   * The above copyright notice and this permission notice shall be included  *
15   * in all copies or substantial portions of the Software.                   *
16   *                                                                          *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18   * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20   * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22   * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23   * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24   *                                                                          *
25   * Except as contained in this notice, the name(s) of the above copyright   *
26   * holders shall not be used in advertising or otherwise to promote the     *
27   * sale, use or other dealings in this Software without prior written       *
28   * authorization.                                                           *
29   ****************************************************************************
30   * @Id: curs_getstr.3x,v 1.41 2023/07/29 16:32:52 tom Exp @
31 -->
32 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
33 <HTML>
34 <HEAD>
35 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
36 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
37 <TITLE>curs_getstr 3x 2023-07-29 ncurses 6.4 Library calls</TITLE>
38 <link rel="author" href="mailto:bug-ncurses@gnu.org">
39
40 </HEAD>
41 <BODY>
42 <H1 class="no-header">curs_getstr 3x 2023-07-29 ncurses 6.4 Library calls</H1>
43 <PRE>
44 <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>                  Library calls                 <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>
45
46
47
48
49 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
50        <STRONG>getstr</STRONG>, <STRONG>getnstr</STRONG>, <STRONG>wgetstr</STRONG>, <STRONG>wgetnstr</STRONG>, <STRONG>mvgetstr</STRONG>, <STRONG>mvgetnstr</STRONG>, <STRONG>mvwgetstr</STRONG>,
51        <STRONG>mvwgetnstr</STRONG> - accept character strings from <STRONG>curses</STRONG> terminal keyboard
52
53
54 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
55        <STRONG>#include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
56
57        <STRONG>int</STRONG> <STRONG>getstr(char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
58        <STRONG>int</STRONG> <STRONG>getnstr(char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
59        <STRONG>int</STRONG> <STRONG>wgetstr(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
60        <STRONG>int</STRONG> <STRONG>wgetnstr(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
61
62        <STRONG>int</STRONG> <STRONG>mvgetstr(int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
63        <STRONG>int</STRONG> <STRONG>mvwgetstr(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
64        <STRONG>int</STRONG> <STRONG>mvgetnstr(int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
65        <STRONG>int</STRONG> <STRONG>mvwgetnstr(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
66
67
68 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
69        The function <STRONG>wgetnstr</STRONG> is equivalent to a series of calls to <STRONG><A HREF="curs_getch.3x.html">wgetch(3x)</A></STRONG>,
70        until a newline or carriage return terminates the series:
71
72        <STRONG>o</STRONG>   The terminating character is not included in the returned string.
73
74        <STRONG>o</STRONG>   In all instances, the end of the string is terminated by a NUL.
75
76        <STRONG>o</STRONG>   The  function  stores  the result in the area pointed to by the <EM>str</EM>
77            parameter.
78
79        <STRONG>o</STRONG>   The function reads at most <EM>n</EM> characters, thus preventing a possible
80            overflow of the input buffer.
81
82            Any  attempt  to  enter more characters (other than the terminating
83            newline or carriage return) causes a beep.
84
85            Function keys also cause a beep and are ignored.
86
87        The user's <EM>erase</EM> and <EM>kill</EM> characters are interpreted:
88
89        <STRONG>o</STRONG>   The <EM>erase</EM> character (e.g., <STRONG>^H</STRONG>) erases the character at the  end  of
90            the buffer, moving the cursor to the left.
91
92            If <EM>keypad</EM> mode is on for the window, <STRONG>KEY_LEFT</STRONG> and <STRONG>KEY_BACKSPACE</STRONG> are
93            both considered equivalent to the user's <EM>erase</EM> character.
94
95        <STRONG>o</STRONG>   The <EM>kill</EM> character (e.g., <STRONG>^U</STRONG>) erases the entire buffer, leaving the
96            cursor at the beginning of the buffer.
97
98        Characters  input  are  echoed  only  if <STRONG>echo</STRONG> is currently on.  In that
99        case, backspace is echoed as deletion of the previous character  (typi-
100        cally a left motion).
101
102        The  <STRONG>getnstr</STRONG>, <STRONG>mvgetnstr</STRONG>, <STRONG>mvwgetnstr</STRONG>, and <STRONG>wgetnstr</STRONG> functions are identi-
103        cal to the <STRONG>getstr</STRONG>, <STRONG>mvgetstr</STRONG>, <STRONG>mvwgetstr</STRONG>, and <STRONG>wgetstr</STRONG> functions,  respec-
104        tively, except that the <STRONG>*n*</STRONG> versions read at most <EM>n</EM> characters, letting
105        the application prevent overflow of the input buffer.
106
107
108 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
109        Any of these functions other than <STRONG>wgetnstr</STRONG> may be macros.
110
111        Using <STRONG>getstr</STRONG>, <STRONG>mvgetstr</STRONG>, <STRONG>mvwgetstr</STRONG>, or <STRONG>wgetstr</STRONG> to read a line that over-
112        flows the array pointed to by <STRONG>str</STRONG> causes undefined results.  The use of
113        <STRONG>getnstr</STRONG>, <STRONG>mvgetnstr</STRONG>, <STRONG>mvwgetnstr</STRONG>, or <STRONG>wgetnstr</STRONG>,  respectively,  is  recom-
114        mended.
115
116
117 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
118        All  of  these  functions return the integer <STRONG>OK</STRONG> upon successful comple-
119        tion.  (SVr4 specifies only "an integer value other than <STRONG>ERR</STRONG>")  If  un-
120        successful, they return <STRONG>ERR</STRONG>.
121
122        X/Open defines no error conditions.
123
124        In this implementation, these functions return an error
125
126        <STRONG>o</STRONG>   if the window pointer is null, or
127
128        <STRONG>o</STRONG>   if its timeout expires without having any data.
129
130        <STRONG>o</STRONG>   if the associated call to <STRONG>wgetch</STRONG> failed.
131
132        This  implementation  provides an extension as well.  If a <STRONG>SIGWINCH</STRONG> in-
133        terrupts the function, it will return <STRONG>KEY_RESIZE</STRONG> rather than <STRONG>OK</STRONG> or <STRONG>ERR</STRONG>.
134
135        Functions with a "mv" prefix first  perform  a  cursor  movement  using
136        <STRONG>wmove</STRONG>, and return an error if the position is outside the window, or if
137        the window pointer is null.
138
139
140 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
141        These functions are described in The Single Unix Specification, Version
142        2.  No error conditions are defined.
143
144        This  implementation  returns  <STRONG>ERR</STRONG> if the window pointer is null, or if
145        the lower-level <STRONG><A HREF="curs_getch.3x.html">wgetch(3x)</A></STRONG> call returns an <STRONG>ERR</STRONG>.
146
147        SVr3 and early SVr4 curses  implementations  did  not  reject  function
148        keys;  the  SVr4.0  documentation  claimed that "special keys" (such as
149        function keys, "home" key, "clear" key, <EM>etc</EM>.) are "interpreted",  with-
150        out  giving details.  It lied.  In fact, the "character" value appended
151        to the string by those implementations was predictable but  not  useful
152        (being, in fact, the low-order eight bits of the key's KEY_ value).
153
154        The  functions  <STRONG>getnstr</STRONG>, <STRONG>mvgetnstr</STRONG>, and <STRONG>mvwgetnstr</STRONG> were present but not
155        documented in SVr4.
156
157        X/Open Curses, Issue 5 (2007) stated that these functions "read at most
158        <EM>n</EM>  bytes"  but  did not state whether the terminating NUL is counted in
159        that limit.  X/Open Curses, Issue 7 (2009) changed  that  to  say  they
160        "read at most <EM>n</EM>-1 bytes" to allow for the terminating NUL.  As of 2018,
161        some implementations count it, some do not:
162
163        <STRONG>o</STRONG>   ncurses 6.1 and PDCurses do not count the NUL in the  given  limit,
164            while
165
166        <STRONG>o</STRONG>   Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
167
168        <STRONG>o</STRONG>   Solaris  xcurses  provides  both:  its wide-character <STRONG>wget_nstr</STRONG> re-
169            serves a NUL, but its <STRONG>wgetnstr</STRONG> does not count the NUL consistently.
170
171        In SVr4 curses, a negative value of <EM>n</EM> tells <STRONG>wgetnstr</STRONG> to assume that the
172        caller's  buffer  is large enough to hold the result, i.e., to act like
173        <STRONG>wgetstr</STRONG>.  X/Open Curses does not mention this (or anything  related  to
174        negative  or  zero  values  of <EM>n</EM>), however most implementations use the
175        feature, with different limits:
176
177        <STRONG>o</STRONG>   Solaris SVr4 curses and PDCurses limit the  result  to  255  bytes.
178            Other Unix systems than Solaris are likely to use the same limit.
179
180        <STRONG>o</STRONG>   Solaris xcurses limits the result to <STRONG>LINE_MAX</STRONG> bytes.
181
182        <STRONG>o</STRONG>   NetBSD  7  assumes no particular limit for the result from <STRONG>wgetstr</STRONG>.
183            However, it limits the <STRONG>wgetnstr</STRONG> parameter <EM>n</EM> to ensure  that  it  is
184            greater than zero.
185
186            A  comment in NetBSD's source code states that this is specified in
187            SUSv2.
188
189        <STRONG>o</STRONG>   ncurses (before 6.2) assumes no particular  limit  for  the  result
190            from  <STRONG>wgetstr</STRONG>,  and  treats  the  <EM>n</EM> parameter of <STRONG>wgetnstr</STRONG> like SVr4
191            curses.
192
193        <STRONG>o</STRONG>   ncurses 6.2 uses <STRONG>LINE_MAX</STRONG>, or  a  larger  (system-dependent)  value
194            which  the  <STRONG>sysconf</STRONG>  function  may provide.  If neither <STRONG>LINE_MAX</STRONG> or
195            <STRONG>sysconf</STRONG> is available, ncurses uses the POSIX value for <STRONG>LINE_MAX</STRONG>  (a
196            2048  byte limit).  In either case, it reserves a byte for the ter-
197            minating NUL.
198
199        Although <STRONG>getnstr</STRONG> is equivalent to a series of calls to <STRONG>getch</STRONG>,  it  also
200        makes  changes to the curses modes to allow simple editing of the input
201        buffer:
202
203        <STRONG>o</STRONG>   <STRONG>getnstr</STRONG> saves the current value of the <STRONG>nl</STRONG>,  <STRONG>echo</STRONG>,  <STRONG>raw</STRONG>  and  <STRONG>cbreak</STRONG>
204            modes, and sets <STRONG>nl</STRONG>, <STRONG>noecho</STRONG>, <STRONG>noraw</STRONG>, and <STRONG>cbreak</STRONG>.
205
206            <STRONG>getnstr</STRONG>  handles  the echoing of characters, rather than relying on
207            the caller to set an appropriate mode.
208
209        <STRONG>o</STRONG>   It also obtains the <EM>erase</EM> and <EM>kill</EM> characters  from  <STRONG>erasechar</STRONG>  and
210            <STRONG>killchar</STRONG>, respectively.
211
212        <STRONG>o</STRONG>   On return, <STRONG>getnstr</STRONG> restores the modes to their previous values.
213
214        Other implementations differ in their treatment of special characters:
215
216        <STRONG>o</STRONG>   While they may set the <EM>echo</EM> mode, other implementations do not mod-
217            ify the <EM>raw</EM> mode, They may take the <EM>cbreak</EM> mode set by  the  caller
218            into account when deciding whether to handle echoing within <STRONG>getnstr</STRONG>
219            or as a side-effect of the <STRONG>getch</STRONG> calls.
220
221        <STRONG>o</STRONG>   The original ncurses (as <EM>pcurses</EM> in 1986) set <STRONG>noraw</STRONG> and <STRONG>cbreak</STRONG> when
222            accepting input for <STRONG>getnstr</STRONG>.  That may have been done to make func-
223            tion- and cursor-keys work; it is not necessary with ncurses.
224
225            Since 1995, ncurses has provided signal handlers for INTR and  QUIT
226            (e.g.,  <STRONG>^C</STRONG>  or  <STRONG>^\</STRONG>).  With the <STRONG>noraw</STRONG> and <STRONG>cbreak</STRONG> settings, those may
227            catch a signal and stop the program,  where  other  implementations
228            allow one to enter those characters in the buffer.
229
230        <STRONG>o</STRONG>   Starting in 2021 (ncurses 6.3), <STRONG>getnstr</STRONG> sets <STRONG>raw</STRONG>, rather than <STRONG>noraw</STRONG>
231            and <STRONG>cbreak</STRONG> for better compatibility with SVr4-curses, e.g.,  allow-
232            ing one to enter a <STRONG>^C</STRONG> into the buffer.
233
234
235 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
236        <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_getch.3x.html">curs_getch(3x)</A></STRONG>, <STRONG><A HREF="curs_termattrs.3x.html">curs_termattrs(3x)</A></STRONG>, <STRONG><A HREF="curs_variables.3x.html">curs_variables(3x)</A></STRONG>.
237
238
239
240 ncurses 6.4                       2023-07-29                   <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>
241 </PRE>
242 <div class="nav">
243 <ul>
244 <li><a href="#h2-NAME">NAME</a></li>
245 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
246 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a></li>
247 <li><a href="#h2-NOTES">NOTES</a></li>
248 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
249 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
250 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
251 </ul>
252 </div>
253 </BODY>
254 </HTML>