^[control-codes
live in libghostty-vt

Control sequences

HVP Horizontal and Vertical Position

View as Markdown

Move the cursor to a given line and column, as CUP does.

CSI Pl ; Pc f
Defaults
Pl = 1, Pc = 1
ECMA-48
§8.3.63 HVP – Character and Line Position, p. 46
DEC STD 070
§5.4.4 Horizontal/Vertical Position, p. 5-51
VT220
§4.7 Cursor Positioning
VT510
HVP—Horizontal and Vertical Position

Move the cursor to line Pl, column Pc, exactly as CUP does: both count from 1, either can be left out, a 0 is taken as 1, a position past the edge is clamped to it, and with origin mode on the position counts from the margins.

The two exist side by side for a historical reason. In ECMA-48, HVP moves the data position while CUP moves the presentation position, a distinction that matters to a device where the two can differ. A terminal has only one cursor. DEC STD 070 defines HVP by calling CUP’s own algorithm, and keeps it only for compatibility with printing terminals, telling software to use CUP instead. The VT510 manual says the same.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Yes§4.7 Cursor Positioning
VT510manual, 1st ed., 1993YesHVP
xtermpatch 412, xterm-411aYes
libghostty-vt0f171f6Yes
kitty0.49.1, run in a VMYespasses the 4 cases that show it working
foot1.28.0, run in a VMYespasses the 4 cases that show it working
pyte0.8.2, run as a libraryPartlyfails HVP-4 of the 4 cases that show it working
xterm.js headless6.0.0, run as a libraryYespasses the 4 cases that show it working
alacritty_terminal0.26.0, run as a libraryYespasses the 4 cases that show it working
ConEmubuild 230724, its documentationYesANSI escape codes
rxvt-unicode9.31, run in a VMYespasses the 4 cases that show it working
VTE0.84.1, run as a libraryYespasses the 4 cases that show it working

Validation

HVP-1: To a position

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

HVP-2: Defaults

\e[3;3f
\e[f      # both left out
A
\e[2f     # column left out
B
\e[;4f    # line left out
C
\e[0;0f   # zero is one
D
|D__C_|
|B____|
|_____|

HVP-3: Clamped to the screen

\e[999;999f
X
|_____|
|_____|
|____X|

HVP-4: With origin mode

\e[2;3r   # region is lines 2 and 3
\e[?6h    # origin mode
\e[1;1f   # the top of the region
A
\e[9;1f   # clamped to the bottom of the region
B
|_____|
|A____|
|B____|
|_____|
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.