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