]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_getstr.3x.html
ncurses 6.2 - patch 20210619
[ncurses.git] / doc / html / man / curs_getstr.3x.html
1 <!--
2   ****************************************************************************
3   * Copyright 2018-2020,2021 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.33 2021/05/22 21:36:35 tom Exp @
31   * X/Open says also until EOf
32   * X/Open says then an EOS is added to the result
33   * X/Open doesn't mention n&lt;0
34 -->
35 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
36 <HTML>
37 <HEAD>
38 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
39 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
40 <TITLE>curs_getstr 3X</TITLE>
41 <link rel="author" href="mailto:bug-ncurses@gnu.org">
42 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
43 </HEAD>
44 <BODY>
45 <H1 class="no-header">curs_getstr 3X</H1>
46 <PRE>
47 <B><A HREF="curs_getstr.3X.html">curs_getstr(3X)</A></B>                                                <B><A HREF="curs_getstr.3X.html">curs_getstr(3X)</A></B>
48
49
50
51
52 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
53        <B>getstr</B>, <B>getnstr</B>, <B>wgetstr</B>, <B>wgetnstr</B>, <B>mvgetstr</B>, <B>mvgetnstr</B>, <B>mvwgetstr</B>,
54        <B>mvwgetnstr</B> - accept character strings from <B>curses</B> terminal keyboard
55
56
57 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
58        <B>#include</B> <B>&lt;curses.h&gt;</B>
59
60        <B>int</B> <B>getstr(char</B> <B>*</B><I>str</I><B>);</B>
61        <B>int</B> <B>getnstr(char</B> <B>*</B><I>str</I><B>,</B> <B>int</B> <I>n</I><B>);</B>
62        <B>int</B> <B>wgetstr(WINDOW</B> <B>*</B><I>win</I><B>,</B> <B>char</B> <B>*</B><I>str</I><B>);</B>
63        <B>int</B> <B>wgetnstr(WINDOW</B> <B>*</B><I>win</I><B>,</B> <B>char</B> <B>*</B><I>str</I><B>,</B> <B>int</B> <I>n</I><B>);</B>
64
65        <B>int</B> <B>mvgetstr(int</B> <I>y</I><B>,</B> <B>int</B> <I>x</I><B>,</B> <B>char</B> <B>*</B><I>str</I><B>);</B>
66        <B>int</B> <B>mvwgetstr(WINDOW</B> <B>*</B><I>win</I><B>,</B> <B>int</B> <I>y</I><B>,</B> <B>int</B> <I>x</I><B>,</B> <B>char</B> <B>*</B><I>str</I><B>);</B>
67        <B>int</B> <B>mvgetnstr(int</B> <I>y</I><B>,</B> <B>int</B> <I>x</I><B>,</B> <B>char</B> <B>*</B><I>str</I><B>,</B> <B>int</B> <I>n</I><B>);</B>
68        <B>int</B> <B>mvwgetnstr(WINDOW</B> <B>*</B><I>win</I><B>,</B> <B>int</B> <I>y</I><B>,</B> <B>int</B> <I>x</I><B>,</B> <B>char</B> <B>*</B><I>str</I><B>,</B> <B>int</B> <I>n</I><B>);</B>
69
70
71 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
72        The function <B>getstr</B> is equivalent to a series of calls to <B>getch</B>,  until
73        a  newline or carriage return is received (the terminating character is
74        not included in the returned string).  The resulting value is placed in
75        the area pointed to by the character pointer <I>str</I>, followed by a NUL.
76
77        The  <B>getnstr</B>  function reads from the <I>stdscr</I> default window.  The other
78        functions, such as <B>wgetnstr</B>, read from the window given as a parameter.
79
80        <B>getnstr</B> reads at most <I>n</I> characters, thus preventing a possible overflow
81        of  the input buffer.  Any attempt to enter more characters (other than
82        the terminating newline or carriage return) causes  a  beep.   Function
83        keys also cause a beep and are ignored.
84
85        The user's <I>erase</I> and <I>kill</I> characters are interpreted:
86
87        <B>o</B>   The  <I>erase</I>  character (e.g., <B>^H</B>) erases the character at the end of
88            the buffer, moving the cursor to the left.
89
90            If <I>keypad</I> mode is on for the window, <B>KEY_LEFT</B> and <B>KEY_BACKSPACE</B> are
91            both considered equivalent to the user's erase character.
92
93        <B>o</B>   The <I>kill</I> character (e.g., <B>^U</B>) erases the entire buffer, leaving the
94            cursor at the beginning of the buffer.
95
96        Characters input are echoed only if <B>echo</B>  is  currently  on.   In  that
97        case,  backspace is echoed as deletion of the previous character (typi-
98        cally a left motion).
99
100
101 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
102        All routines return the integer <B>ERR</B> upon failure and an <B>OK</B> (SVr4 speci-
103        fies  only  "an  integer value other than <B>ERR</B>") upon successful comple-
104        tion.
105
106        X/Open defines no error conditions.
107
108        In this implementation, these functions return an error if  the  window
109        pointer is null, or if its timeout expires without having any data.
110
111        This  implementation  provides an extension as well.  If a <B>SIGWINCH</B> in-
112        terrupts the function, it will return <B>KEY_RESIZE</B> rather than <B>OK</B> or <B>ERR</B>.
113
114        Functions with a "mv" prefix first  perform  a  cursor  movement  using
115        <B>wmove</B>, and return an error if the position is outside the window, or if
116        the window pointer is null.
117
118
119 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
120        Note that <B>getstr</B>, <B>mvgetstr</B>, and <B>mvwgetstr</B> may be macros.
121
122
123 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
124        These functions are described in the  XSI  Curses  standard,  Issue  4.
125        They  read  single-byte  characters only.  The standard does not define
126        any error conditions.  This implementation returns <B>ERR</B>  if  the  window
127        pointer is null, or if the lower-level <B><A HREF="curs_getch.3X.html">wgetch(3X)</A></B> call returns an <B>ERR</B>.
128
129        SVr3  and  early  SVr4  curses  implementations did not reject function
130        keys; the SVr4.0 documentation claimed that  "special  keys"  (such  as
131        function  keys, "home" key, "clear" key, <I>etc</I>.) are "interpreted", with-
132        out giving details.  It lied.  In fact, the "character" value  appended
133        to  the  string by those implementations was predictable but not useful
134        (being, in fact, the low-order eight bits of the key's KEY_ value).
135
136        The functions <B>getnstr</B>, <B>mvgetnstr</B>, and <B>mvwgetnstr</B> were present  but  not
137        documented in SVr4.
138
139        X/Open Curses, Issue 5 (2007) stated that these functions "read at most
140        <I>n</I> bytes" but did not state whether the terminating NUL  is  counted  in
141        that  limit.   X/Open  Curses,  Issue 7 (2009) changed that to say they
142        "read at most <I>n</I>-1 bytes" to allow for the terminating NUL.  As of 2018,
143        some implementations do, some do not count it:
144
145        <B>o</B>   ncurses  6.1  and PDCurses do not count the NUL in the given limit,
146            while
147
148        <B>o</B>   Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
149
150        <B>o</B>   Solaris xcurses provides both:  its  wide-character  <B>wget_nstr</B>  re-
151            serves a NUL, but its <B>wgetnstr</B> does not count the NUL consistently.
152
153        In SVr4 curses, a negative value of <I>n</I> tells <B>wgetnstr</B> to assume that the
154        caller's buffer is large enough to hold the result, i.e., to  act  like
155        <B>wgetstr</B>.   X/Open  Curses does not mention this (or anything related to
156        negative or zero values of <I>n</I>), however  most  implementations  use  the
157        feature, with different limits:
158
159        <B>o</B>   Solaris  SVr4  curses  and  PDCurses limit the result to 255 bytes.
160            Other Unix systems than Solaris are likely to use the same limit.
161
162        <B>o</B>   Solaris xcurses limits the result to <B>LINE_MAX</B> bytes.
163
164        <B>o</B>   NetBSD 7 assumes no particular limit for the result  from  <B>wgetstr</B>.
165            However,  it  limits  the <B>wgetnstr</B> parameter <I>n</I> to ensure that it is
166            greater than zero.
167
168            A comment in NetBSD's source code states that this is specified  in
169            SUSv2.
170
171        <B>o</B>   ncurses  (before  6.2)  assumes  no particular limit for the result
172            from <B>wgetstr</B>, and treats the <I>n</I>  parameter  of  <B>wgetnstr</B>  like  SVr4
173            curses.
174
175        <B>o</B>   ncurses  6.2  uses  <B>LINE_MAX</B>,  or a larger (system-dependent) value
176            which the <B>sysconf</B> function may provide.   If  neither  <B>LINE_MAX</B>  or
177            <B>sysconf</B>  is available, ncurses uses the POSIX value for <B>LINE_MAX</B> (a
178            2048 byte limit).  In either case, it reserves a byte for the  ter-
179            minating NUL.
180
181        Although  <B>getnstr</B>  is equivalent to a series of calls to <B>getch</B>, it also
182        makes changes to the curses modes to allow simple editing of the  input
183        buffer:
184
185        <B>o</B>   <B>getnstr</B>  saves  the  current  value of the <B>nl</B>, <B>echo</B>, <B>raw</B> and <B>cbreak</B>
186            modes, and sets <B>nl</B>, <B>noecho</B>, <B>noraw</B>, and <B>cbreak</B>.
187
188            <B>getnstr</B> handles the echoing of characters, rather than  relying  on
189            the caller to set an appropriate mode.
190
191        <B>o</B>   It  also  obtains  the <I>erase</I> and <I>kill</I> characters from <B>erasechar</B> and
192            <B>killchar</B>, respectively.
193
194        <B>o</B>   On return, <B>getnstr</B> restores the modes to their previous values.
195
196        Other implementations differ in their treatment of special characters:
197
198        <B>o</B>   While they may set the <I>echo</I> mode, other implementations do not mod-
199            ify  the  <I>raw</I> mode, They may take the <I>cbreak</I> mode set by the caller
200            into account when deciding whether to handle echoing within <B>getnstr</B>
201            or as a side-effect of the <B>getch</B> calls.
202
203        <B>o</B>   The original ncurses (as pcurses in 1986) set <B>noraw</B> and <B>cbreak</B> when
204            accepting input for <B>getnstr</B>.  That may have been done to make func-
205            tion- and cursor-keys work; it is not necessary with ncurses.
206
207            Since  1995, ncurses has provided signal handlers for INTR and QUIT
208            (e.g., <B>^C</B> or <B>^\</B>).  With the <B>noraw</B> and <B>cbreak</B>  settings,  those  may
209            catch  a  signal  and stop the program, where other implementations
210            allow one to enter those characters in the buffer.
211
212        <B>o</B>   Starting in 2021 (ncurses 6.3), <B>getnstr</B> sets <B>raw</B>, rather than <B>noraw</B>
213            and  <B>cbreak</B> for better compatibility with SVr4-curses, e.g., allow-
214            ing one to enter a <B>^C</B> into the buffer.
215
216
217 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
218        <B><A HREF="curses.3X.html">curses(3X)</A></B>, <B><A HREF="curs_getch.3X.html">curs_getch(3X)</A></B>, <B><A HREF="curs_termattrs.3X.html">curs_termattrs(3X)</A></B>, <B><A HREF="curs_variables.3X.html">curs_variables(3X)</A></B>.
219
220
221
222                                                                <B><A HREF="curs_getstr.3X.html">curs_getstr(3X)</A></B>
223 </PRE>
224 <div class="nav">
225 <ul>
226 <li><a href="#h2-NAME">NAME</a></li>
227 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
228 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a></li>
229 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
230 <li><a href="#h2-NOTES">NOTES</a></li>
231 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
232 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
233 </ul>
234 </div>
235 </BODY>
236 </HTML>