2 .\"***************************************************************************
3 .\" Copyright 2018-2023,2024 Thomas E. Dickey *
4 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc. *
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: *
14 .\" The above copyright notice and this permission notice shall be included *
15 .\" in all copies or substantial portions of the Software. *
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. *
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 *
29 .\"***************************************************************************
31 .\" $Id: curs_inopts.3x,v 1.70 2024/06/01 22:28:41 tom Exp $
32 .TH curs_inopts 3X 2024-06-01 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
72 get and set \fIcurses\fR terminal input options
75 \fB#include <curses.h>
78 \fBint nocbreak(void);
83 \fBint intrflush(WINDOW * \fIwin\fP \fI/* ignored */\fP, bool \fIbf\fP);
84 \fBint keypad(WINDOW * \fIwin\fP, bool \fIbf\fP);
85 \fBint meta(WINDOW * \fIwin\fP \fI/* ignored */\fP, bool \fIbf\fP);
86 \fBint nodelay(WINDOW * \fIwin\fP, bool \fIbf\fP);
87 \fBint notimeout(WINDOW * \fIwin\fP, bool \fIbf\fP);
92 \fBvoid qiflush(void);
93 \fBvoid noqiflush(void);
98 \fBint halfdelay(int \fItenths\fP);
99 \fBvoid timeout(int \fIdelay\fP);
100 \fBvoid wtimeout(WINDOW * \fIwin\fP, int \fIdelay\fP);
102 \fBint typeahead(int \fIfd\fP);
105 \fBint is_cbreak(void);
106 \fBint is_echo(void);
112 offers configurable parameters permitting an application to control the
113 handling of input from the terminal.
115 applying to all windows;
116 others apply only to a specific window.
117 The library does not automatically apply such parameters to new or
119 an application must configure each window for the desired behavior.
121 Some descriptions below make reference to an
122 .IR "input character reading function" ":"
123 this is \fB\%wgetch\fP(3X) in the non-wide character
125 API and \fB\%wget_wch\fP(3X) in the wide character API.
126 In addition to the variant forms of these described in
130 functions \fB\%wgetstr\fP(3X) and \fB\%wget_wstr\fP(3X) and their own
131 variants call the appropriate input character reading function.
133 .SS "cbreak, nocbreak"
135 the terminal driver buffers typed characters,
136 not delivering them to an application
137 until a line feed or carriage return is typed.
139 configures the terminal in
140 .IR "cbreak mode" ","
141 which disables line buffering
142 and erase and kill character processing
146 and flow control characters are unaffected)
147 and makes characters typed by the user immediately available to the
150 returns the terminal to normal (\*(``cooked\*('') mode.
152 The state of the terminal is unknown to a
154 application when it starts;
156 a program should call
161 Most interactive programs using
169 The man page for the input character reading function
183 determine whether characters typed by the user are written to the
185 window by the input character reading function as they are typed.
187 always disables the terminal driver's own echoing.
191 window has its echo flag set.
192 Authors of most interactive programs prefer
193 to do their own echoing in a controlled area of the screen,
194 or not to echo at all,
197 The man page for the input character reading function
210 .IR "half-delay mode" ","
211 which is similar to \%cbreak mode in that characters typed by the user
212 are immediately available to the program.
217 an input character reading function returns
219 if no input is pending.
222 must be between 1 and 255.
225 to leave half-delay mode.
248 enables recognition of a terminal's function keys.
254 the input character reading function returns a value representing
258 (Wide-character API users:
259 \fB\%wget_wch\fP(3X) returns
261 to indicate the availability of a function key code in its
269 does not treat function keys specially and the program has to interpret
270 escape sequences itself.
271 If the terminal's keypad can be turned on
274 (made to work locally),
276 configures it consistently with the
280 a window's keypad mode is off.
284 whether the terminal returns 7- or 8-bit character codes on input
285 depends on the configuration of the terminal driver;
286 see \fI\%termios\fP(3).
287 To force 8 bits to be returned,
293 to setting the CS8 flag on the terminal.
294 To force 7 bits to be returned,
300 to setting the CS7 flag on the terminal.
312 are defined for the terminal type,
313 enabling meta mode sends
315 to the terminal and disabling it sends
321 whether the terminal reports a carriage return
322 using the character code for a line feed
323 depends on the configuration of the terminal driver;
324 see \fI\%termios\fP(3).
326 configures the terminal to perform this translation.
332 configures the input character reading function to be non-blocking for
335 If no input is ready,
336 the reading function returns
342 the reading function does not return until it has input.
344 When the input character reading function reads an ESC character,
345 it sets a timer while waiting for the next character.
346 .BI \%notimeout( win ,
349 The purpose of the timeout is to distinguish sequences produced by a
350 function key from those typed by a user.
351 To configure the timeout rather than disabling it,
356 .SS "qiflush, noqiflush"
361 configure the terminal driver's treatment of its input and output queues
362 when it handles the interrupt,
364 or quit characters in
366 and \*(``cooked\*('' modes;
368 see \fI\%termios\fP(3).
369 The default behavior is inherited from the terminal driver settings.
372 configures the terminal to flush the queues when any of these events
374 giving the impression of faster response to user input,
375 but making the library's model of the screen contents incorrect.
378 prevents such flushing,
379 but might frustrate impatient users on slow connections if a
381 update of the screen is in progress when the event occurs;
384 below for a mitigation of this problem.
388 if you want output to continue
389 after the handler exits
390 as though the interrupt had not occurred.
394 configures the terminal to read input in
396 which is similar to cbreak mode
400 except that it furthermore passes through the terminal's configured
404 and flow control characters
405 uninterpreted to the application,
406 instead of generating a signal or acting on I/O flow.
407 The behavior of the terminal's \*(``Break\*('' key
409 depends on terminal driver configuration parameters that
413 returns the terminal to normal (\*(``cooked\*('') mode.
415 .SS "timeout, wtimeout"
419 input character reading function called on window
421 uses blocking or non-blocking reads.
425 a blocking read is used,
426 waiting indefinitely for input.
430 a non-blocking read is used;
431 an input character reading function returns
433 if no input is pending.
437 an input character reading function
443 if the delay elapses and there is still no input pending.
454 library checks the terminal for input while updating the screen.
456 the update is postponed until the next \fB\%wrefresh\fP(3X) or
457 \fB\%doupdate\fP(3X) call,
458 allowing faster response to user key strokes.
459 The library tests the file descriptor corresponding to the
461 stream pointer passed to \fB\%newterm\fP(3X)
464 if \fB\%initscr\fP(3X) was called),
469 to test file descriptor
508 the functions in the previous paragraph return
512 the terminal is not initialized or
521 which ignore its value).
529 is outside the range 1..255.
531 See section \*(``EXTENSIONS\*('' below for the
553 may be implemented as macros.
558 follow historical practice in that they attempt to restore normal
559 (\*(``cooked\*('') mode from raw and cbreak modes,
564 .BR cbreak / \%nocbreak
565 calls leads to terminal driver control states that are hard to predict
567 doing so is not recommended.
570 provides four \*(``is_\*('' functions corresponding to
576 permitting their states to be queried by the application.
584 is_cbreak cbreak nocbreak
592 .TP 5 \" "-1" + 2n tag separation + 1n fudge for typesetters like grops
597 if the flag is reset,
601 if the library is not initialized.
603 Applications employing
605 extensions should condition their use on the visibility of the
609 Except as noted in section \*(``EXTENSIONS\*('' above,
611 Issue 4 describes these functions.
612 It specifies no error conditions for them.
616 describes a successful return value only as
617 \*(``an integer value other than
621 follows X/Open Curses
622 and the historical practice of System\ V
624 clearing the terminal driver's \*(``echo\*('' flag when initializing the
631 function turned it off as a side effect.
632 .\" SGTTY's sg_flags had a "RAW" symbol; termio in SVr1 for the PDP-11
634 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4BSD/usr/include/curses.h
635 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/sysv-pdp11_man/a_man/man7/termio.7
636 For best portability,
641 explicitly just after initialization,
642 even if your program remains in normal (\*(``cooked\*('') mode.
644 X/Open Curses is ambiguous regarding whether
646 should disable the carriage return and line feed translation feature
653 did turn off these translations;
659 on the assumption that a programmer requesting raw input wants a clean
662 connection that the operating system will not alter.
668 loads the key definitions for the current terminal description.
669 If the terminal description includes extended string capabilities,
673 option of \fB\%@TIC@\fP(1),
676 also defines keys for the capabilities whose names begin with
678 Corresponding key codes are generated and
679 (depending on previous loads of terminal descriptions)
680 may differ from one execution of a program to the next.
681 The generated key codes are recognized by \fB\%keyname\fP(3X),
682 which then returns a name beginning with \*(``k\*('' denoting the
684 capability name rather than \*(``K\*('',
689 an application can use \fB\%define_key\fP(3X) to bind
690 a specific key to a string of the programmer's choice.
691 This feature enables an application to check for its presence
692 with \fB\%tigetstr\fP(3X),
693 and reassign the key code to match its own needs.
695 Low-level applications can use \fB\%tigetstr\fP(3X) to obtain the
696 definition of any string capability.
698 applications use the input character reading function
699 to obtain key codes from input
700 and rely upon the order in which the string capabilities are loaded.
701 Multiple key capability strings can have the same value,
702 but the input character reading function can report only one key code.
708 load key definitions in the order
711 array of string capability names;
712 see \fB\%term_variables\fP(3X).
713 .\" ncurses/tinfo/parse_entry.c:lookup_fullname, I think --GBR
714 The last capability read using a particular definition determines the
715 key code to be reported.
718 extended capabilities can be interpreted as key definitions.
719 These are loaded after the predefined keys,
720 and if a capability's value is the same as a previously loaded
722 the later definition is the one used.
734 .IR \%noraw "." \" also crmod and nocrmod, never standardized
736 SVr2 (1984) featured a new terminal driver,
739 API to support it with
758 appeared in SVr3.1 (1987),
761 became a wrapper for either of these functions,
762 depending on the value of its Boolean argument.
767 6.5 (2024) introduced
780 to control the conversion of newlines to carriage return/line feed
781 on output as well as input.
782 X/Open Curses documents the use of these functions only for input.
783 This difference arose from converting the
787 \fI\%ioctl\fP(2) calls and the
792 (the POSIX terminal API).
794 both input and output were controlled via a single option
796 while the latter separates these features.
797 Because that conversion interferes with output optimization,
803 to eliminate their effect on output.
806 \fB\%curs_getch\fP(3X),
807 \fB\%curs_initscr\fP(3X),
808 \fB\%curs_util\fP(3X),
809 \fB\%define_key\fP(3X),
810 \fB\%term_variables\fP(3X),