blob: 32ae541abaf91264b9c493a891c4b410e9b6e15a [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301.\"***************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002.\" Copyright 2018-2023,2024 Thomas E. Dickey *
3.\" Copyright 2002-2012,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304.\" *
5.\" Permission is hereby granted, free of charge, to any person obtaining a *
6.\" copy of this software and associated documentation files (the *
7.\" "Software"), to deal in the Software without restriction, including *
8.\" without limitation the rights to use, copy, modify, merge, publish, *
9.\" distribute, distribute with modifications, sublicense, and/or sell *
10.\" copies of the Software, and to permit persons to whom the Software is *
11.\" furnished to do so, subject to the following conditions: *
12.\" *
13.\" The above copyright notice and this permission notice shall be included *
14.\" in all copies or substantial portions of the Software. *
15.\" *
16.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23.\" *
24.\" Except as contained in this notice, the name(s) of the above copyright *
25.\" holders shall not be used in advertising or otherwise to promote the *
26.\" sale, use or other dealings in this Software without prior written *
27.\" authorization. *
28.\"***************************************************************************
29.\"
micky3879b9f5e72025-07-08 18:04:53 -040030.\" $Id: curs_get_wstr.3x,v 1.48 2024/04/20 19:18:18 tom Exp $
31.TH curs_get_wstr 3X 2024-04-20 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
32.ie \n(.g \{\
33.ds `` \(lq
34.ds '' \(rq
35.\}
36.el \{\
37.ie t .ds `` ``
38.el .ds `` ""
39.ie t .ds '' ''
40.el .ds '' ""
41.\}
42.
43.de bP
44.ie n .IP \(bu 4
45.el .IP \(bu 2
46..
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047.SH NAME
micky3879b9f5e72025-07-08 18:04:53 -040048\fB\%get_wstr\fP,
49\fB\%getn_wstr\fP,
50\fB\%wget_wstr\fP,
51\fB\%wgetn_wstr\fP,
52\fB\%mvget_wstr\fP,
53\fB\%mvgetn_wstr\fP,
54\fB\%mvwget_wstr\fP,
55\fB\%mvwgetn_wstr\fP \-
56get a wide-character string from a \fIcurses\fR terminal keyboard
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053057.SH SYNOPSIS
58.nf
micky3879b9f5e72025-07-08 18:04:53 -040059\fB#include <curses.h>
60.PP
61\fBint get_wstr(wint_t *\fIwstr\fP);
62\fBint getn_wstr(wint_t *\fIwstr\fP, int \fIn\fP);
63\fBint wget_wstr(WINDOW *\fIwin\fP, wint_t *\fIwstr\fP);
64\fBint wgetn_wstr(WINDOW *\fIwin\fP, wint_t *\fIwstr\fP, int \fIn\fP);
65.PP
66\fBint mvget_wstr(int \fIy\fP, int \fIx\fP, wint_t *\fIwstr\fP);
67\fBint mvgetn_wstr(int \fIy\fP, int \fIx\fP, wint_t *\fIwstr\fP, int \fIn\fP);
68\fBint mvwget_wstr(WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP, wint_t *\fIwstr\fP);
69\fBint mvwgetn_wstr(WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP, wint_t *\fIwstr\fP, int \fIn\fP);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053070.fi
71.SH DESCRIPTION
micky3879b9f5e72025-07-08 18:04:53 -040072The function
73\fBwgetn_wstr\fP
74is equivalent to a series of calls to
75\fBwget_wch\fP(3X)
76until a newline or carriage return terminates the series:
77.bP
78The terminating character is not included in the returned string.
79.bP
80An end-of-file condition is represented by \fBWEOF\fP,
81as defined in \fB<wchar.h>\fP.
82.bP
83In all instances, the end of the string is terminated
84by a null \fBwchar_t\fP.
85.bP
86The function stores the result in the area pointed to
87by the \fIwstr\fP parameter.
88.bP
89The function reads at most \fIn\fP characters,
90thus preventing a possible overflow of the input buffer.
91.IP
92Any attempt to enter more characters
93(other than the terminating newline or carriage return)
94causes a beep.
95.IP
96Function keys also cause a beep and are ignored.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053097.PP
micky3879b9f5e72025-07-08 18:04:53 -040098The user's \fIerase\fP and \fIkill\fP characters are interpreted:
99.bP
100The \fIerase\fP character (e.g., \fB^H\fP) erases the character
101at the end of the buffer, moving the cursor to the left.
102.IP
103If \fIkeypad\fP mode is on for the window,
104\fBKEY_LEFT\fP and \fBKEY_BACKSPACE\fP
105are both considered equivalent to the user's \fIerase\fP character.
106.bP
107The \fIkill\fP character (e.g., \fB^U\fP) erases the entire buffer,
108leaving the cursor at the beginning of the buffer.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530109.PP
micky3879b9f5e72025-07-08 18:04:53 -0400110Characters input are echoed only if \fBecho\fP is currently on.
111In that case,
112backspace is echoed as deletion of the previous character
113(typically a left motion).
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530114.PP
115The
micky3879b9f5e72025-07-08 18:04:53 -0400116\fBgetn_wstr\fP,
117\fBmvgetn_wstr\fP,
118\fBmvwgetn_wstr\fP, and
119\fBwgetn_wstr\fP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530120functions are identical
121to the
micky3879b9f5e72025-07-08 18:04:53 -0400122\fBget_wstr\fP,
123\fBmvget_wstr\fP,
124\fBmvwget_wstr\fP, and
125\fBwget_wstr\fP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530126functions, respectively,
127except that the
micky3879b9f5e72025-07-08 18:04:53 -0400128\fB*n_*\fP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530129versions read at most
micky3879b9f5e72025-07-08 18:04:53 -0400130\fIn\fP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530131characters, letting the application prevent overflow of the
132input buffer.
micky3879b9f5e72025-07-08 18:04:53 -0400133.SH RETURN VALUE
134All of these functions return the integer \fBOK\fP upon successful completion.
135If unsuccessful, they return \fBERR\fP.
136.PP
137X/Open defines no error conditions.
138.PP
139In this implementation,
140these functions return an error
141.bP
142if the window pointer is null,
143.bP
144if its timeout expires without having any data, or
145.bP
146if the associated call to
147\fBwget_wch\fP
148failed.
149.PP
150Functions prefixed with \*(``mv\*('' first perform cursor movement and
151fail if the position
152.RI ( y ,
153.IR x )
154is outside the window boundaries.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530155.SH NOTES
micky3879b9f5e72025-07-08 18:04:53 -0400156Any of these functions other than
157\fBwgetn_wstr\fP
158may be macros.
159.PP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530160Using
micky3879b9f5e72025-07-08 18:04:53 -0400161\fBget_wstr\fP,
162\fBmvget_wstr\fP,
163\fBmvwget_wstr\fP, or
164\fBwget_wstr\fP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530165to read a line that
166overflows the array pointed to by
micky3879b9f5e72025-07-08 18:04:53 -0400167\fBwstr\fP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530168causes undefined
169results.
170The use of
micky3879b9f5e72025-07-08 18:04:53 -0400171\fBgetn_wstr\fP,
172\fBmvgetn_wstr\fP,
173\fBmvwgetn_wstr\fP, or
174\fBwgetn_wstr\fP,
175respectively, is recommended.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530176.PP
micky3879b9f5e72025-07-08 18:04:53 -0400177These functions cannot return \fBKEY_\fP values because there
178is no way to distinguish a \fBKEY_\fP value from a valid \fBwchar_t\fP value.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530179.SH PORTABILITY
180These functions are described in The Single Unix Specification, Version 2.
181No error conditions are defined.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530182.PP
micky3879b9f5e72025-07-08 18:04:53 -0400183This implementation returns \fBERR\fP if the window pointer is null,
184or if the lower-level \fBwget_wch\fP call returns an \fBERR\fP.
185In the latter case,
186an \fBERR\fP return without other data is treated as an end-of-file condition,
187and the returned array contains a \fBWEOF\fP followed by a null \fBwchar_t\fP.
188.PP
189X/Open curses documented these functions to pass an array of \fBwchar_t\fP
190in 1997, but that was an error because of this part of the description:
191.RS
192.PP
193The effect of \fBget_wstr\fP is as though a series of calls to
194\fBget_wch\fP were made, until a newline character, end-of-line character, or
195end-of-file character is processed.
196.RE
197.PP
198The latter function \fIget_wch\fP can return a negative value,
199while \fBwchar_t\fP is a unsigned type.
200All of the vendors implement this using \fBwint_t\fP, following the standard.
201.PP
202X/Open Curses, Issue 7 (2009) is unclear regarding whether
203the terminating \fInull \fBwchar_t\fR
204value is counted in the length parameter \fIn\fP.
205X/Open Curses, Issue 7 revised the corresponding description
206of \fBwgetnstr\fP to address this issue.
207The unrevised description of \fBwget_nwstr\fP can be interpreted either way.
208This implementation counts the terminator in the length.
209.PP
210X/Open Curses does not specify what happens if the length \fIn\fP is negative.
211.bP
212For analogy with \fBwgetnstr\fP,
213\fI\%ncurses\fP 6.2 uses a limit (based on \fBLINE_MAX\fP).
214.bP
215Some other implementations (such as Solaris xcurses) do the same,
216while others (PDCurses) do not allow this.
217.bP
218NetBSD 7 curses imitates \fI\%ncurses\fP 6.1 in this regard,
219treating a \fB\-1\fP as an indefinite number of characters.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530220.SH SEE ALSO
micky3879b9f5e72025-07-08 18:04:53 -0400221\fB\%curs_getstr\fP(3X) describes comparable functions of the
222.I \%ncurses
223library in its non-wide-character configuration.
224.PP
225\fB\%curses\fP(3X),
226\fB\%curs_get_wch\fP(3X)