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