# Erase Rectangular Area (DECERA)

> Erase every character in a rectangle of the screen.

- **Sequence:** `CSI Pt ; Pl ; Pb ; Pr $ z`
- **Defaults:** the whole screen
- **DEC STD 070:** [§5.12.1 Erase Rectangular Area, p. 5-171](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n425/mode/1up)
- **VT510:** [DECERA—Erase Rectangular Area](https://vt100.net/docs/vt510-rm/DECERA.html)

Erase the rectangle whose top-left corner is line `Pt`, column `Pl` and
whose bottom-right corner is line `Pb`, column `Pr`: every character in it
becomes a space. Nothing outside the rectangle changes, and the cursor does
not move.

A parameter left out or `0` takes the screen's edge: `Pt` and `Pl` the
first line and column, `Pb` and `Pr` the last, so `CSI $ z` erases the
whole screen. A value past the edge is taken as the edge. If `Pt` is below
`Pb` or `Pl` right of `Pr`, nothing is erased. With
[origin mode](https://control-codes.page/modes/decom/index.html.md) on, the corners count from the top and left
margins; otherwise the margins play no part, and the rectangle may run
across them. xterm parses the corners in
[`xtermParseRect`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/screen.c#L2633-L2652) and erases in
[`CASE_DECERA`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/charproc.c#L5657-L5664).

DEC STD 070 says the erased positions lose all their attributes. xterm fills
them with spaces in the *current* rendition, keeping their colors
([`ScrnFillRectangle`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/screen.c#L2678-L2783)), and the cases follow
xterm; none of them checks attributes.

## Not in libghostty-vt

DECERA is one of the VT420's rectangle operations, which DEC STD 070 makes
level 4. libghostty-vt identifies itself as a VT220, level 2 (see
[DA](https://control-codes.page/csi/da/index.html.md)), and has no handler for `CSI … $ z` in `stream.zig`, so it
ignores it. xterm is a VT420 unless told otherwise
([`DFT_DECID`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/ptyx.h#L398-L400)) and implements DECERA at that level,
so by this site's [rule](https://control-codes.page/sources/index.html.md) every case below expects xterm's result
and is a known difference.

[DECFRA](https://control-codes.page/csi/decfra/index.html.md) fills a rectangle with a character instead, and
DECSERA, on the [selective erase](https://control-codes.page/csi/decsca/index.html.md) page, erases only the
characters not protected by DECSCA.

## Validation

### DECERA-1: A rectangle in the middle

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
abcdef\r\nghijkl\r\nmnopqr\r\nstuvwx
\e[1;3H
\e[2;2;3;4$z
```

Expected screen:

```text
|abcdef|
|g___kl|
|m___qr|
|stuvwx|
cursor 1,3
```

### DECERA-2: The whole screen by default

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
abcdef\r\nghijkl\r\nmnopqr\r\nstuvwx
\e[$z
```

Expected screen:

```text
|______|
|______|
|______|
|______|
```

### DECERA-3: Clipped to the screen

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
abcdef\r\nghijkl\r\nmnopqr\r\nstuvwx
\e[3;5;99;99$z
```

Expected screen:

```text
|abcdef|
|ghijkl|
|mnop__|
|stuv__|
```

### DECERA-4: Counted from the margins in origin mode

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
abcdef\r\nghijkl\r\nmnopqr\r\nstuvwx
\e[?69h   # allow left and right margins
\e[2;5s   # margins at columns 2 and 5
\e[2;4r   # region is lines 2 to 4
\e[?6h    # origin mode
\e[1;1;2;2$z
```

Expected screen:

```text
|abcdef|
|g__jkl|
|m__pqr|
|stuvwx|
```

### DECERA-5: Not limited by the margins otherwise

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
abcdef\r\nghijkl\r\nmnopqr\r\nstuvwx
\e[?69h   # allow left and right margins
\e[2;3s   # margins at columns 2 and 3
\e[1;2r   # region is lines 1 and 2
\e[2;2;4;6$z
```

Expected screen:

```text
|abcdef|
|g_____|
|m_____|
|s_____|
```

---

This is the Markdown version of <https://control-codes.page/csi/decera/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
