^[control-codes live in libghostty-vt

Control sequences

CUP Cursor Position

Move the cursor to a given line and column.

CSI Pl ; Pc H
Defaults
Pl = 1, Pc = 1
ECMA-48
§8.3.21 CUP – Cursor Position, p. 36
DEC STD 070
§5.4.4 Cursor Position, p. 5-49
VT510
CUP—Cursor Position

Move the cursor to line Pl, column Pc, both counting from 1. Either can be left out, and so can both: CSI H is the top-left corner. A 0 is taken as 1.

A position past the edge of the screen is clamped to it, so CSI 999 ; 999 H is a common way of reaching the bottom-right corner without knowing the size of the screen.

With origin mode (CSI ? 6 h, DECOM) on, the position counts from the top and left margins instead of the screen’s corner, and is clamped to the margins rather than to the screen.

Moving the cursor cancels any pending wrap, as DEC STD 070 asks (§D.6.1, p. D-13) and xterm’s CursorSet does. CSI Pl ; Pc f (HVP) does the same thing as CUP.

Validation

CUP-1: To a position

\e[2;3H
X
|_____|
|__X__|
|_____|

CUP-2: Defaults

\e[3;3H
\e[H      # both left out
A
\e[2H     # column left out
B
\e[;4H    # line left out
C
|A__C_|
|B____|
|_____|

CUP-3: Clamped to the screen

\e[999;999H
X
|_____|
|_____|
|____X|
cursor 3,5
pending-wrap yes

CUP-4: With origin mode

\e[2;3r   # region is lines 2 and 3
\e[?6h    # origin mode
\e[1;1H   # the top of the region
A
\e[9;1H   # clamped to the bottom of the region
B
|_____|
|A____|
|B____|
|_____|