Terminal Operating Modes

Terminal behavior varies based on a set of configurable terminal parameters. There are five classes of terminal parameters,

  • Control Characters

  • Input Modes

  • Output Modes

  • Control Modes

  • Local Modes

The input, output, and control mode settings are fairly irrelevant in a modern terminal interface. We will discuss just a handful of relevant control characters and local mode settings, which you will want to be familiar with, below.

Local Modes

Local modes control the local behavior of the terminal; i.e. what the user sees, and what the terminal does with input before sending it to applications. Many applications change these settings, and they are relevant to your use of an interactive terminal. There are three that are particularly important:

ECHO

If set, input characters are visually printed to the terminal. Commonly turned off to capture and process input without displaying it to the screen, such as when entering passwords, or in an interactive application.

ICANON

Controls whether the terminal is in canonical mode or non-canonical mode. In canonical mode, input is buffered into units of lines, and applications can read up to the end of a line in a single read operation. In non-canonical mode, input is available for reading immediately as soon as it is entered. This is called a terminal’s line discipline.

ISIG

Controls whether the signal control characters send signals or not.

IXON/IXOFF

Controls whether flow control is enabled. Flow control allows input or output to be temporarily frozen so that users can stop and read fast moving output, among other things.

The terminal is usually switched between two modes, called “raw” and “cooked”. In raw mode, these flags are disabled, along with some other settings. In cooked mode, all of these flags are enabled. When entering input into the command line, your terminal is in cooked mode; when working inside an interactive text editor like vim, your terminal is in raw mode and the text editor is processing your input on a character-by-character basis.

Control Characters

Control characters are a set of specially recognized characters; listed below are their names, default values, and description. You should be familiar with these characters in order to properly use a terminal interface.

Input characters which generate signals

These characters are relevant when signal mode (ISIG) is turned on.

INTR <ctrl-c>

A SIGINT (interrupt) signal is sent to the foreground process group.

QUIT <ctrl-\>

A SIGQUIT (quit) signal is sent to the foreground process group.

SUSP (ctrl-z)

A SIGTSTP (terminal stop) signal is sent to the foreground process group.

Input characters which control the line buffer

These characters are relevant when canonical mode (ICANON) is turned on.

ERASE <backspace>

Erases the previous character in the line buffer up to most recent NL, EOF, or EOL character.

KILL <ctrl-u>

Erases the entire line buffer up to the most recent NL, EOF, or EOL character.

EOF <ctrl-d>

All waiting bytes in the line buffer are immediately passed to the application without waiting for a <newline>. If there are no bytes waiting, this causes the application to read zero bytes, which represents end-of-file.

NL <newline>

This is the line delimiter <newline>. It causes the current line to be available to the application for reading. It cannot be changed.

EOL

This is a secondary custom line delimiter character. Usually unset.

Flow control characters

These characters are relevant when flow control (IXON/IXOFF) is turned on.

STOP (ctrl-s)

Suspends output temporarily (freezes the terminal). Used to prevent output from disappearing before it can be read. Unwary programmers often freeze their terminals when pressing ctrl-s to instinctively save an open text file. Input and output is buffered while the terminal is frozen, not lost.

START (ctrl-q)

Resume output (unfreezes the terminal). You’ll want to remember this one.

Terminal Demonstration

You can explore how the “cooked” vs “raw” setting, as well as how the “echo” flag affects the behavior of a terminal. The below example shows what is displayed to the user, what is sent to the program, and the contents of the line buffer as input is entered.

Note

Some browsers intercept certain control keys. Manual buttons are provided to simulate control-key events.