http://invisible-island.net/xterm/FAQ
An extract from ECMA-48 by Thomas E. Dickey

ECMA-48: 5.4 Control sequences


5.4 Control sequences

A control sequence is a string of bit combinations starting with the control function CONTROL SEQUENCE INTRODUCER (CSI) followed by one or more bit combinations representing parameters, if any, and by one or more bit combinations identifying the control function. The control function CSI itself is an element of the C1 set.

The format of a control sequence is

CSI P ... P I ... I F

where

  1. CSI is represented by bit combinations 01/11 (representing ESC) and 05/11 in a 7-bit code or by bit combination 09/11 in an 8-bit code, see 5.3;

  2. P ... P are Parameter Bytes, which, if present, consist of bit combinations from 03/00 to 03/15;

  3. I ... I are Intermediate Bytes, which, if present, consist of bit combinations from 02/00 to 02/15. Together with the Final Byte F, they identify the control function;

    NOTE

    The number of Intermediate Bytes is not limited by this Standard; in practice, one Intermediate Byte will be sufficient since with sixteen different bit combinations available for the Intermediate Byte over one thousand control functions may be identified.

  4. F is the Final Byte; it consists of a bit combination from 04/00 to 07/14; it terminates the control sequence and together with the Intermediate Bytes, if present, identifies the control function. Bit combinations 07/00 to 07/14 are available as Final Bytes of control sequences for private (or experimental) use.

    The definitions and the coded representations of the control functions are specified in 8.3 (see also tables 3 and 4). Coding examples are shown in B.1 in annex B.

The unallocated bit combinations are reserved for future standardization and shall not be used. See also F.8.3 in annex F.

5.4.1 Parameter representation

A control sequence may contain a string of Parameter Bytes P ... P representing one or more parameters to complete the specification of the control function.

The Parameter Bytes are bit combinations from 03/00 to 03/15. The parameter string is interpreted as follows:

  1. If the first bit combination of the parameter string is in the range 03/00 to 03/11, the parameter string is interpreted according to the format described in 5.4.2.

  2. If the first bit combination of the parameter string is in the range 03/12 to 03/15, the parameter string is available for private (or experimental) use. Its format and meaning are not defined by this Standard.

5.4.2 Parameter string format

A parameter string which does not start with a bit combination in the range 03/12 to 03/15 shall have the following format:

  1. A parameter string consists of one or more parameter sub-strings, each of which represents a number in decimal notation.

  2. Each parameter sub-string consists of one or more bit combinations from 03/00 to 03/10; the bit combinations from 03/00 to 03/09 represent the digits ZERO to NINE; bit combination 03/10 may be used as a separator in a parameter sub-string, for example, to separate the fractional part of a decimal number from the integer part of that number.

  3. Parameter sub-strings are separated by one bit combination 03/11.

  4. Bit combinations 03/12 to 03/15 are reserved for future standardization except when used as the first bit combination of the parameter string.

  5. An empty parameter sub-string represents a default value which depends on the control function.

  6. In each parameter sub-string, leading bit combinations 03/00 are not significant and may be omitted. If the parameter sub-string consists of bit combinations 03/00 only, at least one of them must be retained to indicate the zero value of the sub-string.

  7. If the parameter string starts with the bit combination 03/11, an empty parameter sub-string is assumed preceding the separator; if the parameter string terminates with the bit combination 03/11, an empty parameter sub-string is assumed following the separator; if the parameter string contains successive bit combinations 03/11, empty parameter sub-strings are assumed between the separators.

  8. If the control function has more than one parameter, and some parameter sub-strings are empty, the separators (bit combination 03/11) must still be present. However, if the last parameter sub-string(s) is empty, the separator preceding it may be omitted, see B.2 in annex B.

5.4.3 Types of parameters

In a control sequence with parameters, each parameter sub-string corresponds to one parameter and represents the value of that parameter. The number of parameters is either fixed or variable, depending on the control function. If the number of parameters is variable, neither the maximum number of values nor the order in which the corresponding actions are performed are defined by this Standard.

A parameter may be purely numeric or it may be selective, i.e. denoting one of a numbered list of actions the control function can perform.

In the case of selected parameters a particular parameter value may have the same meaning as a combination of two or more separate values.

Unassigned selective parameter values are reserved for future standardization.