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