]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_getstr.3x.html
ncurses 6.4 - patch 20240420
[ncurses.git] / doc / html / man / curs_getstr.3x.html
1 <!--
2   ****************************************************************************
3   * Copyright 2018-2023,2024 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.58 2024/04/20 19:18:18 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 2024-04-20 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 2024-04-20 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 <EM>curses</EM> 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
100        (typically a left motion).
101
102        The   <STRONG>getnstr</STRONG>,   <STRONG>mvgetnstr</STRONG>,  <STRONG>mvwgetnstr</STRONG>,  and  <STRONG>wgetnstr</STRONG>  functions  are
103        identical to the <STRONG>getstr</STRONG>, <STRONG>mvgetstr</STRONG>, <STRONG>mvwgetstr</STRONG>,  and  <STRONG>wgetstr</STRONG>  functions,
104        respectively,  except  that the <STRONG>*n*</STRONG> versions read at most <EM>n</EM> characters,
105        letting the application prevent overflow of the input buffer.
106
107
108 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
109        All  of  these  functions  return  the  integer  <STRONG>OK</STRONG>   upon   successful
110        completion.  (SVr4 specifies only "an integer value other than <STRONG>ERR</STRONG>") If
111        unsuccessful, they return <STRONG>ERR</STRONG>.
112
113        X/Open defines no error conditions.
114
115        In this implementation, these functions return an error
116
117        <STRONG>o</STRONG>   if the window pointer is null,
118
119        <STRONG>o</STRONG>   if its timeout expires without having any data, or
120
121        <STRONG>o</STRONG>   if the associated call to <STRONG>wgetch</STRONG> failed.
122
123        This implementation provides an  extension  as  well.   If  a  <STRONG>SIGWINCH</STRONG>
124        interrupts  the  function,  it will return <STRONG>KEY_RESIZE</STRONG> rather than <STRONG>OK</STRONG> or
125        <STRONG>ERR</STRONG>.
126
127        Functions prefixed with "mv" first perform cursor movement and fail  if
128        the position (<EM>y</EM>, <EM>x</EM>) is outside the window boundaries.
129
130
131 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
132        Any of these functions other than <STRONG>wgetnstr</STRONG> may be macros.
133
134        Using  <STRONG>getstr</STRONG>,  <STRONG>mvgetstr</STRONG>,  <STRONG>mvwgetstr</STRONG>,  or  <STRONG>wgetstr</STRONG>  to read a line that
135        overflows the array pointed to by <STRONG>str</STRONG> causes  undefined  results.   The
136        use  of  <STRONG>getnstr</STRONG>,  <STRONG>mvgetnstr</STRONG>, <STRONG>mvwgetnstr</STRONG>, or <STRONG>wgetnstr</STRONG>, respectively, is
137        recommended.
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",
150        without  giving  details.   It  lied.   In  fact, the "character" value
151        appended to the string by those implementations was predictable but not
152        useful  (being,  in  fact,  the  low-order eight bits of the key's KEY_
153        value).
154
155        The functions <STRONG>getnstr</STRONG>, <STRONG>mvgetnstr</STRONG>, and <STRONG>mvwgetnstr</STRONG> were present  but  not
156        documented in SVr4.
157
158        X/Open Curses, Issue 5 (2007) stated that these functions "read at most
159        <EM>n</EM> bytes" but did not state whether the terminating NUL  is  counted  in
160        that  limit.   X/Open  Curses,  Issue 7 (2009) changed that to say they
161        "read at most <EM>n</EM>-1 bytes" to allow for the terminating NUL.  As of 2018,
162        some implementations count it, some do not:
163
164        <STRONG>o</STRONG>   <EM>ncurses</EM>  6.1  and PDCurses do not count the NUL in the given limit,
165            while
166
167        <STRONG>o</STRONG>   Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
168
169        <STRONG>o</STRONG>   Solaris  xcurses  provides  both:  its   wide-character   <STRONG>wget_nstr</STRONG>
170            reserves   a   NUL,  but  its  <STRONG>wgetnstr</STRONG>  does  not  count  the  NUL
171            consistently.
172
173        In SVr4 curses, a negative value of <EM>n</EM> tells <STRONG>wgetnstr</STRONG> to assume that the
174        caller's  buffer  is large enough to hold the result, i.e., to act like
175        <STRONG>wgetstr</STRONG>.  X/Open Curses does not mention this (or anything  related  to
176        negative  or  zero  values  of <EM>n</EM>), however most implementations use the
177        feature, with different limits:
178
179        <STRONG>o</STRONG>   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
182        <STRONG>o</STRONG>   Solaris xcurses limits the result to <STRONG>LINE_MAX</STRONG> bytes.
183
184        <STRONG>o</STRONG>   NetBSD  7  assumes no particular limit for the result from <STRONG>wgetstr</STRONG>.
185            However, it limits the <STRONG>wgetnstr</STRONG> parameter <EM>n</EM> to ensure  that  it  is
186            greater than zero.
187
188            A  comment in NetBSD's source code states that this is specified in
189            SUSv2.
190
191        <STRONG>o</STRONG>   <EM>ncurses</EM> (before 6.2) assumes no particular  limit  for  the  result
192            from  <STRONG>wgetstr</STRONG>,  and  treats  the  <EM>n</EM> parameter of <STRONG>wgetnstr</STRONG> like SVr4
193            curses.
194
195        <STRONG>o</STRONG>   <EM>ncurses</EM> 6.2 uses <STRONG>LINE_MAX</STRONG>, or  a  larger  (system-dependent)  value
196            which  the  <STRONG>sysconf</STRONG>  function  may provide.  If neither <STRONG>LINE_MAX</STRONG> or
197            <STRONG>sysconf</STRONG> is available, <EM>ncurses</EM> uses the POSIX value for <STRONG>LINE_MAX</STRONG>  (a
198            2048  byte  limit).   In  either  case,  it reserves a byte for the
199            terminating NUL.
200
201        Although <STRONG>getnstr</STRONG> is equivalent to a series of calls to <STRONG>getch</STRONG>,  it  also
202        makes  changes to the curses modes to allow simple editing of the input
203        buffer:
204
205        <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>
206            modes, and sets <STRONG>nl</STRONG>, <STRONG>noecho</STRONG>, <STRONG>noraw</STRONG>, and <STRONG>cbreak</STRONG>.
207
208            <STRONG>getnstr</STRONG>  handles  the echoing of characters, rather than relying on
209            the caller to set an appropriate mode.
210
211        <STRONG>o</STRONG>   It also obtains the <EM>erase</EM> and <EM>kill</EM> characters  from  <STRONG>erasechar</STRONG>  and
212            <STRONG>killchar</STRONG>, respectively.
213
214        <STRONG>o</STRONG>   On return, <STRONG>getnstr</STRONG> restores the modes to their previous values.
215
216        Other implementations differ in their treatment of special characters:
217
218        <STRONG>o</STRONG>   While  they  may  set  the  <EM>echo</EM> mode, other implementations do not
219            modify the <EM>raw</EM> mode, They may take  the  <EM>cbreak</EM>  mode  set  by  the
220            caller  into account when deciding whether to handle echoing within
221            <STRONG>getnstr</STRONG> or as a side-effect of the <STRONG>getch</STRONG> calls.
222
223        <STRONG>o</STRONG>   The original <EM>ncurses</EM> (as <EM>pcurses</EM> in 1986) set <STRONG>noraw</STRONG> and <STRONG>cbreak</STRONG> when
224            accepting  input  for  <STRONG>getnstr</STRONG>.   That  may  have been done to make
225            function- and cursor-keys work; it is not necessary with <EM>ncurses</EM>.
226
227            Since 1995, <EM>ncurses</EM> has provided signal handlers for INTR and  QUIT
228            (e.g.,  <STRONG>^C</STRONG>  or  <STRONG>^\</STRONG>).  With the <STRONG>noraw</STRONG> and <STRONG>cbreak</STRONG> settings, those may
229            catch a signal and stop the program,  where  other  implementations
230            allow one to enter those characters in the buffer.
231
232        <STRONG>o</STRONG>   Starting in 2021 (<EM>ncurses</EM> 6.3), <STRONG>getnstr</STRONG> sets <STRONG>raw</STRONG>, rather than <STRONG>noraw</STRONG>
233            and  <STRONG>cbreak</STRONG>  for  better  compatibility  with  SVr4-curses,   e.g.,
234            allowing one to enter a <STRONG>^C</STRONG> into the buffer.
235
236
237 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
238        <STRONG><A HREF="curs_get_wstr.3x.html">curs_get_wstr(3x)</A></STRONG> describes comparable functions of the <EM>ncurses</EM> library
239        in its wide-character configuration (<EM>ncursesw</EM>).
240
241        <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>
242
243
244
245 ncurses 6.4                       2024-04-20                   <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>
246 </PRE>
247 <div class="nav">
248 <ul>
249 <li><a href="#h2-NAME">NAME</a></li>
250 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
251 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a></li>
252 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
253 <li><a href="#h2-NOTES">NOTES</a></li>
254 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
255 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
256 </ul>
257 </div>
258 </BODY>
259 </HTML>