1 .\"***************************************************************************
2 .\" Copyright 2018-2019,2020 Thomas E. Dickey *
3 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc. *
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: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
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. *
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 *
28 .\"***************************************************************************
30 .\" $Id: curs_inopts.3x,v 1.32 2020/10/24 09:18:33 tom Exp $
57 \fBtypeahead\fR \- \fBcurses\fR input options
61 \fB#include <curses.h>\fR
63 \fBint cbreak(void);\fR
65 \fBint nocbreak(void);\fR
69 \fBint noecho(void);\fR
71 \fBint intrflush(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
73 \fBint keypad(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
75 \fBint meta(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
77 \fBint nodelay(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
79 \fBint notimeout(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
87 \fBint noraw(void);\fR
89 \fBvoid qiflush(void);\fR
91 \fBvoid noqiflush(void);\fR
93 \fBint halfdelay(int \fP\fItenths\fP\fB);\fR
95 \fBvoid timeout(int \fP\fIdelay\fP\fB);\fR
97 \fBvoid wtimeout(WINDOW *\fP\fIwin\fP\fB, int \fP\fIdelay\fP\fB);\fR
99 \fBint typeahead(int \fP\fIfd\fP\fB);\fR
102 The \fBncurses\fP library provides several functions which let an application
103 change the way input from the terminal is handled.
104 Some are global, applying to all windows.
105 Others apply only to a specific window.
106 Window-specific settings are not automatically applied to new or derived
108 An application must apply these to each window, if the same behavior
112 Normally, the tty driver buffers typed characters until a newline or carriage
114 The \fBcbreak\fR routine disables line buffering and
115 erase/kill character-processing (interrupt and flow control characters are
116 unaffected), making characters typed by the user immediately available to the
118 The \fBnocbreak\fR routine returns the terminal to normal (cooked)
121 Initially the terminal may or may not be in \fBcbreak\fR mode, as the mode is
122 inherited; therefore, a program should call \fBcbreak\fR or \fBnocbreak\fR
124 Most interactive programs using \fBcurses\fR set the \fBcbreak\fR
126 Note that \fBcbreak\fR overrides \fBraw\fR.
127 [See \fBcurs_getch\fR(3X) for a
128 discussion of how these routines interact with \fBecho\fR and \fBnoecho\fR.]
132 The \fBecho\fR and \fBnoecho\fR routines control whether characters typed by
133 the user are echoed by \fBgetch\fR(3X) as they are typed.
135 driver is always disabled, but initially \fBgetch\fR is in echo mode, so
136 characters typed are echoed.
137 Authors of most interactive programs prefer to do
138 their own echoing in a controlled area of the screen, or not to echo at all, so
139 they disable echoing by calling \fBnoecho\fR.
140 [See \fBcurs_getch\fR(3X) for a
141 discussion of how these routines interact with \fBcbreak\fR and
146 The \fBhalfdelay\fR routine is used for half-delay mode, which is similar to
147 \fBcbreak\fR mode in that characters typed by the user are immediately
148 available to the program.
149 However, after blocking for \fItenths\fR tenths of
150 seconds, \fBERR\fP is returned if nothing has been typed.
151 The value of \fItenths\fR
152 must be a number between 1 and 255.
153 Use \fBnocbreak\fR to leave half-delay
158 If the \fBintrflush\fR option is enabled (\fIbf\fR is \fBTRUE\fR), and an
159 interrupt key is pressed on the keyboard (interrupt, break, quit), all output in
160 the tty driver queue will be flushed, giving the effect of faster response to
161 the interrupt, but causing \fBcurses\fR to have the wrong idea of what is on
163 Disabling the option (\fIbf\fR is \fBFALSE\fR) prevents the
165 The default for the option is inherited from the tty driver settings.
166 The window argument is ignored.
170 The \fBkeypad\fR option enables the keypad of the user's terminal.
172 enabled (\fIbf\fR is \fBTRUE\fR), the user can press a function key
173 (such as an arrow key) and \fBwgetch\fR(3X) returns a single value
174 representing the function key, as in \fBKEY_LEFT\fR.
176 (\fIbf\fR is \fBFALSE\fR), \fBcurses\fR does not treat function keys
177 specially and the program has to interpret the escape sequences
179 If the keypad in the terminal can be turned on (made to
180 transmit) and off (made to work locally), turning on this option
181 causes the terminal keypad to be turned on when \fBwgetch\fR(3X) is
183 The default value for keypad is \fBFALSE\fP.
187 Initially, whether the terminal returns 7 or 8 significant bits on
188 input depends on the control mode of the tty driver [see \fBtermios\fP(3)].
189 To force 8 bits to be returned, invoke \fBmeta\fR(\fIwin\fR,
190 \fBTRUE\fR); this is equivalent, under POSIX, to setting the CS8 flag
192 To force 7 bits to be returned, invoke
193 \fBmeta\fR(\fIwin\fR, \fBFALSE\fR); this is equivalent, under POSIX,
194 to setting the CS7 flag on the terminal.
196 \fIwin\fR, is always ignored.
197 If the terminfo capabilities \fBsmm\fR
198 (meta_on) and \fBrmm\fR (meta_off) are defined for the terminal,
199 \fBsmm\fR is sent to the terminal when \fBmeta\fR(\fIwin\fR,
200 \fBTRUE\fR) is called and \fBrmm\fR is sent when \fBmeta\fR(\fIwin\fR,
201 \fBFALSE\fR) is called.
205 The \fBnl\fR and \fBnonl\fR routines control whether the underlying display
206 device translates the return key into newline on input.
208 .SS nodelay/notimeout
210 The \fBnodelay\fR option causes \fBgetch\fR to be a non-blocking call.
211 If no input is ready, \fBgetch\fR returns \fBERR\fR.
213 (\fIbf\fR is \fBFALSE\fR), \fBgetch\fR waits until a key is pressed.
215 While interpreting an input escape sequence, \fBwgetch\fR(3X) sets a timer
216 while waiting for the next character.
217 If \fBnotimeout(\fR\fIwin\fR,
218 \fBTRUE\fR) is called, then \fBwgetch\fR does not set a timer.
220 purpose of the timeout is to differentiate between sequences received
221 from a function key and those typed by a user.
225 The \fBraw\fR and \fBnoraw\fR routines place the terminal into or out of raw
227 Raw mode is similar to \fBcbreak\fR mode, in that characters typed are
228 immediately passed through to the user program.
229 The differences are that in
230 raw mode, the interrupt, quit, suspend, and flow control characters are all
231 passed through uninterpreted, instead of generating a signal.
233 the BREAK key depends on other bits in the tty driver that are not set by
236 .SS qiflush/noqiflush
238 When the \fBnoqiflush\fR routine is used, normal flush of input and
239 output queues associated with the \fBINTR\fR, \fBQUIT\fR and
240 \fBSUSP\fR characters will not be done [see \fBtermios\fP(3)].
242 \fBqiflush\fR is called, the queues will be flushed when these control
244 You may want to call \fBnoqiflush\fR in a signal
245 handler if you want output to continue as though the interrupt
246 had not occurred, after the handler exits.
250 The \fBtimeout\fR and \fBwtimeout\fR routines set blocking or
251 non-blocking read for a given window.
252 If \fIdelay\fR is negative,
253 blocking read is used (i.e., waits indefinitely for
255 If \fIdelay\fR is zero, then non-blocking read is used
256 (i.e., read returns \fBERR\fR if no input is waiting).
258 \fIdelay\fR is positive, then read blocks for \fIdelay\fR
259 milliseconds, and returns \fBERR\fR if there is still no input.
260 Hence, these routines provide the same functionality as \fBnodelay\fR,
261 plus the additional capability of being able to block for only
262 \fIdelay\fR milliseconds (where \fIdelay\fR is positive).
266 The \fBcurses\fR library does \*(``line-breakout optimization\*(''
267 by looking for typeahead periodically while updating the screen.
268 If input is found, and it is coming from a tty,
269 the current update is postponed until
270 \fBrefresh\fR(3X) or \fBdoupdate\fR is called again.
271 This allows faster response to commands typed in advance.
272 Normally, the input FILE
273 pointer passed to \fBnewterm\fR, or \fBstdin\fR in the case that
274 \fBinitscr\fR was used, will be used to do this typeahead checking.
275 The \fBtypeahead\fR routine specifies that the file descriptor
276 \fIfd\fR is to be used to check for typeahead instead.
278 \-1, then no typeahead checking is done.
281 All routines that return an integer return \fBERR\fR upon failure and \fBOK\fP
282 (SVr4 specifies only \*(``an integer value other than \fBERR\fR\*('')
283 upon successful completion,
284 unless otherwise noted in the preceding routine descriptions.
286 X/Open does not define any error conditions.
287 In this implementation,
288 functions with a window parameter will return an error if it is null.
289 Any function will also return an error if the terminal was not initialized.
295 if its parameter is outside the range 1..255.
298 These functions are described in the XSI Curses standard, Issue 4.
300 The ncurses library obeys the XPG4 standard and the historical practice of the
301 AT&T curses implementations, in that the echo bit is cleared when curses
302 initializes the terminal state.
303 BSD curses differed from this slightly; it
304 left the echo bit on at initialization, but the BSD \fBraw\fR call turned it
305 off as a side-effect.
306 For best portability, set \fBecho \fPor \fBnoecho\fP explicitly
307 just after initialization, even if your program remains in cooked mode.
309 The XSI Curses standard is ambiguous on the question of whether \fBraw\fR
310 should disable the CRLF translations controlled by \fBnl\fR and \fBnonl\fR.
311 BSD curses did turn off these translations; AT&T curses (at least as late as
313 We chose to do so, on the theory that a programmer requesting
314 raw input wants a clean (ideally 8-bit clean) connection that the operating
315 system will not alter.
317 When \fBkeypad\fP is first enabled,
318 ncurses loads the key-definitions for the current terminal description.
319 If the terminal description includes extended string capabilities,
320 e.g., from using the \fB\-x\fP option of \fB@TIC@\fP,
321 then ncurses also defines keys for the capabilities whose names
322 begin with \*(``k\*(''.
323 The corresponding keycodes are generated and (depending on previous
324 loads of terminal descriptions) may differ from one execution of a
326 The generated keycodes are recognized by the \fBkeyname\fP function
327 (which will then return a name beginning with \*(``k\*('' denoting the
328 terminfo capability name rather than \*(``K\*('', used for curses key-names).
329 On the other hand, an application can use \fBdefine_key\fP to establish
330 a specific keycode for a given string.
331 This makes it possible for an application to check for an extended
332 capability's presence with \fBtigetstr\fP,
333 and reassign the keycode to match its own needs.
335 Low-level applications can use \fBtigetstr\fP to obtain the definition
336 of any particular string capability.
337 Higher-level applications which use the curses \fBwgetch\fP
338 and similar functions to return keycodes rely upon the order in which
339 the strings are loaded.
340 If more than one key definition has the same string value,
341 then \fBwgetch\fP can return only one keycode.
342 Most curses implementations (including ncurses)
343 load key definitions in the order
344 defined by the array of string capability names.
345 The last key to be loaded determines the keycode which will be returned.
346 In ncurses, you may also have extended capabilities interpreted as
348 These are loaded after the predefined keys,
349 and if a capability's value is the same as a previously-loaded
351 the later definition is the one used.
366 \fBwtimeout\fR may be macros.
368 The \fBnoraw\fR and \fBnocbreak\fR calls follow historical practice in that
369 they attempt to restore to normal (\*(``cooked\*('') mode
370 from raw and cbreak modes respectively.
371 Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver
372 control states that are hard to predict or understand; it is not recommended.
375 \fBcurs_getch\fR(3X),
376 \fBcurs_initscr\fR(3X),
378 \fBdefine_key\fR(3X),