^[control-codes
live in libghostty-vt

Operating system commands

OSC 104 Reset Color Palette

View as Markdown

Put palette colors back as they started.

OSC 104 ; Pc ST
ECMA-48
§8.3.89 OSC – Operating System Command, p. 51
xterm
Operating System Commands

OSC 104 ; Pc ST puts palette color Pc back as the terminal started it, undoing OSC 4. It takes any number of colors, OSC 104 ; 1 ; 2 ST, and with none, OSC 104 ST, resets every one (ResetAnsiColorRequest).

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).

It also reads past the end of the list. After each number it checks that a ; follows with strchr(";", c), which also finds the terminating NUL, so after the last number it steps over the end of the string and goes on reading whatever an earlier, longer OSC left in the same buffer (misc.c). After OSC 4 ; 1 ; red ; 2 ; blue ST, OSC 104 ; 1 ; 3 ST resets colors 1 and 3, then finds 2;blue left over after its own end, and resets color 2 as well. What it resets depends on what came before, but it is a bug of a default xterm, which this site follows, so OSC104-2 expects it.

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, so it tries to reset those too. Those also have a reset of their own, OSC 105, and can be named here as palette numbers 256 to 260. In a default xterm none of these resets works on a special color, for the reason the OSC 105 page gives, so a special color that has been changed stays changed.

DECSTR and RIS reset the palette as well, as the OSC 4 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.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984NoOSC is not among the controls it recognizes (§4.2)
VT510manual, 1st ed., 1993Noignores an OSC string (chapter 4)
xtermpatch 412, xterm-411aYeswith no number, tries the special colors too, but cannot reset them
libghostty-vt0f171f6Yesskips what is not a number, and has no special colors (OSC104-5 to OSC104-7)
Konsole26.11.70, a24c3d71Yesa list item that is not a number resets color 0; no special colors
kitty0.49.1, run in a VMYespasses the 3 cases that show it working; ends its replies with ST where xterm uses BEL
foot1.28.0, run in a VMPartlyfails OSC104-1 of the 3 cases that show it working
pyte0.8.2, run as a libraryNofails the 3 cases that show it working
xterm.js headless6.0.0, run as a libraryNofails the 3 cases that show it working
alacritty_terminal0.26.0, run as a libraryPartlyfails OSC104-1 of the 3 cases that show it working
ConEmubuild 230724, its documentationNonot in its ANSI escape codes
rxvt-unicode9.31, run in a VMNofails the 3 cases that show it working
VTE0.84.1, run as a libraryYespasses the 3 cases that show it working

Validation

OSC104-1: Reset one color

\e]4;1;red;2;blue\a
\e]104;1\a
\e]4;1;?;2;?\a
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/0000/ffff\a

OSC104-2: Several, and one more from the buffer

\e]4;1;red;2;blue;3;green\a
\e]104;1;3\a                # then reads "2;blue" left after its end
\e]4;1;?;2;?;3;?\a
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/cdcd/0000\a\e]4;3;rgb:cdcd/cdcd/0000\a

OSC104-3: Reset them all

\e]4;1;red;2;blue\a
\e]104\a
\e]4;1;?;2;?\a
|____|
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

\e]4;1;red;2;blue\a
\e]104;\a
\e]4;1;?;2;?\a
|____|
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

\e]4;1;red;2;blue\a
\e]104;1;x;2\a
\e]4;1;?;2;?\a
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/0000/ffff\a

OSC104-6: So nothing is reset

\e]4;1;red\a
\e]104;x\a
\e]4;1;?\a
|____|
reply \e]4;1;rgb:ffff/0000/0000\a

OSC104-7: With no number, not the special colors

\e]5;0;red\a   # the color for bold
\e]104\a
\e]5;0;?\a
|____|
reply \e]5;0;rgb:ffff/0000/0000\a
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.