]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_get_wch.3x
ncurses 6.5 - patch 20240511
[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.41 2024/05/11 20:39:53 tom Exp $
31 .TH curs_get_wch 3X 2024-05-11 "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)
110 has been called,
111 it occurs when the next newline is read.
112 If \fB\%halfdelay\fP(3X)
113 has been called,
114 .I curses
115 waits until input is available or the specified delay elapses.
116 .PP
117 If \fB\%echo\fP(3X) has been called,
118 and the window is not a pad,
119 .I curses
120 writes
121 .I wch
122 to the window
123 (at the cursor position)
124 per the following rules.
125 .bP
126 If
127 .I wch
128 matches the terminal's erase character,
129 the cursor moves leftward one position
130 and the new position is erased
131 as if \fB\%wmove\fP(3X) and then \fB\%wdelch\fP(3X) were called.
132 When the window's keypad mode is enabled
133 (see below),
134 .B \%KEY_LEFT
135 and
136 .B \%KEY_BACKSPACE
137 are handled the same way.
138 .bP
139 .I curses
140 writes any other
141 .I wch
142 to the window,
143 as with \fB\%wecho_wchar\fP(3X).
144 .bP
145 If the window
146 .I win
147 has been moved or modified since the last call to
148 \fB\%wrefresh\fP(3X),
149 .I curses
150 calls
151 .B \%wrefresh
152 on it.
153 .PP
154 If
155 .I wch
156 is a carriage return and \fBnl\fP(3X) has been called,
157 .B \%wgetch
158 stores the the character code for line feed in
159 .I wch
160 instead.
161 .SS "Ungetting Characters"
162 .B \%unget_wch
163 places
164 .I wch
165 into the input queue to be returned by the next call to
166 .BR \%wget_wch "."
167 A single input queue serves all windows associated with the terminal.
168 .SH RETURN VALUE
169 .B \%wget_wch
170 returns
171 .B OK
172 when it reads a wide character and
173 .B \%KEY_CODE_YES
174 when it reads a function key code.
175 It returns
176 .B ERR
177 if
178 .bP
179 the
180 .I \%WINDOW
181 pointer is
182 .BR NULL ","
183 or
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 .B \%errno
191 is set to
192 .BR \%EINTR "."
193 .PP
194 Functions prefixed with \*(``mv\*('' first perform cursor movement and
195 fail if the position
196 .RI ( y ,
197 .IR x ")"
198 is outside the window boundaries.
199 .PP
200 .B \%unget_wch
201 returns
202 .B OK
203 on success and
204 .B ERR
205 if there is no more room in the input queue.
206 .SH NOTES
207 See the \*(``NOTES\*('' section of \fB\%wgetch\fP(3X).
208 .PP
209 All of these functions except
210 .B \%wget_wch
211 and
212 .B \%unget_wch
213 may be implemented as macros.
214 .PP
215 Unlike \fB\%wgetch\fP(3X),
216 .B \%wget_wch
217 and its variants store the value of the input character in an additional
218 .I wch
219 parameter instead of the return value.
220 .PP
221 Unlike
222 .BR \%ungetch ","
223 .B \%unget_wch
224 cannot distinguish function key codes from conventional character codes.
225 An application can overcome this limitation by pushing function key
226 codes with
227 .B \%ungetch
228 and subsequently checking the return value of
229 .B \%wget_wch
230 for a match with
231 .BR \%KEY_CODE_YES "."
232 .SH EXTENSIONS
233 See the \*(``EXTENSIONS\*('' section of \fB\%wgetch\fP(3X).
234 .SH PORTABILITY
235 Applications employing
236 .I \%ncurses
237 extensions should condition their use on the visibility of the
238 .B \%NCURSES_VERSION
239 preprocessor macro.
240 .PP
241 X/Open Curses,
242 Issue 4 describes these functions.
243 It specifies no error conditions for them.
244 .PP
245 See the \*(``PORTABILITY\*('' section of \fB\%wgetch\fP(3X) regarding
246 the interaction of
247 .B \%wget_wch
248 with signal handlers.
249 .SH SEE ALSO
250 \fB\%curs_getch\fP(3X) describes comparable functions of the
251 .I \%ncurses
252 library in its non-wide-character configuration.
253 .PP
254 \fB\%curses\fP(3X),
255 \fB\%curs_add_wch\fP(3X),
256 \fB\%curs_inopts\fP(3X),
257 \fB\%curs_move\fP(3X),
258 \fB\%curs_refresh\fP(3X)