]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_getstr.3x.html
dc22cb809b921f971c5fbcc10e41d7088b0d35e0
[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.65 2024/06/08 21:04:32 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-06-08 ncurses 6.5 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-06-08 ncurses 6.5 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 <STRONG>ERR</STRONG>
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        X/Open Curses, Issue 4 describes  these  functions.   It  specifies  no
142        error conditions for them.
143
144        SVr3  and  early  SVr4  curses  implementations did not reject function
145        keys; the SVr4.0 documentation claimed that  "special  keys"  (such  as
146        function  keys,  "home"  key,  "clear"  key,  <EM>etc</EM>.)  are "interpreted",
147        without giving details.  It  lied.   In  fact,  the  "character"  value
148        appended to the string by those implementations was predictable but not
149        useful (being, in fact, the low-order eight  bits  of  the  key's  KEY_
150        value).
151
152        The  functions  <STRONG>getnstr</STRONG>, <STRONG>mvgetnstr</STRONG>, and <STRONG>mvwgetnstr</STRONG> were present but not
153        documented in SVr4.
154
155        X/Open Curses, Issue 5 (2007) stated that these functions "read at most
156        <EM>n</EM>  bytes"  but did not state whether the terminating NUL counted toward
157        that limit.  X/Open Curses, Issue 7 (2009) changed  that  to  say  they
158        "read at most <EM>n</EM>-1 bytes" to allow for the terminating NUL.  As of 2018,
159        some implementations count it, some do not:
160
161        <STRONG>o</STRONG>   <EM>ncurses</EM> 6.1 and PDCurses do not count the NUL in the  given  limit,
162            while
163
164        <STRONG>o</STRONG>   Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
165
166        <STRONG>o</STRONG>   Solaris   xcurses   provides  both:  its  wide-character  <STRONG>wget_nstr</STRONG>
167            reserves  a  NUL,  but  its  <STRONG>wgetnstr</STRONG>  does  not  count   the   NUL
168            consistently.
169
170        In SVr4 curses, a negative value of <EM>n</EM> tells <STRONG>wgetnstr</STRONG> to assume that the
171        caller's buffer is large enough to hold the result, i.e., to  act  like
172        <STRONG>wgetstr</STRONG>.   X/Open  Curses does not mention this (or anything related to
173        negative or zero values of <EM>n</EM>), however  most  implementations  use  the
174        feature, with different limits:
175
176        <STRONG>o</STRONG>   Solaris  SVr4  curses  and  PDCurses limit the result to 255 bytes.
177            Other Unix systems than Solaris are likely to use the same limit.
178
179        <STRONG>o</STRONG>   Solaris xcurses limits the result to <STRONG>LINE_MAX</STRONG> bytes.
180
181        <STRONG>o</STRONG>   NetBSD 7 assumes no particular limit for the result  from  <STRONG>wgetstr</STRONG>.
182            However,  it  limits  the <STRONG>wgetnstr</STRONG> parameter <EM>n</EM> to ensure that it is
183            greater than zero.
184
185            A comment in NetBSD's source code states that this is specified  in
186            SUSv2.
187
188        <STRONG>o</STRONG>   <EM>ncurses</EM>  (before  6.2)  assumes  no particular limit for the result
189            from <STRONG>wgetstr</STRONG>, and treats the <EM>n</EM>  parameter  of  <STRONG>wgetnstr</STRONG>  like  SVr4
190            curses.
191
192        <STRONG>o</STRONG>   <EM>ncurses</EM>  6.2  uses  <STRONG>LINE_MAX</STRONG>,  or a larger (system-dependent) value
193            which the <STRONG>sysconf</STRONG> function may provide.   If  neither  <STRONG>LINE_MAX</STRONG>  or
194            <STRONG>sysconf</STRONG>  is available, <EM>ncurses</EM> uses the POSIX value for <STRONG>LINE_MAX</STRONG> (a
195            2048 byte limit).  In either case,  it  reserves  a  byte  for  the
196            terminating NUL.
197
198        Although  <STRONG>getnstr</STRONG>  is equivalent to a series of calls to <STRONG>getch</STRONG>, it also
199        makes changes to the curses modes to allow simple editing of the  input
200        buffer:
201
202        <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>
203            modes, and sets <STRONG>nl</STRONG>, <STRONG>noecho</STRONG>, <STRONG>noraw</STRONG>, and <STRONG>cbreak</STRONG>.
204
205            <STRONG>getnstr</STRONG> handles the echoing of characters, rather than  relying  on
206            the caller to set an appropriate mode.
207
208        <STRONG>o</STRONG>   It  also  obtains  the <EM>erase</EM> and <EM>kill</EM> characters from <STRONG>erasechar</STRONG> and
209            <STRONG>killchar</STRONG>, respectively.
210
211        <STRONG>o</STRONG>   On return, <STRONG>getnstr</STRONG> restores the modes to their previous values.
212
213        Other implementations differ in their treatment of special characters:
214
215        <STRONG>o</STRONG>   While they may set the <EM>echo</EM>  mode,  other  implementations  do  not
216            modify  the  <EM>raw</EM>  mode,  They  may  take the <EM>cbreak</EM> mode set by the
217            caller into account when deciding whether to handle echoing  within
218            <STRONG>getnstr</STRONG> or as a side-effect of the <STRONG>getch</STRONG> calls.
219
220        <STRONG>o</STRONG>   The original <EM>ncurses</EM> (as <EM>pcurses</EM> in 1986) set <STRONG>noraw</STRONG> and <STRONG>cbreak</STRONG> when
221            accepting input for <STRONG>getnstr</STRONG>.  That  may  have  been  done  to  make
222            function- and cursor-keys work; it is not necessary with <EM>ncurses</EM>.
223
224            Since  1995, <EM>ncurses</EM> has provided signal handlers for INTR and QUIT
225            (e.g., <STRONG>^C</STRONG> or <STRONG>^\</STRONG>).  With the <STRONG>noraw</STRONG> and <STRONG>cbreak</STRONG>  settings,  those  may
226            catch  a  signal  and stop the program, where other implementations
227            allow one to enter those characters in the buffer.
228
229        <STRONG>o</STRONG>   Starting in 2021 (<EM>ncurses</EM> 6.3), <STRONG>getnstr</STRONG> sets <STRONG>raw</STRONG>, rather than <STRONG>noraw</STRONG>
230            and   <STRONG>cbreak</STRONG>  for  better  compatibility  with  SVr4-curses,  e.g.,
231            allowing one to enter a <STRONG>^C</STRONG> into the buffer.
232
233
234 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
235        <STRONG><A HREF="curs_get_wstr.3x.html">curs_get_wstr(3x)</A></STRONG> describes comparable functions of the <EM>ncurses</EM> library
236        in its wide-character configuration (<EM>ncursesw</EM>).
237
238        <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>
239
240
241
242 ncurses 6.5                       2024-06-08                   <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>
243 </PRE>
244 <div class="nav">
245 <ul>
246 <li><a href="#h2-NAME">NAME</a></li>
247 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
248 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a></li>
249 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
250 <li><a href="#h2-NOTES">NOTES</a></li>
251 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
252 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
253 </ul>
254 </div>
255 </BODY>
256 </HTML>