# Secure Reset (DECSR, DECSRC)

> Reset the terminal to its power-up state, erase everything the host could have stored in it, and confirm that it was done.

- **Sequence:** `CSI Pr + p`
- **Defaults:** Pr = 0, no confirmation
- **DEC STD 070:** [§4, ch. 5 Secure Reset, p. 29](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n232/mode/1up)
- **VT510:** [DECSR—Secure Reset](https://vt100.net/docs/vt510-rm/DECSR.html)

DECSR is the reset for a host that has to be sure what state the terminal is
in before it trusts it: a login program, say, taking over from a session that
could have left anything behind. DEC STD 070 says it "initializes the
terminal to its Power-Up state and erases all host setable state information
and data", which goes further than [RIS](https://control-codes.page/esc/ris/index.html.md): it also erases the
user-defined keys ([DECUDK](https://control-codes.page/dcs/decudk/index.html.md)) "even if the 'UDKs Locked' state
is in effect", the soft character sets ([DECDLD](https://control-codes.page/dcs/decdld/index.html.md)), macros,
and any buffer that could hold data from the host
([pp. 29–30](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n232/mode/1up)).
The VT510 manual lists among its actions that it "Clears the screen and all
off-screen page memory" and "Returns the cursor to the upper-left corner of
the first page".

The parameter asks for a confirmation:

> If a non-zero numeric parameter in the range 1 to 16383 is provided, the
> device responds with a Secure Reset Confirmation (DECSRC) control function
> with the same parameter upon successful completion. If Pn is omitted or
> zero, no response is generated. If Pn exceeds 16383, the entire sequence
> shall be ignored.

DECSRC is `CSI Pr * q`, carrying the number back, so a host that picks a
random number can tell its own reset's confirmation from anything else
([DECSRC—Secure Reset Confirmation](https://vt100.net/docs/vt510-rm/DECSRC.html)).
DEC STD 070 makes DECSR level 4, but notes that it "is recognized at all
conformance levels", and that it also takes the terminal out of display
controls mode, since otherwise only the user could.

xterm does not implement DECSR. Its parse table ignores the whole of a
control sequence with `+` as its intermediate byte
([`VTPrsTbl.c`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/VTPrsTbl.c#L533)):

```c
CASE_CSI_IGNORE,	/* vt420 and vt520 */
```

and DECSRC appears only as a comment
([`VTPrsTbl.c`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/VTPrsTbl.c#L3542)).
A default xterm consumes the sequence and does nothing, and the cases follow
it, as the [sources](https://control-codes.page/sources/index.html.md) page explains: no reset and no
confirmation, whatever the parameter. DEC STD 070's reset and DECSRC are
described above, not tested.

DEC STD 070's algorithm sends the confirmation's introducer as the 8-bit
`CSI`, `0x9B`. A terminal sending 7-bit controls would send `ESC [`, as it
does for `CSI` in every other report.

## Not in libghostty-vt

libghostty-vt does not implement DECSR either. Its dispatch for `CSI … p` in
`stream.zig` handles only DECRQM, and logs any other intermediate byte as
unimplemented, so `CSI + p` changes nothing and sends nothing, as in xterm.

## Validation

### DECSR-1: No confirmation is sent

Input, one step per line:

```text
\e[1+p    # DEC STD 070: confirm with CSI 1 * q
```

Expected screen:

```text
|_____|
reply none
```

### DECSR-2: The screen is not cleared

Input, one step per line:

```text
AB
\e[2;3H
\e[+p     # DEC STD 070: reset, clearing the screen
```

Expected screen:

```text
|AB___|
|_____|
cursor 2,3
reply none
```

### DECSR-3: A number too large is ignored

Input, one step per line:

```text
AB
\e[16384+p   # more than 16383: DEC STD 070 ignores it too
```

Expected screen:

```text
|AB___|
|_____|
cursor 1,3
reply none
```

---

This is the Markdown version of <https://control-codes.page/csi/decsr/>. 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>.
