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