^[control-codes live in libghostty-vt

Control sequences

ED Erase in Display

Erase part or all of the screen.

CSI Ps J
Defaults
Ps = 0
ECMA-48
§8.3.39 ED – Erase in Page, p. 41
DEC STD 070
§5.11 Erase in Display, p. 5-156
VT510
ED—Erase in Display

Erase some of the screen, chosen by Ps:

PsErases
0from the cursor to the end of the screen, the cursor’s cell included
1from the start of the screen to the cursor, the cursor’s cell included
2the whole screen
3the scrollback, which is not on the screen (an xterm extension)

The cursor does not move. Erasing ignores the margins; it is the screen that is erased, not the scrolling region.

An erased cell takes the current background color, set with SGR, rather than the default. That is background color erase, and is why programs reset SGR before clearing the screen.

Validation

ED-1: Below

\e#8      # fill with E
\e[2;2H
\e[J
|EEEE|
|E___|
|____|
cursor 2,2

ED-2: Above

\e#8      # fill with E
\e[2;2H
\e[1J
|____|
|__EE|
|EEEE|
cursor 2,2

ED-3: Everything

\e#8      # fill with E
\e[2;2H
\e[2J
|____|
|____|
|____|
cursor 2,2

ED-4: With a background color

\e[44m    # blue background
\e[2J
|____|
|____|
attr 1,1 bg=4
attr 2,4 bg=4