]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_inopts.3x
ncurses 6.2 - patch 20210306
[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.33 2020/12/05 19:38:18 Benno.Schulenberg 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 \fBnl\fR,
48 \fBnonl\fR,
49 \fBnodelay\fR,
50 \fBnotimeout\fR,
51 \fBraw\fR,
52 \fBnoraw\fR,
53 \fBqiflush\fR,
54 \fBnoqiflush\fR,
55 \fBtimeout\fR,
56 \fBwtimeout\fR,
57 \fBtypeahead\fR \- \fBcurses\fR input options
58 .ad
59 .hy
60 .SH SYNOPSIS
61 \fB#include <curses.h>\fR
62 .PP
63 \fBint cbreak(void);\fR
64 .br
65 \fBint nocbreak(void);\fR
66 .sp
67 \fBint echo(void);\fR
68 .br
69 \fBint noecho(void);\fR
70 .sp
71 \fBint intrflush(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
72 .br
73 \fBint keypad(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
74 .br
75 \fBint meta(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
76 .br
77 \fBint nodelay(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
78 .br
79 \fBint notimeout(WINDOW *\fP\fIwin\fP\fB, bool \fP\fIbf\fP\fB);\fR
80 .sp
81 \fBint nl(void);\fR
82 .br
83 \fBint nonl(void);\fR
84 .sp
85 \fBint raw(void);\fR
86 .br
87 \fBint noraw(void);\fR
88 .sp
89 \fBvoid qiflush(void);\fR
90 .br
91 \fBvoid noqiflush(void);\fR
92 .sp
93 \fBint halfdelay(int \fP\fItenths\fP\fB);\fR
94 .br
95 \fBvoid timeout(int \fP\fIdelay\fP\fB);\fR
96 .br
97 \fBvoid wtimeout(WINDOW *\fP\fIwin\fP\fB, int \fP\fIdelay\fP\fB);\fR
98 .sp
99 \fBint typeahead(int \fP\fIfd\fP\fB);\fR
100 .br
101 .SH DESCRIPTION
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
107 windows.
108 An application must apply these to each window, if the same behavior
109 is needed.
110 .\"
111 .SS cbreak/nocbreak
112 Normally, the tty driver buffers typed characters until a newline or carriage
113 return is typed.
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
117 program.
118 The \fBnocbreak\fR routine returns the terminal to normal (cooked)
119 mode.
120 .PP
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
123 explicitly.
124 Most interactive programs using \fBcurses\fR set the \fBcbreak\fR
125 mode.
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.]
129 .\"
130 .SS echo/noecho
131 .PP
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.
134 Echoing by the tty
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
142 \fBnocbreak\fR.]
143 .\"
144 .SS halfdelay
145 .PP
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
154 mode.
155 .\"
156 .SS intrflush
157 .PP
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
162 the screen.
163 Disabling the option (\fIbf\fR is \fBFALSE\fR) prevents the
164 flush.
165 The default for the option is inherited from the tty driver settings.
166 The window argument is ignored.
167 .\"
168 .SS keypad
169 .PP
170 The \fBkeypad\fR option enables the keypad of the user's terminal.
171 If
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.
175 If disabled
176 (\fIbf\fR is \fBFALSE\fR), \fBcurses\fR does not treat function keys
177 specially and the program has to interpret the escape sequences
178 itself.
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
182 called.
183 The default value for keypad is \fBFALSE\fP.
184 .\"
185 .SS meta
186 .PP
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
191 on the terminal.
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.
195 The window argument,
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.
202 .\"
203 .SS nl/nonl
204 .PP
205 The \fBnl\fR and \fBnonl\fR routines control whether the underlying display
206 device translates the return key into newline on input.
207 .\"
208 .SS nodelay
209 .PP
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.
212 If disabled
213 (\fIbf\fR is \fBFALSE\fR), \fBgetch\fR waits until a key is pressed.
214 .SS notimeout
215 .PP
216 When interpreting an escape sequence, \fBwgetch\fR(3X) sets a timer
217 while waiting for the next character.
218 If \fBnotimeout(\fR\fIwin\fR,
219 \fBTRUE\fR) is called, then \fBwgetch\fR does not set a timer.
220 The
221 purpose of the timeout is to differentiate between sequences received
222 from a function key and those typed by a user.
223 .\"
224 .SS raw/noraw
225 .PP
226 The \fBraw\fR and \fBnoraw\fR routines place the terminal into or out of raw
227 mode.
228 Raw mode is similar to \fBcbreak\fR mode, in that characters typed are
229 immediately passed through to the user program.
230 The differences are that in
231 raw mode, the interrupt, quit, suspend, and flow control characters are all
232 passed through uninterpreted, instead of generating a signal.
233 The behavior of
234 the BREAK key depends on other bits in the tty driver that are not set by
235 \fBcurses\fR.
236 .\"
237 .SS qiflush/noqiflush
238 .PP
239 When the \fBnoqiflush\fR routine is used, normal flush of input and
240 output queues associated with the \fBINTR\fR, \fBQUIT\fR and
241 \fBSUSP\fR characters will not be done [see \fBtermios\fP(3)].
242 When
243 \fBqiflush\fR is called, the queues will be flushed when these control
244 characters are read.
245 You may want to call \fBnoqiflush\fR in a signal
246 handler if you want output to continue as though the interrupt
247 had not occurred, after the handler exits.
248 .\"
249 .SS timeout/wtimeout
250 .PP
251 The \fBtimeout\fR and \fBwtimeout\fR routines set blocking or
252 non-blocking read for a given window.
253 If \fIdelay\fR is negative,
254 blocking read is used (i.e., waits indefinitely for
255 input).
256 If \fIdelay\fR is zero, then non-blocking read is used
257 (i.e., read returns \fBERR\fR if no input is waiting).
258 If
259 \fIdelay\fR is positive, then read blocks for \fIdelay\fR
260 milliseconds, and returns \fBERR\fR if there is still no input.
261 Hence, these routines provide the same functionality as \fBnodelay\fR,
262 plus the additional capability of being able to block for only
263 \fIdelay\fR milliseconds (where \fIdelay\fR is positive).
264 .\"
265 .SS typeahead
266 .PP
267 The \fBcurses\fR library does \*(``line-breakout optimization\*(''
268 by looking for typeahead periodically while updating the screen.
269 If input is found, and it is coming from a tty,
270 the current update is postponed until
271 \fBrefresh\fR(3X) or \fBdoupdate\fR is called again.
272 This allows faster response to commands typed in advance.
273 Normally, the input FILE
274 pointer passed to \fBnewterm\fR, or \fBstdin\fR in the case that
275 \fBinitscr\fR was used, will be used to do this typeahead checking.
276 The \fBtypeahead\fR routine specifies that the file descriptor
277 \fIfd\fR is to be used to check for typeahead instead.
278 If \fIfd\fR is
279 \-1, then no typeahead checking is done.
280 .\"
281 .SH RETURN VALUE
282 All routines that return an integer return \fBERR\fR upon failure and \fBOK\fP
283 (SVr4 specifies only \*(``an integer value other than \fBERR\fR\*('')
284 upon successful completion,
285 unless otherwise noted in the preceding routine descriptions.
286 .PP
287 X/Open does not define any error conditions.
288 In this implementation,
289 functions with a window parameter will return an error if it is null.
290 Any function will also return an error if the terminal was not initialized.
291 Also,
292 .RS
293 .TP 5
294 \fBhalfdelay\fP
295 returns an error
296 if its parameter is outside the range 1..255.
297 .RE
298 .SH PORTABILITY
299 These functions are described in the XSI Curses standard, Issue 4.
300 .PP
301 The ncurses library obeys the XPG4 standard and the historical practice of the
302 AT&T curses implementations, in that the echo bit is cleared when curses
303 initializes the terminal state.
304 BSD curses differed from this slightly; it
305 left the echo bit on at initialization, but the BSD \fBraw\fR call turned it
306 off as a side-effect.
307 For best portability, set \fBecho \fPor \fBnoecho\fP explicitly
308 just after initialization, even if your program remains in cooked mode.
309 .PP
310 The XSI Curses standard is ambiguous on the question of whether \fBraw\fR
311 should disable the CRLF translations controlled by \fBnl\fR and \fBnonl\fR.
312 BSD curses did turn off these translations; AT&T curses (at least as late as
313 SVr1) did not.
314 We chose to do so, on the theory that a programmer requesting
315 raw input wants a clean (ideally 8-bit clean) connection that the operating
316 system will not alter.
317 .PP
318 When \fBkeypad\fP is first enabled,
319 ncurses loads the key-definitions for the current terminal description.
320 If the terminal description includes extended string capabilities,
321 e.g., from using the \fB\-x\fP option of \fB@TIC@\fP,
322 then ncurses also defines keys for the capabilities whose names
323 begin with \*(``k\*(''.
324 The corresponding keycodes are generated and (depending on previous
325 loads of terminal descriptions) may differ from one execution of a
326 program to the next.
327 The generated keycodes are recognized by the \fBkeyname\fP function
328 (which will then return a name beginning with \*(``k\*('' denoting the
329 terminfo capability name rather than \*(``K\*('', used for curses key-names).
330 On the other hand, an application can use \fBdefine_key\fP to establish
331 a specific keycode for a given string.
332 This makes it possible for an application to check for an extended
333 capability's presence with \fBtigetstr\fP,
334 and reassign the keycode to match its own needs.
335 .PP
336 Low-level applications can use \fBtigetstr\fP to obtain the definition
337 of any particular string capability.
338 Higher-level applications which use the curses \fBwgetch\fP
339 and similar functions to return keycodes rely upon the order in which
340 the strings are loaded.
341 If more than one key definition has the same string value,
342 then \fBwgetch\fP can return only one keycode.
343 Most curses implementations (including ncurses)
344 load key definitions in the order
345 defined by the array of string capability names.
346 The last key to be loaded determines the keycode which will be returned.
347 In ncurses, you may also have extended capabilities interpreted as
348 key definitions.
349 These are loaded after the predefined keys,
350 and if a capability's value is the same as a previously-loaded
351 key definition,
352 the later definition is the one used.
353 .SH NOTES
354 Note that
355 \fBecho\fR,
356 \fBnoecho\fR,
357 \fBhalfdelay\fR,
358 \fBintrflush\fR,
359 \fBmeta\fR,
360 \fBnl\fR,
361 \fBnonl\fR,
362 \fBnodelay\fR,
363 \fBnotimeout\fR,
364 \fBnoqiflush\fR,
365 \fBqiflush\fR,
366 \fBtimeout\fR, and
367 \fBwtimeout\fR may be macros.
368 .PP
369 The \fBnoraw\fR and \fBnocbreak\fR calls follow historical practice in that
370 they attempt to restore to normal (\*(``cooked\*('') mode
371 from raw and cbreak modes respectively.
372 Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver
373 control states that are hard to predict or understand; it is not recommended.
374 .SH SEE ALSO
375 \fBcurses\fR(3X),
376 \fBcurs_getch\fR(3X),
377 \fBcurs_initscr\fR(3X),
378 \fBcurs_util\fR(3X),
379 \fBdefine_key\fR(3X),
380 \fBtermios\fR(3)