curs_inopts: cbreak, nocbreak, echo, noecho, halfdelay, intrflush, keypad, meta, nodelay, notimeout, raw, noraw, noqiflush, qiflush, timeout, wtimeout, typeahead -- curses terminal input option control routines


cc ... -lcurses

#include <curses.h>

int cbreak(void); int nocbreak(void); int echo(void); int noecho(void); int halfdelay(int tenths); 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 raw(void); int noraw(void); void noqiflush(void); void qiflush(void); void timeout(int delay); void wtimeout(WINDOW *win, int delay); int typeahead(int fd);


cbreak and nocbreak

The routine cbreak(S) puts the terminal into cbreak mode and the routine nocbreak(S) takes the terminal out of cbreak mode.

In cbreak mode, characters typed by the user are immediately available to the program, and erase or kill characters are not processed.

When out of this mode, the tty driver buffers the typed characters until a newline or carriage return is typed.

Interrupt and flow control characters are not affected by the mode.

Initially the terminal can be in either mode, because the mode is inherited; therefore, a program should call cbreak( ) or nocbreak( ) explicitly. Most interactive programs using curses(S) set the cbreak mode.

cbreak( ) overrides raw(S). See curs_getch(S) for a discussion of how cbreak( ) and raw( ) interact with echo(S) and noecho(S).

echo and noecho

The routines echo( ) and noecho( ) control whether characters typed by the user are echoed by getch(S) as they are typed. Echoing by the tty driver is always disabled, but initially getch( ) is in echo mode and echoes each character. Authors of most interactive programs prefer to do their own echoing in a controlled area of the screen, or not to echo at all, so they call noecho( ). (See curs_getch(S) for a discussion of how echo( ) and noecho( ) interact with cbreak( ) and nocbreak( )).


The routine halfdelay(S) is used for half-delay mode, which is similar to cbreak mode in that characters typed by the user are immediately available to the program. However, after blocking for tenths tenths of a second, ERR is returned if nothing has been typed. tenths must be a number between 1 and 255. Use nocbreak( ) to leave half-delay mode.


If the intrflush option is enabled (bf is TRUE), when an interrupt key (interrupt, break, or quit) is pressed on the keyboard all output in the tty driver queue is flushed, giving a faster response to the interrupt, but confusing curses( ) about what is on the screen. Disabling the option (bf is FALSE), prevents the flush. The default for this option is inherited from the tty driver settings. The window argument is ignored.


The keypad option enables the keypad of the user's terminal. If it is enabled (bf is TRUE), the user can press a function key (such as an arrow key) and wgetch(S) returns a single value representing the function key, as in KEY_LEFT.

If keypad is disabled (bf is FALSE), curses( ) does not treat function keys specially and the program has to interpret the escape sequences itself.

If the keypad in the terminal can be turned on (made to transmit) and off (made to work locally), turning on this option turns on the terminal keypad when wgetch( ) is called.

The default value for keypad is FALSE.


Initially, whether the terminal returns 7 or 8 significant bits on input depends on the control mode of the tty driver (see termio(M)). To force 8 bits to be returned, invoke meta(win, TRUE). To force 7 bits to be returned, invoke meta(win, FALSE). The window argument, win, is always ignored. If the terminfo capabilities smm (meta_on) and rmm (meta_off) are defined for the terminal, smm is sent to the terminal when meta(win, TRUE) is called and rmm is sent when meta(win, FALSE) is called.


The nodelay option causes getch( ) to be a non-blocking call. If no input is ready, getch( ) returns ERR. If nodelay is disabled (bf is FALSE), getch( ) waits until a key is pressed.


While interpreting an input escape sequence, wgetch( ) sets a timer while waiting for the next character. If notimeout(win, TRUE) is called, then wgetch( ) does not set a timer. The timeout differentiates between sequences received from a function key and those typed by a user.

raw and noraw

The routines raw( ) and noraw(S) put the terminal into or out of raw mode. Raw mode is like cbreak mode, in that characters typed are immediately passed through to the user program. The differences are that in raw mode, characters for interrupt, quit, suspend, and flow control 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(S) routine is used, normal flush of input and output queues associated with the INTR, QUIT and SUSP characters is not done (see termio(M)).

When qiflush(S) is called, the queues are flushed when these control characters are read.

timeout and notimeout

The timeout(S) and wtimeout(S) routines set blocking or non-blocking read for a given window.

If delay is negative, blocking read is used (that is, read( ) waits indefinitely for input).

If delay is zero, then non-blocking read is used (that is, 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( ), as well as being able to block for only delay milliseconds.


curses( ) does ``line-breakout optimization'' by looking for typeahead periodically while updating the screen. If input is found, and it is coming from a tty, the current update is postponed until refresh(S) or doupdate(S) is called again. This allows faster response to commands typed in advance.

Normally, to do typeahead checking the input FILE pointer passed to newterm(S), is used, or stdin if initscr(S) was used. However, typeahead(S) uses the file descriptor fd instead, to do this checking. If fd is -1, no typeahead checking is done.

Return values

All routines that return an integer return ERR on failure and an integer value other than ERR on successful completion, unless otherwise noted in the preceding routine descriptions.


The header file curses.h automatically includes the header files stdio.h and unctrl.h.

The following can be macros: echo( ), noecho( ), halfdelay( ), intrflush( ), meta(S), nodelay( ), notimeout(S), noqiflush( ), qiflush( ), timeout( ), and wtimeout( ).


the library

See also

curses(S), curs_getch(S), curs_initscr(S), termio(M)

Standards conformance

cbreak(S), echo(S), halfdelay(S), intrflush(S), keypad(S), meta(S), nocbreak(S), nodelay(S), noecho(S), noraw(S), notimeout(S), raw(S), noqiflush(S), qiflush(S), timeout(S), wtimeout(S), and typeahead(S) are not part of any currently supported standard; they were developed by UNIX System Laboratories, Inc. and are maintained by The SCO Group.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003