# Reset to Initial State (RIS)

> Reset the terminal to the state it has when switched on.

- **Sequence:** `ESC c`
- **ECMA-48:** [§8.3.105 RIS – Reset to Initial State, p. 55](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n68/mode/1up)
- **DEC STD 070:** [§D.2 Reset to Initial State, p. D-5](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n1191/mode/1up)
- **VT510:** [RIS—Reset to Initial State](https://vt100.net/docs/vt510-rm/RIS.html)

Put the terminal back the way it was when it was switched on. ECMA-48 lists
what that "may imply": clearing tab stops, resetting the graphic rendition,
erasing every character position, moving the cursor to the first position
of the first line, and setting the modes to their reset state.

DEC STD 070 keeps RIS in an appendix of exceptions, and says conforming
software "will not use the RIS control". Its algorithm resets the margins,
the rendition, origin mode, insert mode, the character sets and the saved
cursor, erases the display, homes the cursor, and puts a tab stop every
eight columns. Some of that state, such as autowrap and the tab stops, a DEC
terminal lets the user choose and store in setup, and RIS restores the
stored choice, so DEC STD 070 warns that software cannot rely on it. The
VT510 manual adds that RIS "usually causes a communication line disconnect"
on a real terminal.

Both recommend the soft reset instead, DECSTR, `CSI ! p`
([DEC STD 070 §4, ch. 5, p. 31](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n234/mode/1up),
[VT510 DECSTR](https://vt100.net/docs/vt510-rm/DECSTR.html)). DECSTR resets
the modes, margins, rendition and character sets a program might have
changed, but leaves the screen and the cursor alone. libghostty-vt does not
implement DECSTR; the last case below shows it.

## Validation

### RIS-1: Erases the screen and homes the cursor

Input, one step per line:

```text
AB\r\nCD
\ec
```

Expected screen:

```text
|____________|
|____________|
cursor 1,1
```

### RIS-2: Resets the rendition

Input, one step per line:

```text
\e[1;31m  # bold, red
\ec
X
```

Expected screen:

```text
|X___________|
attr 1,1 plain
```

### RIS-3: Resets the margins and origin mode

Input, one step per line:

```text
\e[2;3r   # region is lines 2 and 3
\e[?6h    # origin mode
\ec
X
```

Expected screen:

```text
|X___________|
|____________|
|____________|
```

### RIS-4: Puts the tab stops back

Input, one step per line:

```text
\e[3g     # clear every tab stop
\ec
\tX
```

Expected screen:

```text
|________X___|
```

### RIS-5: Resets insert mode

Input, one step per line:

```text
\e[4h     # insert mode
\ec
AB
\e[1;1H
Z         # replaces A rather than pushing it along
```

Expected screen:

```text
|ZB__________|
```

### RIS-6: DECSTR, by contrast, keeps the screen

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

Input, one step per line:

```text
AB
\e[1;31m  # bold, red
\e[!p     # DECSTR
X
```

Expected screen:

```text
|ABX_________|
attr 1,3 plain
cursor 1,4
```

libghostty-vt ignores `CSI ! p`. Its dispatch for the final byte `p` in
`stream.zig` handles only DECRQM, with a `$` intermediate, and logs any other
intermediate as unimplemented, so the screen is kept, as it should be, but
the rendition stays bold and red. DEC STD 070's list of what DECSTR resets
includes "Current Rendition normal", and the VT510 manual's DECSTR page
lists SGR as reset to normal rendition.

---

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