Debian Codegraph @

upstream/debian-trixie/man3/get_wch.3ncurses

raw
1 .\"***************************************************************************
2 .\" Copyright 2018-2024,2025 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.66 2025/02/15 19:35:48 tom Exp $
31 .TH get_wch 3NCURSES 2025-02-15 "ncurses 6.5" "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 <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(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 \*(``Predefined 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 \fB\%nl\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 .bP
185 its timeout expires without any data arriving,
186 or
187 .bP
188 execution was interrupted by a signal,
189 in which case
190 .I \%errno
191 is set to
192 .IR \%EINTR "."
193 .PP
194 Functions taking a
195 .I \%WINDOW
196 pointer argument fail if
197 .I win
198 is a null pointer.
199 .PP
200 Functions prefixed with \*(``mv\*('' first perform cursor movement and
201 fail if the position
202 .RI ( y ,
203 .IR x ")"
204 is outside the window boundaries.
205 .PP
206 .B \%unget_wch
207 returns
208 .B OK
209 on success and
210 .B ERR
211 if there is no more room in the input queue.
212 .SH NOTES
213 See the \*(``NOTES\*('' section of \fB\%wgetch\fP(3NCURSES).
214 .PP
215 All of these functions except
216 .B \%wget_wch
217 and
218 .B \%unget_wch
219 may be implemented as macros.
220 .PP
221 Unlike \fB\%wgetch\fP(3NCURSES),
222 .B \%wget_wch
223 and its variants store the value of the input character in an additional
224 .I wch
225 parameter instead of the return value.
226 .PP
227 Unlike
228 .BR \%ungetch ","
229 .B \%unget_wch
230 cannot distinguish function key codes from conventional character codes.
231 An application can overcome this limitation by pushing function key
232 codes with
233 .B \%ungetch
234 and subsequently checking the return value of
235 .B \%wget_wch
236 for a match with
237 .BR \%KEY_CODE_YES "."
238 .SH EXTENSIONS
239 See the \*(``EXTENSIONS\*('' section of \fB\%wgetch\fP(3NCURSES).
240 .SH PORTABILITY
241 Applications employing
242 .I \%ncurses
243 extensions should condition their use on the visibility of the
244 .B \%NCURSES_VERSION
245 preprocessor macro.
246 .PP
247 X/Open Curses Issue\ 4 describes these functions.
248 It specifies no error conditions for them.
249 .PP
250 See the \*(``PORTABILITY\*('' section of \fB\%wgetch\fP(3NCURSES) regarding
251 the interaction of
252 .I \%wget_wch
253 with signal handlers.
254 .SH HISTORY
255 X/Open Curses Issue\ 4 (1995) initially specified these functions.
256 The System\ V Interface Definition Version\ 4
257 of the same year
258 specified functions named
259 .I \%wgetwch
260 (with its variants)
261 .IR \%ungetwch "."
262 .\" SVID 4, vol 3., pp. 496-499
263 These were later additions to
264 .RI SVr4. x ,
265 not appearing in the first SVr4 (1989).
266 They differ from X/Open's later
267 .I \%wget_wch
268 and
269 .I \%unget_wch
270 in that
271 .I \%wgetwch
272 takes no
273 .I wch
274 argument,
275 but returns the (wide) key code as an
276 .I int
277 (with no provision for distinguishing a character code
278 from a function key code);
279 and
280 .I \%ungetwch
281 takes a
282 .RI non- const
283 .I int
284 argument.
285 .SH SEE ALSO
286 \fB\%getch\fP(3NCURSES) describes comparable functions of the
287 .I \%ncurses
288 library in its non-wide-character configuration.
289 .PP
290 \fB\%ncurses\fP(3NCURSES),
291 \fB\%add_wch\fP(3NCURSES),
292 \fB\%inopts\fP(3NCURSES),
293 \fB\%move\fP(3NCURSES),
294 \fB\%refresh\fP(3NCURSES)