]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_inopts.3x
ncurses 6.2 - patch 20200808
[ncurses.git] / man / curs_inopts.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2019,2020 Thomas E. Dickey                                *
3 .\" Copyright 1998-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_inopts.3x,v 1.29 2020/02/02 23:34:34 tom Exp $
31 .TH curs_inopts 3X ""
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .na
37 .hy 0
38 .SH NAME
39 \fBcbreak\fR,
40 \fBnocbreak\fR,
41 \fBecho\fR,
42 \fBnoecho\fR,
43 \fBhalfdelay\fR,
44 \fBintrflush\fR,
45 \fBkeypad\fR,
46 \fBmeta\fR,
47 \fBnodelay\fR,
48 \fBnotimeout\fR,
49 \fBraw\fR,
50 \fBnoraw\fR,
51 \fBnoqiflush\fR,
52 \fBqiflush\fR,
53 \fBtimeout\fR,
54 \fBwtimeout\fR,
55 \fBtypeahead\fR \- \fBcurses\fR input options
56 .ad
57 .hy
58 .SH SYNOPSIS
59 \fB#include <curses.h>\fR
60 .PP
61 \fBint cbreak(void);\fR
62 .br
63 \fBint nocbreak(void);\fR
64 .br
65 \fBint echo(void);\fR
66 .br
67 \fBint noecho(void);\fR
68 .br
69 \fBint halfdelay(int tenths);\fR
70 .br
71 \fBint intrflush(WINDOW *win, bool bf);\fR
72 .br
73 \fBint keypad(WINDOW *win, bool bf);\fR
74 .br
75 \fBint meta(WINDOW *win, bool bf);\fR
76 .br
77 \fBint nodelay(WINDOW *win, bool bf);\fR
78 .br
79 \fBint raw(void);\fR
80 .br
81 \fBint noraw(void);\fR
82 .br
83 \fBvoid noqiflush(void);\fR
84 .br
85 \fBvoid qiflush(void);\fR
86 .br
87 \fBint notimeout(WINDOW *win, bool bf);\fR
88 .br
89 \fBvoid timeout(int delay);\fR
90 .br
91 \fBvoid wtimeout(WINDOW *win, int delay);\fR
92 .br
93 \fBint typeahead(int fd);\fR
94 .br
95 .SH DESCRIPTION
96 The \fBncurses\fP library provides several functions which let an application
97 change the way input from the terminal is handled.
98 Some are global, applying to all windows.
99 Others apply only to a specific window.
100 Window-specific settings are not automatically applied to new or derived
101 windows.
102 An application must apply these to each window, if the same behavior
103 is needed.
104 .\"
105 .SS cbreak
106 Normally, the tty driver buffers typed characters until a newline or carriage
107 return is typed.
108 The \fBcbreak\fR routine disables line buffering and
109 erase/kill character-processing (interrupt and flow control characters are
110 unaffected), making characters typed by the user immediately available to the
111 program.
112 The \fBnocbreak\fR routine returns the terminal to normal (cooked)
113 mode.
114 .PP
115 Initially the terminal may or may not be in \fBcbreak\fR mode, as the mode is
116 inherited; therefore, a program should call \fBcbreak\fR or \fBnocbreak\fR
117 explicitly.
118 Most interactive programs using \fBcurses\fR set the \fBcbreak\fR
119 mode.
120 Note that \fBcbreak\fR overrides \fBraw\fR.
121 [See \fBcurs_getch\fR(3X) for a
122 discussion of how these routines interact with \fBecho\fR and \fBnoecho\fR.]
123 .\"
124 .SS echo/noecho
125 .PP
126 The \fBecho\fR and \fBnoecho\fR routines control whether characters typed by
127 the user are echoed by \fBgetch\fR(3X) as they are typed.
128 Echoing by the tty
129 driver is always disabled, but initially \fBgetch\fR is in echo mode, so
130 characters typed are echoed.
131 Authors of most interactive programs prefer to do
132 their own echoing in a controlled area of the screen, or not to echo at all, so
133 they disable echoing by calling \fBnoecho\fR.
134 [See \fBcurs_getch\fR(3X) for a
135 discussion of how these routines interact with \fBcbreak\fR and
136 \fBnocbreak\fR.]
137 .\"
138 .SS halfdelay
139 .PP
140 The \fBhalfdelay\fR routine is used for half-delay mode, which is similar to
141 \fBcbreak\fR mode in that characters typed by the user are immediately
142 available to the program.
143 However, after blocking for \fItenths\fR tenths of
144 seconds, \fBERR\fP is returned if nothing has been typed.
145 The value of \fItenths\fR
146 must be a number between 1 and 255.
147 Use \fBnocbreak\fR to leave half-delay
148 mode.
149 .\"
150 .SS intrflush
151 .PP
152 If the \fBintrflush\fR option is enabled (\fIbf\fR is \fBTRUE\fR), and an
153 interrupt key is pressed on the keyboard (interrupt, break, quit), all output in
154 the tty driver queue will be flushed, giving the effect of faster response to
155 the interrupt, but causing \fBcurses\fR to have the wrong idea of what is on
156 the screen.
157 Disabling the option (\fIbf\fR is \fBFALSE\fR) prevents the
158 flush.
159 The default for the option is inherited from the tty driver settings.
160 The window argument is ignored.
161 .\"
162 .SS keypad
163 .PP
164 The \fBkeypad\fR option enables the keypad of the user's terminal.
165 If
166 enabled (\fIbf\fR is \fBTRUE\fR), the user can press a function key
167 (such as an arrow key) and \fBwgetch\fR(3X) returns a single value
168 representing the function key, as in \fBKEY_LEFT\fR.
169 If disabled
170 (\fIbf\fR is \fBFALSE\fR), \fBcurses\fR does not treat function keys
171 specially and the program has to interpret the escape sequences
172 itself.
173 If the keypad in the terminal can be turned on (made to
174 transmit) and off (made to work locally), turning on this option
175 causes the terminal keypad to be turned on when \fBwgetch\fR(3X) is
176 called.
177 The default value for keypad is \fBFALSE\fP.
178 .\"
179 .SS meta
180 .PP
181 Initially, whether the terminal returns 7 or 8 significant bits on
182 input depends on the control mode of the tty driver [see \fBtermios\fP(3)].
183 To force 8 bits to be returned, invoke \fBmeta\fR(\fIwin\fR,
184 \fBTRUE\fR); this is equivalent, under POSIX, to setting the CS8 flag
185 on the terminal.
186 To force 7 bits to be returned, invoke
187 \fBmeta\fR(\fIwin\fR, \fBFALSE\fR); this is equivalent, under POSIX,
188 to setting the CS7 flag on the terminal.
189 The window argument,
190 \fIwin\fR, is always ignored.
191 If the terminfo capabilities \fBsmm\fR
192 (meta_on) and \fBrmm\fR (meta_off) are defined for the terminal,
193 \fBsmm\fR is sent to the terminal when \fBmeta\fR(\fIwin\fR,
194 \fBTRUE\fR) is called and \fBrmm\fR is sent when \fBmeta\fR(\fIwin\fR,
195 \fBFALSE\fR) is called.
196 .\"
197 .SS nodelay
198 .PP
199 The \fBnodelay\fR option causes \fBgetch\fR to be a non-blocking call.
200 If no input is ready, \fBgetch\fR returns \fBERR\fR.
201 If disabled
202 (\fIbf\fR is \fBFALSE\fR), \fBgetch\fR waits until a key is pressed.
203 .PP
204 While interpreting an input escape sequence, \fBwgetch\fR(3X) sets a timer
205 while waiting for the next character.
206 If \fBnotimeout(\fR\fIwin\fR,
207 \fBTRUE\fR) is called, then \fBwgetch\fR does not set a timer.
208 The
209 purpose of the timeout is to differentiate between sequences received
210 from a function key and those typed by a user.
211 .\"
212 .SS raw/noraw
213 .PP
214 The \fBraw\fR and \fBnoraw\fR routines place the terminal into or out of raw
215 mode.
216 Raw mode is similar to \fBcbreak\fR mode, in that characters typed are
217 immediately passed through to the user program.
218 The differences are that in
219 raw mode, the interrupt, quit, suspend, and flow control characters are all
220 passed through uninterpreted, instead of generating a signal.
221 The behavior of
222 the BREAK key depends on other bits in the tty driver that are not set by
223 \fBcurses\fR.
224 .\"
225 .SS noqiflush
226 .PP
227 When the \fBnoqiflush\fR routine is used, normal flush of input and
228 output queues associated with the \fBINTR\fR, \fBQUIT\fR and
229 \fBSUSP\fR characters will not be done [see \fBtermios\fP(3)].
230 When
231 \fBqiflush\fR is called, the queues will be flushed when these control
232 characters are read.
233 You may want to call \fBnoqiflush\fR in a signal
234 handler if you want output to continue as though the interrupt
235 had not occurred, after the handler exits.
236 .\"
237 .SS timeout/wtimeout
238 .PP
239 The \fBtimeout\fR and \fBwtimeout\fR routines set blocking or
240 non-blocking read for a given window.
241 If \fIdelay\fR is negative,
242 blocking read is used (i.e., waits indefinitely for
243 input).
244 If \fIdelay\fR is zero, then non-blocking read is used
245 (i.e., read returns \fBERR\fR if no input is waiting).
246 If
247 \fIdelay\fR is positive, then read blocks for \fIdelay\fR
248 milliseconds, and returns \fBERR\fR if there is still no input.
249 Hence, these routines provide the same functionality as \fBnodelay\fR,
250 plus the additional capability of being able to block for only
251 \fIdelay\fR milliseconds (where \fIdelay\fR is positive).
252 .\"
253 .SS typeahead
254 .PP
255 The \fBcurses\fR library does \*(``line-breakout optimization\*(''
256 by looking for typeahead periodically while updating the screen.
257 If input is found, and it is coming from a tty,
258 the current update is postponed until
259 \fBrefresh\fR(3X) or \fBdoupdate\fR is called again.
260 This allows faster response to commands typed in advance.
261 Normally, the input FILE
262 pointer passed to \fBnewterm\fR, or \fBstdin\fR in the case that
263 \fBinitscr\fR was used, will be used to do this typeahead checking.
264 The \fBtypeahead\fR routine specifies that the file descriptor
265 \fIfd\fR is to be used to check for typeahead instead.
266 If \fIfd\fR is
267 \-1, then no typeahead checking is done.
268 .\"
269 .SH RETURN VALUE
270 All routines that return an integer return \fBERR\fR upon failure and \fBOK\fP
271 (SVr4 specifies only \*(``an integer value other than \fBERR\fR\*('')
272 upon successful completion,
273 unless otherwise noted in the preceding routine descriptions.
274 .PP
275 X/Open does not define any error conditions.
276 In this implementation,
277 functions with a window parameter will return an error if it is null.
278 Any function will also return an error if the terminal was not initialized.
279 Also,
280 .RS
281 .TP 5
282 \fBhalfdelay\fP
283 returns an error
284 if its parameter is outside the range 1..255.
285 .RE
286 .SH PORTABILITY
287 These functions are described in the XSI Curses standard, Issue 4.
288 .PP
289 The ncurses library obeys the XPG4 standard and the historical practice of the
290 AT&T curses implementations, in that the echo bit is cleared when curses
291 initializes the terminal state.
292 BSD curses differed from this slightly; it
293 left the echo bit on at initialization, but the BSD \fBraw\fR call turned it
294 off as a side-effect.
295 For best portability, set echo or noecho explicitly
296 just after initialization, even if your program remains in cooked mode.
297 .PP
298 When \fBkeypad\fP is first enabled,
299 ncurses loads the key-definitions for the current terminal description.
300 If the terminal description includes extended string capabilities,
301 e.g., from using the \fB\-x\fP option of \fB@TIC@\fP,
302 then ncurses also defines keys for the capabilities whose names
303 begin with \*(``k\*(''.
304 The corresponding keycodes are generated and (depending on previous
305 loads of terminal descriptions) may differ from one execution of a
306 program to the next.
307 The generated keycodes are recognized by the \fBkeyname\fP function
308 (which will then return a name beginning with \*(``k\*('' denoting the
309 terminfo capability name rather than \*(``K\*('', used for curses key-names).
310 On the other hand, an application can use \fBdefine_key\fP to establish
311 a specific keycode for a given string.
312 This makes it possible for an application to check for an extended
313 capability's presence with \fBtigetstr\fP,
314 and reassign the keycode to match its own needs.
315 .PP
316 Low-level applications can use \fBtigetstr\fP to obtain the definition
317 of any particular string capability.
318 Higher-level applications which use the curses \fBwgetch\fP
319 and similar functions to return keycodes rely upon the order in which
320 the strings are loaded.
321 If more than one key definition has the same string value,
322 then \fBwgetch\fP can return only one keycode.
323 Most curses implementations (including ncurses)
324 load key definitions in the order
325 defined by the array of string capability names.
326 The last key to be loaded determines the keycode which will be returned.
327 In ncurses, you may also have extended capabilities interpreted as
328 key definitions.
329 These are loaded after the predefined keys,
330 and if a capability's value is the same as a previously-loaded
331 key definition,
332 the later definition is the one used.
333 .SH NOTES
334 Note that \fBecho\fR, \fBnoecho\fR, \fBhalfdelay\fR, \fBintrflush\fR,
335 \fBmeta\fR, \fBnodelay\fR, \fBnotimeout\fR, \fBnoqiflush\fR,
336 \fBqiflush\fR, \fBtimeout\fR, and \fBwtimeout\fR may be macros.
337 .PP
338 The \fBnoraw\fR and \fBnocbreak\fR calls follow historical practice in that
339 they attempt to restore to normal (\*(``cooked\*('') mode
340 from raw and cbreak modes respectively.
341 Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver
342 control states that are hard to predict or understand; it is not recommended.
343 .SH SEE ALSO
344 \fBcurses\fR(3X),
345 \fBcurs_getch\fR(3X),
346 \fBcurs_initscr\fR(3X),
347 \fBcurs_util\fR(3X),
348 \fBdefine_key\fR(3X),
349 \fBtermios\fR(3)