^[control-codes live in libghostty-vt

Control sequences

ECH Erase Character

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
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.

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