Table of contents

Notes on Control Functions

ECMA-48 is the standard which defines control functions. They are in several types:

Control characters

Control characters are those in the ranges 0x00 to 0x1F (C0) and 0x80 to 0x9F (C1). The elements of the C1 set can also be represented by ESC (0x1B) followed by a byte in the range 0x40 to 0x5F.

Escape sequences

Escape sequences are defined by ECMA-35.

Escape sequences are introduced by ESC (0x1B).

After ESC come intermediate bytes which are in the range 0x20 to 0x2F (, !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /). They are optional.

Then come the final byte which is in the range 0x30 to 0x7E.

Control sequences

Control Sequences are introduced by CSI. CSI is a control function of the C1 set which can be represented by either 0x9B or 0x1B 0x5B (ESC [).

After CSI come the parameter bytes which are in the range 0x30 to 0x3F (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?). They are optional.

Then come intermediate bytes which are in the range 0x20 to 0x2F (, !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /). They are optional.

The comes the final byte which is in the range 0x40 to 0x7E.

The function of the control sequence is determined by the intermediate bytes and the final byte.

Independant control functions

Those are represented by ESC (0x1B) followed by a byte in the range 0x60 to 0x7E.

Control strings

There are five kinds of Control Strings. They are introduced by

Commands are followed by bytes in the range 0x08 to 0xB (BS, HT, LF, VT, FF, CR) or 0x20 to 0x7E and terminated by a ST (0x9C or 0x1B 0x5C - ESC \).

Strings are followed by sequence of any bytes excepted SOS (0x98 or 0x1B 0x58) or ST (0x9C or 0x1B 0x5C) and terminated by a ST (0x9C or 0x1B 0x5C).

According to XTerm Control Sequences PM is followed by a string.

Notes

XTerm Control Sequences documents the control sequences of XTerm; most terminal emulators are using a subset of these. Some of the functions have been standardized in ECMA-35 or ECMA-48, the other are compatible with the given structure and are placed in unassigned or reserved for private use. I’d not be surprised if a terminal emulator somewhere used a standardized function for something else that what the standards define, or use a badly formed sequence, but I’m not aware of any other than the palette setting for Linux console mentionned in XTerm Control Sequences.