1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
4 .\" Permission is hereby granted, free of charge, to any person obtaining a *
5 .\" copy of this software and associated documentation files (the *
6 .\" "Software"), to deal in the Software without restriction, including *
7 .\" without limitation the rights to use, copy, modify, merge, publish, *
8 .\" distribute, distribute with modifications, sublicense, and/or sell *
9 .\" copies of the Software, and to permit persons to whom the Software is *
10 .\" furnished to do so, subject to the following conditions: *
12 .\" The above copyright notice and this permission notice shall be included *
13 .\" in all copies or substantial portions of the Software. *
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 .\" Except as contained in this notice, the name(s) of the above copyright *
24 .\" holders shall not be used in advertising or otherwise to promote the *
25 .\" sale, use or other dealings in this Software without prior written *
27 .\"***************************************************************************
29 .\" $Id: curs_inopts.3x,v 1.25 2017/02/18 16:39:44 tom Exp $
54 \fBtypeahead\fR \- \fBcurses\fR input options
58 \fB#include <curses.h>\fR
60 \fBint cbreak(void);\fR
62 \fBint nocbreak(void);\fR
66 \fBint noecho(void);\fR
68 \fBint halfdelay(int tenths);\fR
70 \fBint intrflush(WINDOW *win, bool bf);\fR
72 \fBint keypad(WINDOW *win, bool bf);\fR
74 \fBint meta(WINDOW *win, bool bf);\fR
76 \fBint nodelay(WINDOW *win, bool bf);\fR
80 \fBint noraw(void);\fR
82 \fBvoid noqiflush(void);\fR
84 \fBvoid qiflush(void);\fR
86 \fBint notimeout(WINDOW *win, bool bf);\fR
88 \fBvoid timeout(int delay);\fR
90 \fBvoid wtimeout(WINDOW *win, int delay);\fR
92 \fBint typeahead(int fd);\fR
95 The \fBncurses\fP library provides several functions which let an application
96 change the way input from the terminal is handled.
97 Some are global, applying to all windows.
98 Others apply only to a specific window.
99 Window-specific settings are not automatically applied to new or derived
101 An application must apply these to each window, if the same behavior
105 Normally, the tty driver buffers typed characters until a newline or carriage
107 The \fBcbreak\fR routine disables line buffering and
108 erase/kill character-processing (interrupt and flow control characters are
109 unaffected), making characters typed by the user immediately available to the
111 The \fBnocbreak\fR routine returns the terminal to normal (cooked)
114 Initially the terminal may or may not be in \fBcbreak\fR mode, as the mode is
115 inherited; therefore, a program should call \fBcbreak\fR or \fBnocbreak\fR
117 Most interactive programs using \fBcurses\fR set the \fBcbreak\fR
119 Note that \fBcbreak\fR overrides \fBraw\fR.
120 [See \fBcurs_getch\fR(3X) for a
121 discussion of how these routines interact with \fBecho\fR and \fBnoecho\fR.]
125 The \fBecho\fR and \fBnoecho\fR routines control whether characters typed by
126 the user are echoed by \fBgetch\fR(3X) as they are typed.
128 driver is always disabled, but initially \fBgetch\fR is in echo mode, so
129 characters typed are echoed.
130 Authors of most interactive programs prefer to do
131 their own echoing in a controlled area of the screen, or not to echo at all, so
132 they disable echoing by calling \fBnoecho\fR.
133 [See \fBcurs_getch\fR(3X) for a
134 discussion of how these routines interact with \fBcbreak\fR and
139 The \fBhalfdelay\fR routine is used for half-delay mode, which is similar to
140 \fBcbreak\fR mode in that characters typed by the user are immediately
141 available to the program.
142 However, after blocking for \fItenths\fR tenths of
143 seconds, ERR is returned if nothing has been typed.
144 The value of \fItenths\fR
145 must be a number between 1 and 255.
146 Use \fBnocbreak\fR to leave half-delay
151 If the \fBintrflush\fR option is enabled (\fIbf\fR is \fBTRUE\fR), and an
152 interrupt key is pressed on the keyboard (interrupt, break, quit), all output in
153 the tty driver queue will be flushed, giving the effect of faster response to
154 the interrupt, but causing \fBcurses\fR to have the wrong idea of what is on
156 Disabling the option (\fIbf\fR is \fBFALSE\fR) prevents the
158 The default for the option is inherited from the tty driver settings.
159 The window argument is ignored.
163 The \fBkeypad\fR option enables the keypad of the user's terminal.
165 enabled (\fIbf\fR is \fBTRUE\fR), the user can press a function key
166 (such as an arrow key) and \fBwgetch\fR(3X) returns a single value
167 representing the function key, as in \fBKEY_LEFT\fR.
169 (\fIbf\fR is \fBFALSE\fR), \fBcurses\fR does not treat function keys
170 specially and the program has to interpret the escape sequences
172 If the keypad in the terminal can be turned on (made to
173 transmit) and off (made to work locally), turning on this option
174 causes the terminal keypad to be turned on when \fBwgetch\fR(3X) is
176 The default value for keypad is \fBFALSE\fP.
180 Initially, whether the terminal returns 7 or 8 significant bits on
181 input depends on the control mode of the tty driver [see termio(7)].
182 To force 8 bits to be returned, invoke \fBmeta\fR(\fIwin\fR,
183 \fBTRUE\fR); this is equivalent, under POSIX, to setting the CS8 flag
185 To force 7 bits to be returned, invoke
186 \fBmeta\fR(\fIwin\fR, \fBFALSE\fR); this is equivalent, under POSIX,
187 to setting the CS7 flag on the terminal.
189 \fIwin\fR, is always ignored.
190 If the terminfo capabilities \fBsmm\fR
191 (meta_on) and \fBrmm\fR (meta_off) are defined for the terminal,
192 \fBsmm\fR is sent to the terminal when \fBmeta\fR(\fIwin\fR,
193 \fBTRUE\fR) is called and \fBrmm\fR is sent when \fBmeta\fR(\fIwin\fR,
194 \fBFALSE\fR) is called.
198 The \fBnodelay\fR option causes \fBgetch\fR to be a non-blocking call.
199 If no input is ready, \fBgetch\fR returns \fBERR\fR.
201 (\fIbf\fR is \fBFALSE\fR), \fBgetch\fR waits until a key is pressed.
203 While interpreting an input escape sequence, \fBwgetch\fR(3X) sets a timer
204 while waiting for the next character.
205 If \fBnotimeout(\fR\fIwin\fR,
206 \fBTRUE\fR) is called, then \fBwgetch\fR does not set a timer.
208 purpose of the timeout is to differentiate between sequences received
209 from a function key and those typed by a user.
213 The \fBraw\fR and \fBnoraw\fR routines place the terminal into or out of raw
215 Raw mode is similar to \fBcbreak\fR mode, in that characters typed are
216 immediately passed through to the user program.
217 The differences are that in
218 raw mode, the interrupt, quit, suspend, and flow control characters are all
219 passed through uninterpreted, instead of generating a signal.
221 the BREAK key depends on other bits in the tty driver that are not set by
226 When the \fBnoqiflush\fR routine is used, normal flush of input and
227 output queues associated with the \fBINTR\fR, \fBQUIT\fR and
228 \fBSUSP\fR characters will not be done [see termio(7)].
230 \fBqiflush\fR is called, the queues will be flushed when these control
232 You may want to call \fBnoqiflush\fR in a signal
233 handler if you want output to continue as though the interrupt
234 had not occurred, after the handler exits.
238 The \fBtimeout\fR and \fBwtimeout\fR routines set blocking or
239 non-blocking read for a given window.
240 If \fIdelay\fR is negative,
241 blocking read is used (i.e., waits indefinitely for
243 If \fIdelay\fR is zero, then non-blocking read is used
244 (i.e., read returns \fBERR\fR if no input is waiting).
246 \fIdelay\fR is positive, then read blocks for \fIdelay\fR
247 milliseconds, and returns \fBERR\fR if there is still no input.
248 Hence, these routines provide the same functionality as \fBnodelay\fR,
249 plus the additional capability of being able to block for only
250 \fIdelay\fR milliseconds (where \fIdelay\fR is positive).
254 The \fBcurses\fR library does \*(``line-breakout optimization\*(''
255 by looking for typeahead periodically while updating the screen.
256 If input is found, and it is coming from a tty,
257 the current update is postponed until
258 \fBrefresh\fR(3X) or \fBdoupdate\fR is called again.
259 This allows faster response to commands typed in advance.
260 Normally, the input FILE
261 pointer passed to \fBnewterm\fR, or \fBstdin\fR in the case that
262 \fBinitscr\fR was used, will be used to do this typeahead checking.
263 The \fBtypeahead\fR routine specifies that the file descriptor
264 \fIfd\fR is to be used to check for typeahead instead.
266 \-1, then no typeahead checking is done.
269 All routines that return an integer return \fBERR\fR upon failure and OK (SVr4
270 specifies only \*(``an integer value other than \fBERR\fR\*('') upon successful
271 completion, unless otherwise noted in the preceding routine descriptions.
273 X/Open does not define any error conditions.
274 In this implementation,
275 functions with a window parameter will return an error if it is null.
276 Any function will also return an error if the terminal was not initialized.
282 if its parameter is outside the range 1..255.
285 These functions are described in the XSI Curses standard, Issue 4.
287 The ncurses library obeys the XPG4 standard and the historical practice of the
288 AT&T curses implementations, in that the echo bit is cleared when curses
289 initializes the terminal state.
290 BSD curses differed from this slightly; it
291 left the echo bit on at initialization, but the BSD \fBraw\fR call turned it
292 off as a side-effect.
293 For best portability, set echo or noecho explicitly
294 just after initialization, even if your program remains in cooked mode.
296 When \fBkeypad\fP is first enabled,
297 ncurses loads the key-definitions for the current terminal description.
298 If the terminal description includes extended string capabilities,
299 e.g., from using the \fB\-x\fP option of \fBtic\fP,
300 then ncurses also defines keys for the capabilities whose names
301 begin with \*(``k\*(''.
302 The corresponding keycodes are generated and (depending on previous
303 loads of terminal descriptions) may differ from one execution of a
305 The generated keycodes are recognized by the \fBkeyname\fP function
306 (which will then return a name beginning with \*(``k\*('' denoting the
307 terminfo capability name rather than \*(``K\*('', used for curses key-names).
308 On the other hand, an application can use \fBdefine_key\fP to establish
309 a specific keycode for a given string.
310 This makes it possible for an application to check for an extended
311 capability's presence with \fBtigetstr\fP,
312 and reassign the keycode to match its own needs.
314 Low-level applications can use \fBtigetstr\fP to obtain the definition
315 of any particular string capability.
316 Higher-level applications which use the curses \fBwgetch\fP
317 and similar functions to return keycodes rely upon the order in which
318 the strings are loaded.
319 If more than one key definition has the same string value,
320 then \fBwgetch\fP can return only one keycode.
321 Most curses implementations (including ncurses)
322 load key definitions in the order
323 defined by the array of string capability names.
324 The last key to be loaded determines the keycode which will be returned.
325 In ncurses, you may also have extended capabilities interpreted as
327 These are loaded after the predefined keys,
328 and if a capability's value is the same as a previously-loaded
330 the later definition is the one used.
332 Note that \fBecho\fR, \fBnoecho\fR, \fBhalfdelay\fR, \fBintrflush\fR,
333 \fBmeta\fR, \fBnodelay\fR, \fBnotimeout\fR, \fBnoqiflush\fR,
334 \fBqiflush\fR, \fBtimeout\fR, and \fBwtimeout\fR may be macros.
336 The \fBnoraw\fR and \fBnocbreak\fR calls follow historical practice in that
337 they attempt to restore to normal (\*(``cooked\*('') mode from raw and cbreak modes
339 Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver
340 control states that are hard to predict or understand; it is not recommended.
343 \fBcurs_getch\fR(3X),
344 \fBcurs_initscr\fR(3X),
346 \fBdefine_key\fR(3X),