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