# Reset Color Palette (OSC 104)

> Put palette colors back as they started.

- **Sequence:** `OSC 104 ; Pc ST`
- **ECMA-48:** [§8.3.89 OSC – Operating System Command, p. 51](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n64/mode/1up)
- **xterm:** [Operating System Commands](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

`OSC 104 ; Pc ST` puts palette color `Pc` back as the terminal started it,
undoing [OSC 4](https://control-codes.page/osc/palette/index.html.md). It takes any number of colors,
`OSC 104 ; 1 ; 2 ST`, and with none, `OSC 104 ST`, resets every one
([`ResetAnsiColorRequest`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L3051-L3086)).

xterm reads the numbers in turn and stops at the first that is not a number,
so `OSC 104 ; 1 ; x ; 2 ST` resets color 1 and leaves color 2 alone. A
number past the palette is skipped ([`ResetOneAnsiColor`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L3032-L3048)).

With no number xterm resets more than the palette: it runs over every color
slot it has, and the slots after the 256 palette colors hold the five
[special colors](https://control-codes.page/osc/special-colors/index.html.md), so they are reset too. Those also
have a reset of their own, [OSC 105](https://control-codes.page/osc/reset-special-colors/index.html.md), and can be
reset one by one here as palette numbers 256 to 260.

DECSTR and RIS reset the palette as well, as the [OSC 4](https://control-codes.page/osc/palette/index.html.md) page
shows.

libghostty-vt resets the colors named, and with none, the whole palette. It
differs from xterm when the list has something in it that is not a number:
it skips that and goes on, and a list with no number left in it resets the
whole palette, as an empty one does. Its source says this follows kitty on
purpose. It also leaves the special colors alone, having none. Those cases
are known differences.

## Validation

### OSC104-1: Reset one color

Input, one step per line:

```text
\e]4;1;red;2;blue\a
\e]104;1\a
\e]4;1;?;2;?\a
```

Expected screen:

```text
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/0000/ffff\a
```

### OSC104-2: Several

Input, one step per line:

```text
\e]4;1;red;2;blue;3;green\a
\e]104;1;3\a
\e]4;1;?;2;?;3;?\a
```

Expected screen:

```text
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/0000/ffff\a\e]4;3;rgb:cdcd/cdcd/0000\a
```

### OSC104-3: Reset them all

Input, one step per line:

```text
\e]4;1;red;2;blue\a
\e]104\a
\e]4;1;?;2;?\a
```

Expected screen:

```text
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/cdcd/0000\a
```

### OSC104-4: An empty list is all of them too

Input, one step per line:

```text
\e]4;1;red;2;blue\a
\e]104;\a
\e]4;1;?;2;?\a
```

Expected screen:

```text
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/cdcd/0000\a
```

### OSC104-5: Something not a number stops the list

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

Input, one step per line:

```text
\e]4;1;red;2;blue\a
\e]104;1;x;2\a
\e]4;1;?;2;?\a
```

Expected screen:

```text
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/0000/ffff\a
```

### OSC104-6: So nothing is reset

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

Input, one step per line:

```text
\e]4;1;red\a
\e]104;x\a
\e]4;1;?\a
```

Expected screen:

```text
|____|
reply \e]4;1;rgb:ffff/0000/0000\a
```

### OSC104-7: With no number, the special colors too

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

Input, one step per line:

```text
\e]5;0;red\a   # the color for bold
\e]104\a
\e]5;0;?\a
```

Expected screen:

```text
|____|
reply \e]5;0;rgb:0000/0000/0000\a
```

---

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