^[control-codes
live in libghostty-vt

Control sequences

ECH Erase Character

View as Markdown

Blank n characters from the cursor rightwards, without moving anything.

CSI Pn X
Defaults
Pn = 1
ECMA-48
§8.3.38 ECH – Erase Character, p. 41
DEC STD 070
§5.11 Erase Character, p. 5-152
VT220
§4.12 Erasing
VT510
ECH—Erase Character

Erase the character under the cursor and the Pn − 1 after it. A 0 is taken as 1. Nothing else on the line moves, and neither does the cursor. Asking for more characters than are left on the line erases to the end of the line and stops; ECH never continues onto the next one.

Unlike DCH and ICH, ECH ignores the margins. DEC STD 070 says it “is not affected by the margins”, and the VT510 manual that it “works inside or outside the scrolling margins”. The erased cells lose their character attributes as well as their characters.

EL erases from the cursor to the end of the line in one go.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Yes§4.12 Erasing
VT510manual, 1st ed., 1993YesECH
xtermpatch 412, xterm-411aYes
libghostty-vt0f171f6Yes
kitty0.49.1, run in a VMYespasses the 5 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 libraryYespasses the 5 cases that show it working
xterm.js headless6.0.0, run as a libraryYespasses the 5 cases that show it working
alacritty_terminal0.26.0, run as a libraryYespasses the 5 cases that show it working
ConEmubuild 230724, its documentationYesANSI escape codes
rxvt-unicode9.31, run in a VMYespasses the 5 cases that show it working
VTE0.84.1, run as a libraryYespasses the 4 cases that show it working

Validation

ECH-1: Erase one character

ABCDE
\e[1;2H
\e[X
|A_CDE|
cursor 1,2

ECH-2: Erase three

ABCDE
\e[1;2H
\e[3X
|A___E|

ECH-3: Stops at the end of the line

ABCDE\r\nFGHIJ
\e[1;4H
\e[99X
|ABC__|
|FGHIJ|
cursor 1,4

ECH-4: Ignores the margins

abcdefg
\e[?69h   # allow left and right margins
\e[2;4s   # margins at columns 2 and 4
\e[1;3H
\e[4X     # runs past the right margin
|ab____g|

ECH-5: Attributes are erased too

\e[1mABC\e[m
\e[1;2H
\e[X
|A_C__|
attr 1,1 bold
attr 1,2 plain
attr 1,3 bold
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.