]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_inopts.3x
ncurses 6.4 - patch 20230917
[ncurses.git] / man / curs_inopts.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2022,2023 Thomas E. Dickey                                *
4 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
5 .\"                                                                          *
6 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
7 .\" copy of this software and associated documentation files (the            *
8 .\" "Software"), to deal in the Software without restriction, including      *
9 .\" without limitation the rights to use, copy, modify, merge, publish,      *
10 .\" distribute, distribute with modifications, sublicense, and/or sell       *
11 .\" copies of the Software, and to permit persons to whom the Software is    *
12 .\" furnished to do so, subject to the following conditions:                 *
13 .\"                                                                          *
14 .\" The above copyright notice and this permission notice shall be included  *
15 .\" in all copies or substantial portions of the Software.                   *
16 .\"                                                                          *
17 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24 .\"                                                                          *
25 .\" Except as contained in this notice, the name(s) of the above copyright   *
26 .\" holders shall not be used in advertising or otherwise to promote the     *
27 .\" sale, use or other dealings in this Software without prior written       *
28 .\" authorization.                                                           *
29 .\"***************************************************************************
30 .\"
31 .\" $Id: curs_inopts.3x,v 1.47 2023/09/16 23:37:03 tom Exp $
32 .TH curs_inopts 3X 2023-09-16 "ncurses 6.4" "Library calls"
33 .ie \n(.g .ds `` \(lq
34 .el       .ds `` ``
35 .ie \n(.g .ds '' \(rq
36 .el       .ds '' ''
37 .SH NAME
38 \fB\%cbreak\fP,
39 \fB\%echo\fP,
40 \fB\%halfdelay\fP,
41 \fB\%intrflush\fP,
42 \fB\%is_cbreak\fP,
43 \fB\%is_echo\fP,
44 \fB\%is_nl\fP,
45 \fB\%is_raw\fP,
46 \fB\%keypad\fP,
47 \fB\%meta\fP,
48 \fB\%nl\fP,
49 \fB\%nocbreak\fP,
50 \fB\%nodelay\fP,
51 \fB\%noecho\fP,
52 \fB\%nonl\fP,
53 \fB\%noqiflush\fP,
54 \fB\%noraw\fP,
55 \fB\%notimeout\fP,
56 \fB\%qiflush\fP,
57 \fB\%raw\fP,
58 \fB\%timeout\fP,
59 \fB\%wtimeout\fP,
60 \fB\%typeahead\fP \-
61 get and set \fIcurses\fR terminal input options
62 .SH SYNOPSIS
63 \fB#include <curses.h>\fP
64 .PP
65 \fBint cbreak(void);\fP
66 .br
67 \fBint nocbreak(void);\fP
68 .sp
69 \fBint echo(void);\fP
70 .br
71 \fBint noecho(void);\fP
72 .sp
73 \fBint intrflush(WINDOW *\fIwin\fB, bool \fIbf\fB);\fR
74 .br
75 \fBint keypad(WINDOW *\fIwin\fB, bool \fIbf\fB);\fR
76 .br
77 \fBint meta(WINDOW *\fIwin\fB, bool \fIbf\fB);\fR
78 .br
79 \fBint nodelay(WINDOW *\fIwin\fB, bool \fIbf\fB);\fR
80 .br
81 \fBint notimeout(WINDOW *\fIwin\fB, bool \fIbf\fB);\fR
82 .sp
83 \fBint nl(void);\fP
84 .br
85 \fBint nonl(void);\fP
86 .sp
87 \fBint raw(void);\fP
88 .br
89 \fBint noraw(void);\fP
90 .sp
91 \fBvoid qiflush(void);\fP
92 .br
93 \fBvoid noqiflush(void);\fP
94 .sp
95 \fBint halfdelay(int \fItenths\fB);\fR
96 .br
97 \fBvoid timeout(int \fIdelay\fB);\fR
98 .br
99 \fBvoid wtimeout(WINDOW *\fIwin\fB, int \fIdelay\fB);\fR
100 .sp
101 \fBint typeahead(int \fIfd\fB);\fR
102 .sp
103 /* extensions */
104 .br
105 \fBint is_cbreak(void);\fP
106 .br
107 \fBint is_echo(void);\fP
108 .br
109 \fBint is_nl(void);\fP
110 .br
111 \fBint is_raw(void);\fP
112 .br
113 .SH DESCRIPTION
114 The \fBncurses\fP library provides several functions which let an application
115 change the way input from the terminal is handled.
116 Some are global, applying to all windows.
117 Others apply only to a specific window.
118 Window-specific settings are not automatically applied to new or derived
119 windows.
120 An application must apply these to each window, if the same behavior
121 is needed.
122 .\"
123 .SS cbreak/nocbreak
124 Normally, the tty driver buffers typed characters until a newline or carriage
125 return is typed.
126 The \fBcbreak\fP routine disables line buffering and
127 erase/kill character-processing (interrupt and flow control characters are
128 unaffected), making characters typed by the user immediately available to the
129 program.
130 The \fBnocbreak\fP routine returns the terminal to normal (cooked)
131 mode.
132 .PP
133 Initially the terminal may or may not be in \fBcbreak\fP mode, as the mode is
134 inherited; therefore, a program should call \fBcbreak\fP or \fBnocbreak\fP
135 explicitly.
136 Most interactive programs using \fBcurses\fP set the \fBcbreak\fP
137 mode.
138 Note that \fBcbreak\fP overrides \fBraw\fP.
139 [See \fBcurs_getch\fP(3X) for a
140 discussion of how these routines interact with \fBecho\fP and \fBnoecho\fP.]
141 .\"
142 .SS echo/noecho
143 The \fBecho\fP and \fBnoecho\fP routines control whether characters typed by
144 the user are echoed by \fBgetch\fP(3X) as they are typed.
145 Echoing by the tty
146 driver is always disabled, but initially \fBgetch\fP is in echo mode, so
147 characters typed are echoed.
148 Authors of most interactive programs prefer to do
149 their own echoing in a controlled area of the screen, or not to echo at all, so
150 they disable echoing by calling \fBnoecho\fP.
151 [See \fBcurs_getch\fP(3X) for a
152 discussion of how these routines interact with \fBcbreak\fP and
153 \fBnocbreak\fP.]
154 .\"
155 .SS halfdelay
156 The \fBhalfdelay\fP routine is used for half-delay mode, which is similar to
157 \fBcbreak\fP mode in that characters typed by the user are immediately
158 available to the program.
159 However, after blocking for \fItenths\fP tenths of
160 seconds, \fBERR\fP is returned if nothing has been typed.
161 The value of \fItenths\fP
162 must be a number between 1 and 255.
163 Use \fBnocbreak\fP to leave half-delay
164 mode.
165 .\"
166 .SS intrflush
167 If the \fBintrflush\fP option is enabled (\fIbf\fP is \fBTRUE\fP), and an
168 interrupt key is pressed on the keyboard (interrupt, break, quit), all output in
169 the tty driver queue will be flushed, giving the effect of faster response to
170 the interrupt, but causing \fBcurses\fP to have the wrong idea of what is on
171 the screen.
172 Disabling the option (\fIbf\fP is \fBFALSE\fP) prevents the
173 flush.
174 The default for the option is inherited from the tty driver settings.
175 The window argument is ignored.
176 .\"
177 .SS keypad
178 The \fBkeypad\fP option enables the keypad of the user's terminal.
179 If
180 enabled (\fIbf\fP is \fBTRUE\fP), the user can press a function key
181 (such as an arrow key) and \fBwgetch\fP(3X) returns a single value
182 representing the function key, as in \fBKEY_LEFT\fP.
183 If disabled
184 (\fIbf\fP is \fBFALSE\fP), \fBcurses\fP does not treat function keys
185 specially and the program has to interpret the escape sequences
186 itself.
187 If the keypad in the terminal can be turned on (made to
188 transmit) and off (made to work locally), turning on this option
189 causes the terminal keypad to be turned on when \fBwgetch\fP(3X) is
190 called.
191 The default value for keypad is \fBFALSE\fP.
192 .\"
193 .SS meta
194 Initially, whether the terminal returns 7 or 8 significant bits on
195 input depends on the control mode of the tty driver [see \fBtermios\fP(3)].
196 To force 8 bits to be returned, invoke \fBmeta\fP(\fIwin\fP,
197 \fBTRUE\fP); this is equivalent, under POSIX, to setting the CS8 flag
198 on the terminal.
199 To force 7 bits to be returned, invoke
200 \fBmeta\fP(\fIwin\fP, \fBFALSE\fP); this is equivalent, under POSIX,
201 to setting the CS7 flag on the terminal.
202 The window argument,
203 \fIwin\fP, is always ignored.
204 If the terminfo capabilities \fBsmm\fP
205 (meta_on) and \fBrmm\fP (meta_off) are defined for the terminal,
206 \fBsmm\fP is sent to the terminal when \fBmeta\fP(\fIwin\fP,
207 \fBTRUE\fP) is called and \fBrmm\fP is sent when \fBmeta\fP(\fIwin\fP,
208 \fBFALSE\fP) is called.
209 .\"
210 .SS nl/nonl
211 The \fBnl\fP and \fBnonl\fP routines control whether the underlying display
212 device translates the return key into newline on input.
213 .\"
214 .SS nodelay
215 The \fBnodelay\fP option causes \fBgetch\fP to be a non-blocking call.
216 If no input is ready, \fBgetch\fP returns \fBERR\fP.
217 If disabled
218 (\fIbf\fP is \fBFALSE\fP), \fBgetch\fP waits until a key is pressed.
219 .SS notimeout
220 When interpreting an escape sequence, \fBwgetch\fP(3X) sets a timer
221 while waiting for the next character.
222 If \fBnotimeout(\fIwin\fR,
223 \fBTRUE\fP) is called, then \fBwgetch\fP does not set a timer.
224 The
225 purpose of the timeout is to differentiate between sequences received
226 from a function key and those typed by a user.
227 .\"
228 .SS raw/noraw
229 The \fBraw\fP and \fBnoraw\fP routines place the terminal into or out of raw
230 mode.
231 Raw mode is similar to \fBcbreak\fP mode, in that characters typed are
232 immediately passed through to the user program.
233 The differences are that in
234 raw mode, the interrupt, quit, suspend, and flow control characters are all
235 passed through uninterpreted, instead of generating a signal.
236 The behavior of
237 the BREAK key depends on other bits in the tty driver that are not set by
238 \fBcurses\fP.
239 .\"
240 .SS qiflush/noqiflush
241 When the \fBnoqiflush\fP routine is used, normal flush of input and
242 output queues associated with the \fBINTR\fP, \fBQUIT\fP and
243 \fBSUSP\fP characters will not be done [see \fBtermios\fP(3)].
244 When
245 \fBqiflush\fP is called, the queues will be flushed when these control
246 characters are read.
247 You may want to call \fBnoqiflush\fP in a signal
248 handler if you want output to continue as though the interrupt
249 had not occurred, after the handler exits.
250 .\"
251 .SS timeout/wtimeout
252 The \fBtimeout\fP and \fBwtimeout\fP routines set blocking or
253 non-blocking read for a given window.
254 If \fIdelay\fP is negative,
255 blocking read is used (i.e., waits indefinitely for
256 input).
257 If \fIdelay\fP is zero, then non-blocking read is used
258 (i.e., read returns \fBERR\fP if no input is waiting).
259 If
260 \fIdelay\fP is positive, then read blocks for \fIdelay\fP
261 milliseconds, and returns \fBERR\fP if there is still no input.
262 Hence, these routines provide the same functionality as \fBnodelay\fP,
263 plus the additional capability of being able to block for only
264 \fIdelay\fP milliseconds (where \fIdelay\fP is positive).
265 .\"
266 .SS typeahead
267 The \fBcurses\fP 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\fP(3X) or \fBdoupdate\fP is called again.
272 This allows faster response to commands typed in advance.
273 Normally, the input FILE
274 pointer passed to \fBnewterm\fP, or \fBstdin\fP in the case that
275 \fBinitscr\fP was used, will be used to do this typeahead checking.
276 The \fBtypeahead\fP routine specifies that the file descriptor
277 \fIfd\fP is to be used to check for typeahead instead.
278 If \fIfd\fP is
279 \-1, then no typeahead checking is done.
280 .\"
281 .SH RETURN VALUE
282 All routines that return an integer return \fBERR\fP upon failure and \fBOK\fP
283 (SVr4 specifies only \*(``an integer value other than \fBERR\fP\*('')
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 3
293 .TP 5
294 \fBhalfdelay\fP
295 returns an error
296 if its parameter is outside the range 1..255.
297 .RE
298 .SH EXTENSIONS
299 This implementation provides four functions which may be used to detect
300 if the corresponding flags were set or reset:
301 .PP
302 .TS
303 l l l.
304 \fBQuery\fP     \fBSet\fP       \fBReset\fP
305 _
306 is_cbreak       cbreak  nocbreak
307 is_echo echo    noecho
308 is_nl   nl      nonl
309 is_raw  raw     noraw
310 .TE
311 .PP
312 In each case, the function returns
313 .TP 5
314 1
315 if the flag is set,
316 .TP 5
317 0
318 if the flag is reset, or
319 .TP 5
320 -1
321 if the curses library was not initialized.
322 .PP
323 These routines are specific to ncurses.
324 They were not supported on Version 7, BSD or System V implementations.
325 It is recommended that any code depending on ncurses extensions
326 be conditioned using NCURSES_VERSION.
327 .SH PORTABILITY
328 Except as noted in the section on extensions,
329 these functions are described in the XSI Curses standard, Issue 4.
330 .PP
331 The ncurses library obeys the XPG4 standard and the historical practice of the
332 AT&T curses implementations, in that the echo bit is cleared when curses
333 initializes the terminal state.
334 BSD curses differed from this slightly; it
335 left the echo bit on at initialization, but the BSD \fBraw\fP call turned it
336 off as a side-effect.
337 For best portability, set \fBecho \fPor \fBnoecho\fP explicitly
338 just after initialization, even if your program remains in cooked mode.
339 .PP
340 The XSI Curses standard is ambiguous on the question of whether \fBraw\fP
341 should disable the CRLF translations controlled by \fBnl\fP and \fBnonl\fP.
342 BSD curses did turn off these translations; AT&T curses (at least as late as
343 SVr1) did not.
344 We chose to do so, on the theory that a programmer requesting
345 raw input wants a clean (ideally 8-bit clean) connection that the operating
346 system will not alter.
347 .PP
348 When \fBkeypad\fP is first enabled,
349 ncurses loads the key-definitions for the current terminal description.
350 If the terminal description includes extended string capabilities,
351 e.g., from using the \fB\-x\fP option of \fB@TIC@\fP,
352 then ncurses also defines keys for the capabilities whose names
353 begin with \*(``k\*(''.
354 The corresponding keycodes are generated and (depending on previous
355 loads of terminal descriptions) may differ from one execution of a
356 program to the next.
357 The generated keycodes are recognized by the \fBkeyname\fP function
358 (which will then return a name beginning with \*(``k\*('' denoting the
359 terminfo capability name rather than \*(``K\*('', used for curses key-names).
360 On the other hand, an application can use \fBdefine_key\fP to establish
361 a specific keycode for a given string.
362 This makes it possible for an application to check for an extended
363 capability's presence with \fBtigetstr\fP,
364 and reassign the keycode to match its own needs.
365 .PP
366 Low-level applications can use \fBtigetstr\fP to obtain the definition
367 of any particular string capability.
368 Higher-level applications which use the curses \fBwgetch\fP
369 and similar functions to return keycodes rely upon the order in which
370 the strings are loaded.
371 If more than one key definition has the same string value,
372 then \fBwgetch\fP can return only one keycode.
373 Most curses implementations (including ncurses)
374 load key definitions in the order
375 defined by the array of string capability names.
376 The last key to be loaded determines the keycode which will be returned.
377 In ncurses, you may also have extended capabilities interpreted as
378 key definitions.
379 These are loaded after the predefined keys,
380 and if a capability's value is the same as a previously-loaded
381 key definition,
382 the later definition is the one used.
383 .SH NOTES
384 Note that
385 \fBecho\fP,
386 \fBnoecho\fP,
387 \fBhalfdelay\fP,
388 \fBintrflush\fP,
389 \fBmeta\fP,
390 \fBnl\fP,
391 \fBnonl\fP,
392 \fBnodelay\fP,
393 \fBnotimeout\fP,
394 \fBnoqiflush\fP,
395 \fBqiflush\fP,
396 \fBtimeout\fP, and
397 \fBwtimeout\fP may be macros.
398 .PP
399 The \fBnoraw\fP and \fBnocbreak\fP calls follow historical practice in that
400 they attempt to restore to normal (\*(``cooked\*('') mode
401 from raw and cbreak modes respectively.
402 Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver
403 control states that are hard to predict or understand; it is not recommended.
404 .SH SEE ALSO
405 \fBcurses\fP(3X),
406 \fBcurs_getch\fP(3X),
407 \fBcurs_initscr\fP(3X),
408 \fBcurs_util\fP(3X),
409 \fBdefine_key\fP(3X),
410 \fBtermios\fP(3)