^[control-codes live in libghostty-vt

C0 control characters

ESC Escape

Begin an escape sequence, abandoning any sequence already in progress.

ESC
ECMA-48
§8.3.48 ESC – Escape, p. 43
DEC STD 070
§3.5.1.2.3 Escape, p. 3-19
VT510
4.2 Control Characters

ESC begins an escape sequence: it “causes the meanings of a limited number of bit combinations following it in the data stream to be changed”, in ECMA-48’s words, which leaves the rules for what may follow to ECMA-35. Every multi-byte sequence on this site starts with it, including the control sequences, whose introducer CSI is written ESC [ in a 7-bit stream.

An ESC that arrives while a sequence is still in progress abandons that sequence and starts a new one. DEC STD 070 says “the sequence is canceled and a new sequence begins with that ESC”, and the VT510 manual (§4.3.5) that ESC can be sent “to cancel a sequence in progress and begin a new sequence”. Unlike CAN and SUB, the ESC is not lost: it is the start of whatever comes next.

xterm’s parser table sends ESC to CASE_ESC in the ground state as it does in the middle of a sequence.

Validation

ESC-1: Abandons a control sequence, and starts another

A
\e[3      # CUF, unfinished
\e[2;1H   # a new CUP
X
|A____|
|X____|

ESC-2: Abandons an escape sequence

\e#       # DECALN, unfinished
\e[2;2H
X
|_____|
|_X___|