$OpenBSD: curs_inopts.3,v 1.9 2023/10/17 09:52:08 nicm Exp $
***************************************************************************
Copyright 2018-2022,2023 Thomas E. Dickey *
Copyright 1998-2016,2017 Free Software Foundation, Inc. *
*
Permission is hereby granted, free of charge, to any person obtaining a *
copy of this software and associated documentation files (the *
"Software"), to deal in the Software without restriction, including *
without limitation the rights to use, copy, modify, merge, publish, *
distribute, distribute with modifications, sublicense, and/or sell *
copies of the Software, and to permit persons to whom the Software is *
furnished to do so, subject to the following conditions: *
*
The above copyright notice and this permission notice shall be included *
in all copies or substantial portions of the Software. *
*
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
*
Except as contained in this notice, the name(s) of the above copyright *
holders shall not be used in advertising or otherwise to promote the *
sale, use or other dealings in this Software without prior written *
authorization. *
***************************************************************************
$Id: curs_inopts.3,v 1.9 2023/10/17 09:52:08 nicm Exp $
int cbreak(void);
int nocbreak(void); int echo(void);
int noecho(void); int intrflush(WINDOW *win, bool bf);
int keypad(WINDOW *win, bool bf);
int meta(WINDOW *win, bool bf);
int nodelay(WINDOW *win, bool bf);
int notimeout(WINDOW *win, bool bf); int nl(void);
int nonl(void); int raw(void);
int noraw(void); void qiflush(void);
void noqiflush(void); int halfdelay(int tenths);
void timeout(int delay);
void wtimeout(WINDOW *win, int delay); int typeahead(int fd); /* extensions */
int is_cbreak(void);
int is_echo(void);
int is_nl(void);
int is_raw(void);
Normally, the tty driver buffers typed characters until a newline or carriage return is typed. The cbreak routine disables line buffering and erase/kill character-processing (interrupt and flow control characters are unaffected), making characters typed by the user immediately available to the program. The nocbreak routine returns the terminal to normal (cooked) mode.
Initially the terminal may or may not be in cbreak mode, as the mode is
inherited; therefore, a program should call cbreak or nocbreak
explicitly.
Most interactive programs using curses set the cbreak
mode.
Note that cbreak overrides raw.
[See curs_getch(3) for a
discussion of how these routines interact with echo and noecho.]
The nl and nonl routines control whether the underlying display device translates the return key into newline on input.
The raw and noraw routines place the terminal into or out of raw mode. Raw mode is similar to cbreak mode, in that characters typed are immediately passed through to the user program. The differences are that in raw mode, the interrupt, quit, suspend, and flow control characters are all passed through uninterpreted, instead of generating a signal. The behavior of the BREAK key depends on other bits in the tty driver that are not set by curses.
When the noqiflush routine is used, normal flush of input and output queues associated with the INTR, QUIT and SUSP characters will not be done [see termios(3)]. When qiflush is called, the queues will be flushed when these control characters are read. You may want to call noqiflush in a signal handler if you want output to continue as though the interrupt had not occurred, after the handler exits.
The timeout and wtimeout routines set blocking or non-blocking read for a given window. If delay is negative, blocking read is used (i.e., waits indefinitely for input). If delay is zero, then non-blocking read is used (i.e., read returns ERR if no input is waiting). If delay is positive, then read blocks for delay milliseconds, and returns ERR if there is still no input. Hence, these routines provide the same functionality as nodelay, plus the additional capability of being able to block for only delay milliseconds (where delay is positive).
X/Open does not define any error conditions. In this implementation, functions with a window parameter will return an error if it is null. Any function will also return an error if the terminal was not initialized. Also,
5 halfdelay returns an error if its parameter is outside the range 1..255.
Query Set Reset |
is_cbreak cbreak nocbreak |
is_echo echo noecho |
is_nl nl nonl |
is_raw raw noraw |
In each case, the function returns
5 1 if the flag is set,
5 0 if the flag is reset, or
5 -1 if the curses library was not initialized.
These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations. It is recommended that any code depending on ncurses extensions be conditioned using NCURSES_VERSION.
The ncurses library obeys the XPG4 standard and the historical practice of the AT&T curses implementations, in that the echo bit is cleared when curses initializes the terminal state. BSD curses differed from this slightly; it left the echo bit on at initialization, but the BSD raw call turned it off as a side-effect. For best portability, set echo or noecho explicitly just after initialization, even if your program remains in cooked mode.
The XSI Curses standard is ambiguous on the question of whether raw should disable the CRLF translations controlled by nl and nonl. BSD curses did turn off these translations; AT&T curses (at least as late as SVr1) did not. We chose to do so, on the theory that a programmer requesting raw input wants a clean (ideally 8-bit clean) connection that the operating system will not alter.
When keypad is first enabled, ncurses loads the key-definitions for the current terminal description. If the terminal description includes extended string capabilities, e.g., from using the -x option of tic, then ncurses also defines keys for the capabilities whose names begin with \*(``k\*(''. The corresponding keycodes are generated and (depending on previous loads of terminal descriptions) may differ from one execution of a program to the next. The generated keycodes are recognized by the keyname function (which will then return a name beginning with \*(``k\*('' denoting the terminfo capability name rather than \*(``K\*('', used for curses key-names). On the other hand, an application can use define_key to establish a specific keycode for a given string. This makes it possible for an application to check for an extended capability's presence with tigetstr, and reassign the keycode to match its own needs.
Low-level applications can use tigetstr to obtain the definition of any particular string capability. Higher-level applications which use the curses wgetch and similar functions to return keycodes rely upon the order in which the strings are loaded. If more than one key definition has the same string value, then wgetch can return only one keycode. Most curses implementations (including ncurses) load key definitions in the order defined by the array of string capability names. The last key to be loaded determines the keycode which will be returned. In ncurses, you may also have extended capabilities interpreted as key definitions. These are loaded after the predefined keys, and if a capability's value is the same as a previously-loaded key definition, the later definition is the one used.
The noraw and nocbreak calls follow historical practice in that they attempt to restore to normal (\*(``cooked\*('') mode from raw and cbreak modes respectively. Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver control states that are hard to predict or understand; it is not recommended.