Debian Codegraph @

upstream/opensuse-tumbleweed/man3/get_wch.3ncurses

raw
1 .\"***************************************************************************
2 .\" Copyright 2018-2025,2026 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.72 2026/04/18 22:59:29 tom Exp $
31 .TH get_wch 3NCURSES 2026-04-18 "ncurses 6.6" "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 buffer
54 .SH SYNOPSIS
55 .nf
56 \fB#include <ncursesw/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 input stream 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(3NCURSES) 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 \*(``Key Codes\*(''
96 in \fB\%getch\fP(3NCURSES).
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(3NCURSES)),
101 the function returns
102 .BR ERR ";"
103 otherwise,
104 .I curses
105 waits until the terminal has input.
106 If \fB\%cbreak\fP(3NCURSES) or \fB\%raw\fP(3NCURSES)
107 has been called,
108 this happens after one character is read.
109 If \fB\%nocbreak\fP(3NCURSES) or \fB\%noraw\fP(3NCURSES)
110 has been called,
111 it occurs when the next newline is read.
112 (Because the terminal's canonical 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(3NCURSES)
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(3NCURSES) 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(3NCURSES)),
134 the cursor moves leftward one position
135 and the new position is erased
136 as if \fB\%wmove\fP(3NCURSES) and then \fB\%wdelch\fP(3NCURSES) 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(3NCURSES).
149 .bP
150 If the window
151 .I win
152 has been moved or modified since the last call to
153 \fB\%wrefresh\fP(3NCURSES),
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(3NCURSES) has been called,
161 .B \%wget_wch
162 stores 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 screen.
172 .SH RETURN VALUE
173 .B \%wget_wch
174 returns
175 .B OK
176 when it reads a wide character,
177 .B \%KEY_CODE_YES
178 when it reads a function key code,
179 and
180 .B ERR
181 on failure.
182 .B \%wget_wch
183 fails if
184 its timeout expires without any data arriving,
185 which cannot happen if \fB\%nodelay\fP(3NCURSES) is in effect on the window.
186 .PP
187 In
188 .IR \%ncurses ,
189 .B \%wget_wch
190 also fails if
191 .bP
192 the
193 .I curses
194 screen has not been initialized,
195 .bP
196 (for functions taking a
197 .I \%WINDOW
198 pointer argument)
199 .I win
200 is a null pointer,
201 .bP
202 the terminal input stream is closed,
203 in which case
204 .I \%errno
205 is set to
206 .IR \%EBADF ","
207 or
208 .bP
209 execution was interrupted by a signal,
210 in which case
211 .I \%errno
212 is set to
213 .IR \%EINTR "."
214 .PP
215 Functions prefixed with \*(``mv\*('' first perform cursor movement and
216 fail if the position
217 .RI ( y ,
218 .IR x ")"
219 is outside the window boundaries.
220 .PP
221 .B \%unget_wch
222 returns
223 .B OK
224 on success and
225 .B ERR
226 on failure.
227 In
228 .IR \%ncurses ,
229 .B \%unget_wch
230 fails if
231 .bP
232 the
233 .I curses
234 screen has not been initialized,
235 or
236 .bP
237 there is no more room in the input queue.
238 .SH NOTES
239 See the \*(``NOTES\*('' section of \fB\%wgetch\fP(3NCURSES).
240 .PP
241 All of these functions except
242 .B \%wget_wch
243 and
244 .B \%unget_wch
245 may be implemented as macros.
246 .PP
247 Unlike \fB\%wgetch\fP(3NCURSES),
248 .B \%wget_wch
249 stores the value of the input character in an additional
250 .I wch
251 parameter instead of the return value.
252 .PP
253 Unlike
254 .BR \%ungetch ","
255 .B \%unget_wch
256 cannot distinguish function key codes from conventional character codes.
257 An application can overcome this limitation by pushing function key
258 codes with
259 .B \%ungetch
260 and subsequently checking the return value of
261 .B \%wget_wch
262 for a match with
263 .BR \%KEY_CODE_YES "."
264 .SH EXTENSIONS
265 See the \*(``EXTENSIONS\*('' section of \fB\%wgetch\fP(3NCURSES).
266 .SH PORTABILITY
267 Applications employing
268 .I \%ncurses
269 extensions should condition their use on the visibility of the
270 .B \%NCURSES_VERSION
271 preprocessor macro.
272 .PP
273 X/Open Curses Issue\ 4 describes these functions.
274 It specifies no error conditions for them.
275 .PP
276 See the \*(``PORTABILITY\*('' section of \fB\%wgetch\fP(3NCURSES) regarding
277 the interaction of
278 .I \%wget_wch
279 with signal handlers.
280 .SH HISTORY
281 X/Open Curses Issue\ 4 (1995) initially specified these functions.
282 The System\ V Interface Definition Version\ 4
283 of the same year
284 specified functions named
285 .I \%wgetwch
286 (with its variants)
287 .IR \%ungetwch "."
288 .\" SVID 4, vol 3., pp. 496-499
289 These were later additions to
290 .RI SVr4. x ,
291 not appearing in the first SVr4 (1989).
292 They differ from X/Open's later
293 .I \%wget_wch
294 and
295 .I \%unget_wch
296 in that
297 .I \%wgetwch
298 takes no
299 .I wch
300 argument,
301 but returns the (wide) key code as an
302 .I int
303 (with no provision for distinguishing a character code
304 from a function key code);
305 and
306 .I \%ungetwch
307 takes a
308 .RI non- const
309 .I int
310 argument.
311 .SH SEE ALSO
312 \fB\%getch\fP(3NCURSES) describes comparable functions of the
313 .I \%ncurses
314 library in its non-wide-character configuration.
315 .PP
316 \fB\%ncurses\fP(3NCURSES),
317 \fB\%add_wch\fP(3NCURSES),
318 \fB\%inopts\fP(3NCURSES),
319 \fB\%move\fP(3NCURSES),
320 \fB\%refresh\fP(3NCURSES)