inopts(3NCURSES)
π NAME π
cbreak, echo, halfdelay, intrflush, is_cbreak, is_echo, is_nl, is_raw, keypad, meta, nl, nocbreak, nodelay, noecho, nonl, noqiflush, noraw, notimeout, qiflush, raw, timeout, wtimeout, typeahead β aka every single little knob that gets and sets ur curses terminal input options. this is inopts(3NCURSES), the library calls page, and bestie we are going THROUGH it. π
β¨ SYNOPSIS β¨
#include <curses.h>
int cbreak(void);
int nocbreak(void);
int echo(void);
int noecho(void);
int intrflush(WINDOW * win /* ignored */, bool bf);
int keypad(WINDOW * win, bool bf);
int meta(WINDOW * win /* ignored */, bool bf);
int nodelay(WINDOW * win, bool bf);
int notimeout(WINDOW * win, bool bf);
int nl(void);
int nonl(void);
void qiflush(void);
void noqiflush(void);
int raw(void);
int noraw(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);
π DESCRIPTION π
okay so curses hands u a whole lil control panel ποΈ β configurable parameters that let ur application decide how input from the terminal gets handled. some of these (the ones messing with the terminal's mode or its line discipline) are global, like they apply to every single window, periodt. others are per-window only. and here's the part people fumble: the library does not automatically apply these parameters to new or derived windows. ur app has to configure each window for the behavior it wants. no shortcuts, bestie. π
some of the descriptions below reference an input character reading function β that's wgetch(3NCURSES) in the non-wide character curses API, and wget_wch(3NCURSES) in the wide character API. and btw, on top of the variant forms of those described in ncurses(3NCURSES), the curses functions wgetstr(3NCURSES) and wget_wstr(3NCURSES) and their own variants also call the appropriate input character reading function. so like, it's them. they're the ones reading. π«Ά
πΈ cbreak, nocbreak πΈ
so normally the terminal driver is out here buffering everything u type and refusing to hand it over to ur application until u hit a line feed or a carriage return. rude, honestly. this canonical ("cooked") line discipline is also the thing supporting software flow control, the simple line editing stuff (character and word erase, plus whole-line erasure aka "kill"), and job control.
cbreak flips the terminal into cbreak mode, which disables line buffering and the erase and kill character processing β but heads up, the interrupt, quit, suspend, and flow control characters are unaffected by this β and it makes characters typed by the user immediately available to the program. iconic behavior honestly. β¨
nocbreak puts u back in canonical ("cooked") mode. the safe, cozy, buffered mode.
when a curses application starts up, the state of the terminal is unknown to it. so a program should callcbreakornocbreakexplicitly. don't assume, bestie!!
most interactive programs using curses set cbreak mode. and note: calling cbreak overrides raw. also, the man page for the input character reading function is where u go to read about how cbreak and nocbreak interact with echo and noecho. π
π echo, noecho π
echo and noecho decide whether characters typed by the user get written to the curses window by the input character reading function as they're typed. and fun fact: curses always disables the terminal driver's own echoing. always. it does its own thing. π
by default, a curses screen's echo option is set. but the authors of most interactive programs would rather do their own echoing in a controlled area of the screen, or not echo at all β so they call noecho. and again, the man page for the input character reading function covers how echo and noecho interact with cbreak and nocbreak. π¦
β³ halfdelay β³
halfdelay sets up half-delay mode, which is like cbreak mode's cooler cousin: characters typed by the user are still immediately available to the program. but β after blocking for tenths tenth-seconds, an input character reading function returns ERR if no input is pending. β
the value of tenths must be between 1 and 255. and when u want out of half-delay mode, call nocbreak. that's the exit door. πͺ
π₯ intrflush π₯
intrflush calls qiflush (see below, babes) if bf is TRUE, and noqiflush if bf is FALSE. and it ignores its win argument. like literally does not care about it. π
π keypad π
keypad enables recognition of a terminal's function keys. here's the tea:
- if enabled (bf is
TRUE), then when an input character reading function readsESC, it waits for further input corresponding to an escape sequence defined by the terminal type description. - if a valid sequence populates the input stream, the input character reading function returns a value representing the function key, such as
KEY_LEFT. (wide-character API users:wget_wch(3NCURSES)returnsKEY_CODE_YESto indicate the availability of a function key code in its wch parameter. iykyk π) - if the sequence is invalid, the input character reading function returns only its last character.
- if disabled (bf is
FALSE), curses does not treat function keys specially and the program has to interpret escape sequences itself. good luck with that bestie π«‘
also: if the terminal type description defines the keypad_local (rmkx) and keypad_xmit (smkx) capabilities, enabling a window's keypad mode sets the terminal's keypad to transmit, and disabling keypad mode sets the terminal's keypad to work locally.
by default, a window's keypad mode is off. π
π meta π
initially, whether the terminal returns 7- or 8-bit character codes on input depends on the configuration of the terminal driver β on POSIX systems, go peek at termios(3). π
- to force 8 bits to be returned, call
meta(..., TRUE); on POSIX systems this is equivalent to setting theCS8flag on the terminal. - to force 7 bits to be returned, call
meta(..., FALSE); on POSIX systems this is equivalent to setting theCS7flag on the terminal.
curses ignores the window argument win. not its business. π
and if the terminfo string capabilities meta_on (smm) and meta_off (rmm) are defined for the terminal type, enabling meta mode sends smm's value to the terminal, and disabling it sends that of rmm to the terminal. β¨
π nl, nonl π
initially, whether the terminal reports a carriage return using the character code for a line feed in cbreak or raw modes depends on the configuration of the terminal driver; see termios(3). π§
nlconfigures the terminal to perform this translation.nonldisables it.
and important: under its canonical ("cooked") line discipline, the terminal driver always translates carriage returns to line feeds. always always. no negotiating. π
π nodelay π
nodelay configures the input character reading function to be non-blocking for window win. if no input is ready, the reading function returns ERR. it said "not today." π€
if disabled (bf is FALSE), the reading function does not return until it has input. it will simply wait. forever. patiently. π°οΈ
π§ notimeout π§
when keypad has been called on a window and the input character reading function reads an ESC character from it, curses sets a timer while waiting for the next character. if the timer elapses, curses interprets the ESC as an explicit press of the terminal's Escape key (or equivalent).
notimeout(win, TRUE) disables this timer. the whole purpose of the timeout is to distinguish sequences produced by a function key from those typed by a user. π
and if this timer is disabled, curses waits forever for subsequent keystrokes until it determines the escape sequence to be valid or invalid. forever forever. main character patience. π
π qiflush, noqiflush π
qiflush and noqiflush configure the terminal driver's treatment of its input and output queues when it handles the interrupt, suspend, or quit characters under the canonical ("cooked") or cbreak line disciplines on POSIX systems; see termios(3). the default behavior is inherited from the terminal driver settings.
calling qiflush configures the terminal to flush the queues (discarding their contents) when any of these events occurs β which gives the impression of faster response to user input, but makes the library's model of the screen contents incorrect. π
calling noqiflush prevents such flushing, but might frustrate impatient users on slow connections if a curses update of the screen is in progress when the event occurs; see typeahead below for a mitigation of this problem. π«Ά
and a lil pro tip from the page itself: you may want to call noqiflush in a signal handler if, after the handler exits, you want output to continue as though the signal had not occurred. β
π₯ raw, noraw π₯
raw configures the terminal to read input in raw mode, which is similar to cbreak mode (see cbreak above) except that it furthermore passes through the terminal's configured interrupt, quit, suspend, and flow control characters uninterpreted to the application, instead of generating a signal or acting on I/O flow. it's giving unfiltered. π
the behavior of the terminal's "Break" key (if any) depends on terminal driver configuration parameters that curses does not handle. not our problem, not our department. π
noraw restores the terminal's canonical ("cooked") line discipline. π
β±οΈ timeout, wtimeout β±οΈ
wtimeout configures whether a curses input character reading function called on window win uses blocking or non-blocking reads:
- if delay is negative, curses uses a blocking read, waiting indefinitely for input. π
- if delay is zero, the read is non-blocking; an input character reading function returns
ERRif no input is pending. β‘ - if delay is positive, an input character reading function blocks for delay milliseconds, and returns
ERRif the delay elapses and there is still no input pending. β³
timeout calls wtimeout on stdscr. that's it, that's the whole relationship. π
π typeahead π
normally, a curses library checks the terminal's input file descriptor for activity with poll(2) or select(2) while updating the screen; if it finds any, it postpones output until the next wrefresh(3NCURSES) or doupdate(3NCURSES) call, allowing faster response to user key strokes. β¨
the library tests the file descriptor corresponding to the FILE stream pointer passed to newterm(3NCURSES) (or stdin if initscr(3NCURSES) was called), for pending input.
typeahead instructs curses to test file descriptor fd instead. and an fd of -1 disables the check entirely. bye bye check. π
π RETURN VALUE π
timeout and wtimeout return no value. they're above returning things, honestly. π
cbreak, nocbreak, echo, noecho, halfdelay, intrflush, keypad, meta, nodelay, notimeout, nl, nonl, raw, noraw, and typeahead return OK on success and ERR on failure. β
in ncurses, the functions in the previous paragraph return ERR if
- the library's
TERMINALstructure for the device has not been initialized withinitscr(3NCURSES),newterm(3NCURSES), orsetupterm(3NCURSES), or - win is a null pointer (except with
intrflushandmeta, which ignore its value). π
further, halfdelay returns ERR if delay is outside the range 1..255. π¨
and see section "EXTENSIONS" below for the return values of is_cbreak, is_echo, is_nl, and is_raw. π
π NOTES π
okay bestie, first thing's first β some of these are lowkey just macros in disguise. echo, noecho, halfdelay, intrflush, meta, nl, nonl, nodelay, notimeout, noqiflush, qiflush, timeout, and wtimeout may be implemented as macros. so like, don't try anything cute with function pointers, mkay? π
so noraw and nocbreak are out here following historical practice β they attempt to restore the terminal's canonical ("cooked") line discipline from raw and cbreak, respectively. cute, right?
but mixingraw/norawcalls withcbreak/nocbreakcalls leads to terminal driver control states that are hard to predict or understand. doing so is not recommended. that's a "bestie please don't" from me, fr fr. π
okay so this is the part where curses docs kinda set you up to be confused, and I need you to know that. π’
curses documentation uses the terms "delay" and "timeout" freely to describe two related but distinct aspects of input handling, at the risk of confusing the user. (that's you. you're the user. hi. π«Ά)
so here's the tea:
halfdelay,nodelay,timeout, andwtimeoutconfigure whether the input character reading function (wgetch(3NCURSES)orwget_wch(3NCURSES)) waits for keyboard input to begin, and for how long. β¨keypadconfigures whether that function waits for further input if the first character it reads is ESC. π- calling
notimeoutβ which has nothing to do withtimeoutorwtimeout, the naming is genuinely a crime β makes this delay in expectation of further characters effectively infinite. π - X/Open Curses affords no means of otherwise configuring the length of this second delay. but! an AIX and ncurses extension,
ESCDELAY, is available both as an environment variable and a global symbol, permitting the user and application, respectively, to do so; seencurses(3NCURSES)andcurses_variables(3NCURSES). she's giving options, she's giving flexibility π
β¨ EXTENSIONS β¨
ncurses provides four is_ functions corresponding to cbreak, echo, nl, and raw, permitting their states to be queried by the application. so you can ask instead of just yolo-ing a state change. iconic behaviour, honestly.
is_cbreakβ queries the state thatcbreaksets andnocbreakresets.is_echoβ queries the state thatechosets andnoechoresets.is_nlβ queries the state thatnlsets andnonlresets.is_rawβ queries the state thatrawsets andnorawresets.
and in each case, the function returns:
1β if the option is set,0β if the option is unset, or-1β if the library'sTERMINALstructure for the device has not been initialized.
π PORTABILITY π
applications employing ncurses extensions should condition their use on the visibility of the NCURSES_VERSION preprocessor macro. that's the vibe check before you use the exclusive stuff, bestie. π
except as noted in section "EXTENSIONS" above, X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. (bold of it.)
SVr4 describes a successful return value only as "an integer value other than ERR". that's the whole description. incredible. no notes. π
okay this next bit matters, so pay attention:
ncurses follows X/Open Curses and the historical practice of System V curses, clearing the terminal driver's "echo" flag when initializing the screen. BSD curses did not, but its raw function turned it off as a side effect.
so for best portability, callechoornoechoexplicitly just after initialization, even if your program retains the terminal's canonical ("cooked") line discipline. don't leave it up to fate, she's unreliable. π
X/Open Curses is ambiguous regarding whether raw should disable the carriage return and line feed translation feature controlled by nl and nonl.
- BSD curses turned off these translations.
- System V curses did not.
- ncurses does do so, on the assumption that a programmer requesting raw input wants a clean (ideally, 8-bit clean) connection that the operating system will not alter. slay, honestly. π
when keypad is first enabled for a window, ncurses loads the standard function key string capabilities for the terminal type description of its screen; see the entries beginning with "key_" in terminfo(5).
if that description includes extended string capabilities, produced by the -x option of tic(1), for example, then ncurses also defines keys for the capabilities whose codes begin with "k". ncurses generates a numeric key code for each such extended capability; depending on previous loads of terminal type descriptions, these may differ from one execution of a program to the next. (yes, that's chaotic. yes, that's on purpose-ish.)
keyname(3NCURSES)recognizes the generated key codes and returns a name beginning with "k" denoting theterminfocapability name rather than "KEY_", used for curses key names.- on the other hand, an application can use
define_key(3NCURSES)to bind a selected key to a string of the programmer's choice. this feature enables an application to check for its presence withtigetstr(3NCURSES), and reassign the numeric key code to match its own needs. main character energy: define your own keys. π
low-level applications can use tigetstr(3NCURSES) to obtain the definition of any string capability.
curses applications use the input character reading function to obtain key codes from input and rely upon the order in which the string capabilities are loaded. multiple key capability strings can have the same value, but the input character reading function can report only one key code. π
most curses implementations (including ncurses) load key definitions in the order they appear in the strfnames array of string capability names; see terminfo_variables(3NCURSES). the last capability read using a particular definition determines the key code to be reported.
in ncurses, extended capabilities can be interpreted as key definitions. the library loads these after its built-in definitions, and if an extended capability's value is the same as one previously loaded, the library uses the later definition. last one wins, periodt. π¦
π HISTORY π
- 4BSD (1980) introduced
echo,noecho,nl,nonl,raw, andnoraw. the OGs. π«Ά - SVr2 (1984) featured a new terminal driver, extending the curses API to support it with
cbreak,nocbreak,intrflush,keypad,meta,nodelay, andtypeahead. - SVr3 (1987) added
halfdelay,notimeout, andwtimeout.qiflushandnoqiflushappeared in SVr3.1 (1987), at which pointintrflushbecame a wrapper for either of these functions, depending on the value of its Boolean argument. SVr3.1 also addedtimeout. glow up after glow up β¨ - ncurses 6.5 (2024) introduced
is_cbreak,is_echo,is_nl, andis_raw. the new girls. π
and here's a lil lore drop for you, because it's genuinely interesting:
Formerly, ncurses used nl and nonl to control the conversion of newlines to carriage return/line feed on output as well as input. X/Open Curses documents the use of these functions only for input.
this difference arose from converting the pcurses source (1986), which used ioctl(2) calls and the sgttyb structure, to termios (the POSIX terminal API). in the former, both input and output conversions were controlled via a single option "CRMOD", while the latter separates these features. because that conversion interferes with output optimization, ncurses 6.2 (2020) amended nl and nonl to eliminate their effect on output. character development arc complete. π¦
πΈ SEE ALSO πΈ
ncurses(3NCURSES)getch(3NCURSES)initscr(3NCURSES)util(3NCURSES)define_key(3NCURSES)termios(3)terminfo_variables(3NCURSES)
okay that's the whole page bestie, you made it, I'm so proud of you π«Ά this one's from ncurses 6.6, dated 2025-10-04, and it lives at inopts(3NCURSES) β go forth and configure your input options with confidence, you absolute icon πβ¨
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2016,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms