^[control-codes live in libghostty-vt

Operating system commands

OSC P Set Palette (Linux)

Change a palette color, as the Linux console does.

OSC P n rrggbb ST
ECMA-48
§8.3.89 OSC – Operating System Command, p. 51
Specification
console_codes(4), Linux manual pages

OSC P n rrggbb ST sets color n, one hex digit from 0 to f, to the color rrggbb. It is the Linux console’s, which has only sixteen colors; OSC 4 does the same for the 256 of the palette, and OSC R resets them. iTerm2 also accepts it, though its Proprietary Escape Codes page advises against it, and extends n past f to its other colors: g and h for the default foreground and background, i for bold, j and k for the selection, l and m for the cursor.

The Linux console’s own definition, in console_codes(4), has no terminator: ESC ] P takes exactly seven hex digits after it, and ESC ] R none at all. Every other terminal reads them as OSCs, which run until ST or BEL, so sent the console’s way, one of these swallows whatever follows it until something ends the string.

A default xterm ignores both: a letter it does not know where the number should be makes the sequence malformed (do_osc). libghostty-vt ignores them too.

Validation

OSC-P-1: It does not change a color

\e]P1ff0000\e\\
\e]4;1;?\a
|______|
reply \e]4;1;rgb:cdcd/0000/0000\a

OSC-P-2: Nor iTerm2’s foreground

\e]Pg4040ff\e\\  # the foreground, iTerm2's way
\e]10;?\a
|______|
reply \e]10;rgb:0000/0000/0000\a

OSC-P-3: Without a terminator, it swallows what follows

\e]P1ff0000  # the console's way
AB
|______|
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.