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