]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_get_wch.3x
ncurses 6.5 - patch 20240608
[ncurses.git] / man / curs_get_wch.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2023,2024 Thomas E. Dickey                                *
3 .\" Copyright 2002-2016,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
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 .\"
30 .\" $Id: curs_get_wch.3x,v 1.43 2024/06/08 20:25:25 tom Exp $
31 .TH curs_get_wch 3X 2024-06-08 "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 ..
47 .SH NAME
48 \fB\%get_wch\fP,
49 \fB\%wget_wch\fP,
50 \fB\%mvget_wch\fP,
51 \fB\%mvwget_wch\fP,
52 \fB\%unget_wch\fP \-
53 get (or push back) a wide character from \fIcurses\fR terminal keyboard
54 .SH SYNOPSIS
55 .nf
56 \fB#include <curses.h>
57 .PP
58 \fBint get_wch(wint_t *\fIwch\fP);
59 \fBint wget_wch(WINDOW *\fIwin\fP, wint_t *\fIwch\fP);
60 \fBint mvget_wch(int \fIy\fP, int \fIx\fP, wint_t *\fIwch\fP);
61 \fBint mvwget_wch(WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP, wint_t *\fIwch\fP);
62 .PP
63 \fBint unget_wch(const wchar_t \fIwc\fP);
64 .fi
65 .SH DESCRIPTION
66 .SS "Reading Characters"
67 .B \%wget_wch
68 gathers a key event from the terminal keyboard associated with a
69 .I curses
70 window
71 .IR win ","
72 returning
73 .B OK
74 if a wide character is read,
75 .B \%KEY_CODE_YES
76 if a function key is read,
77 and
78 .B ERR
79 if no key event is available.
80 \fB\%ncurses\fP(3X) describes the variants of this function.
81 .PP
82 When input is pending,
83 .B \%wget_wch
84 stores an integer
85 identifying the key event in
86 .IR wch ";"
87 for alphanumeric and punctuation keys,
88 this value corresponds to the character encoding used by the terminal.
89 Use of the control key as a modifier,
90 by holding it down while pressing and releasing another key,
91 often results in a distinct code.
92 The behavior of other keys depends on whether
93 .I win
94 is in keypad mode;
95 see subsections \*(``Keypad Mode\*('' and \*(``Predefined Key Codes\*(''
96 in \fB\%getch\fP(3X).
97 .PP
98 If no input is pending,
99 then if the no-delay flag is set in the window
100 (see \fB\%nodelay\fP(3X)),
101 the function returns
102 .BR ERR ";"
103 otherwise,
104 .I curses
105 waits until the terminal has input.
106 If \fB\%cbreak\fP(3X)
107 has been called,
108 this happens after one character is read.
109 If \fB\%nocbreak\fP(3X) or \fB\%noraw\fP(3X)
110 has been called,
111 it occurs when the next newline is read.
112 (Because the terminal's normal or \*(``cooked\*('' mode
113 is line-buffered,
114 multiple
115 .B \%wget_wch
116 calls may then be necessary to empty the input queue.)
117 If \fB\%halfdelay\fP(3X)
118 has been called,
119 .I curses
120 waits until input is available or the specified delay elapses.
121 .PP
122 If \fB\%echo\fP(3X) has been called,
123 and the window is not a pad,
124 .I curses
125 writes the wide character
126 from the input queue
127 to the window
128 (at the cursor position)
129 per the following rules.
130 .bP
131 If the wide character
132 matches the terminal's erase character
133 (see \fB\%erasewchar\fP(3X)),
134 the cursor moves leftward one position
135 and the new position is erased
136 as if \fB\%wmove\fP(3X) and then \fB\%wdelch\fP(3X) were called.
137 When the window's keypad mode is enabled
138 (see below),
139 .B \%KEY_LEFT
140 and
141 .B \%KEY_BACKSPACE
142 are handled the same way.
143 .bP
144 .I curses
145 writes any other
146 wide character
147 to the window,
148 as with \fB\%wecho_wchar\fP(3X).
149 .bP
150 If the window
151 .I win
152 has been moved or modified since the last call to
153 \fB\%wrefresh\fP(3X),
154 .I curses
155 calls
156 .B \%wrefresh
157 on it.
158 .PP
159 If the wide character
160 is a carriage return and \fBnl\fP(3X) has been called,
161 .B \%wgetch
162 stores the the wide character code for line feed in
163 .I wch
164 instead.
165 .SS "Ungetting Characters"
166 .B \%unget_wch
167 places
168 .I wc
169 into the input queue to be retrieved by the next call to
170 .BR \%wget_wch "."
171 A single input queue serves all windows associated with the terminal.
172 .SH RETURN VALUE
173 .B \%wget_wch
174 returns
175 .B OK
176 when it reads a wide character and
177 .B \%KEY_CODE_YES
178 when it reads a function key code.
179 It returns
180 .B ERR
181 if
182 .bP
183 the
184 .I \%WINDOW
185 pointer is
186 .BR NULL ","
187 or
188 .bP
189 its timeout expires without any data arriving,
190 or
191 .bP
192 execution was interrupted by a signal,
193 in which case
194 .B \%errno
195 is set to
196 .BR \%EINTR "."
197 .PP
198 Functions prefixed with \*(``mv\*('' first perform cursor movement and
199 fail if the position
200 .RI ( y ,
201 .IR x ")"
202 is outside the window boundaries.
203 .PP
204 .B \%unget_wch
205 returns
206 .B OK
207 on success and
208 .B ERR
209 if there is no more room in the input queue.
210 .SH NOTES
211 See the \*(``NOTES\*('' section of \fB\%wgetch\fP(3X).
212 .PP
213 All of these functions except
214 .B \%wget_wch
215 and
216 .B \%unget_wch
217 may be implemented as macros.
218 .PP
219 Unlike \fB\%wgetch\fP(3X),
220 .B \%wget_wch
221 and its variants store the value of the input character in an additional
222 .I wch
223 parameter instead of the return value.
224 .PP
225 Unlike
226 .BR \%ungetch ","
227 .B \%unget_wch
228 cannot distinguish function key codes from conventional character codes.
229 An application can overcome this limitation by pushing function key
230 codes with
231 .B \%ungetch
232 and subsequently checking the return value of
233 .B \%wget_wch
234 for a match with
235 .BR \%KEY_CODE_YES "."
236 .SH EXTENSIONS
237 See the \*(``EXTENSIONS\*('' section of \fB\%wgetch\fP(3X).
238 .SH PORTABILITY
239 Applications employing
240 .I \%ncurses
241 extensions should condition their use on the visibility of the
242 .B \%NCURSES_VERSION
243 preprocessor macro.
244 .PP
245 X/Open Curses,
246 Issue 4 describes these functions.
247 It specifies no error conditions for them.
248 .PP
249 See the \*(``PORTABILITY\*('' section of \fB\%wgetch\fP(3X) regarding
250 the interaction of
251 .B \%wget_wch
252 with signal handlers.
253 .SH SEE ALSO
254 \fB\%curs_getch\fP(3X) describes comparable functions of the
255 .I \%ncurses
256 library in its non-wide-character configuration.
257 .PP
258 \fB\%curses\fP(3X),
259 \fB\%curs_add_wch\fP(3X),
260 \fB\%curs_inopts\fP(3X),
261 \fB\%curs_move\fP(3X),
262 \fB\%curs_refresh\fP(3X)