OSC 4 Change Color Palette
Set and query the colors that SGR's color numbers stand for.
OSC 4 ; Pc ; Pt ST
The terminal’s palette is the 256 colors that SGR’s color numbers stand for: CSI 31 m uses color 1, CSI 38 ; 5 ; 196 m color 196. OSC 4 ; Pc ; Pt ST changes color Pc to Pt, and OSC 104 ; Pc ST puts it back as it started. These are xterm’s.
Ptis a color in any form X11’sXParseColoraccepts: a name such asredorlight sky blue,#rrggbb, orrgb:rr/gg/bb, where each part may have one to four hex digits.Ptof?asks what the color is. The answer isOSC 4 ; Pc ; rgb:rrrr/gggg/bbbb, sixteen bits a part, ended with whichever of ST or BEL ended the question.- One sequence can carry several pairs,
OSC 4 ; 1 ; red ; 2 ; ? ST, mixing changes and questions. xterm stops at the first color it cannot parse or number it does not have, and ignores the rest (ChangeAnsiColorRequest,ReportAnsiColorRequest). - DECSTR and RIS both reset the palette (
ReallyReset).
Where the palette starts is the host’s choice, made in xterm with resources such as color1. The cases are run in a terminal given a default xterm’s: black, red3, green3, yellow3, blue2, magenta3, cyan3 and gray90, then their bright versions, for colors 0 to 15 (charproc.c), and the 6×6×6 cube and the gray ramp for 16 to 255 (256colres.h). The answers assume a 24-bit display, where xterm reports each part of a color as its eight bits repeated, cd as cdcd.
xterm also has OSC 5 and OSC 105, which work the same way on its special colors, the ones it can use for bold, underlined, blinking, reversed and italic text. libghostty-vt does keep the palette through DECSTR, but its DECSTR is not implemented at all (see DECSTR).
Support
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | No | OSC is not among the controls it recognizes (§4.2) |
| VT510 | manual, 1st ed., 1993 | No | ignores an OSC string (chapter 4) |
| xterm | patch 412, xterm-411a | Yes | |
| libghostty-vt | 0f171f6 | Yes | DECSTR does not reset it, having no DECSTR (OSC4-8) |
| Konsole | 26.11.70, a24c3d71 | Partly | answers only the first ? in a list, and sets every color in a list to the first one’s |
| kitty | 0.49.1, run in a VM | Partly | fails OSC4-4 of the 3 cases that show it working; ends its replies with ST where xterm uses BEL |
| foot | 1.28.0, run in a VM | Partly | fails OSC4-5 of the 2 cases that show it working |
| pyte | 0.8.2, run as a library | No | fails the 3 cases that show it working |
| xterm.js headless | 6.0.0, run as a library | No | fails the 3 cases that show it working |
| alacritty_terminal | 0.26.0, run as a library | Partly | fails OSC4-5 of the 3 cases that show it working |
| ConEmu | build 230724, its documentation | No | not in its ANSI escape codes |
| rxvt-unicode | 9.31, run in a VM | Partly | fails OSC4-4, OSC4-7 of the 3 cases that show it working; writes colors as ff00 where xterm writes ffff |
| VTE | 0.84.1, run as a library | Partly | fails OSC4-5 of the 3 cases that show it working |
Validation
OSC4-1: Ask for a color
\e]4;1;?\a
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a
OSC4-2: The answer ends as the question did
\e]4;12;?\e\\
|____|
reply \e]4;12;rgb:5c5c/5c5c/ffff\e\\
OSC4-3: From the cube and the gray ramp
\e]4;196;?;244;?\a
|____|
reply \e]4;196;rgb:ffff/0000/0000\a\e]4;244;rgb:8080/8080/8080\a
OSC4-4: Change a color, and text drawn in it
\e[31mA
\e]4;1;#123456\a
\e]4;1;?\a
|A___|
attr 1,1 fg=#123456
reply \e]4;1;rgb:1212/3434/5656\a
OSC4-5: By name, and by rgb:
\e]4;1;light sky blue;2;rgb:f/80/abc\a
\e]4;1;?;2;?\a
|____|
reply \e]4;1;rgb:8787/cece/fafa\a\e]4;2;rgb:ffff/8080/abab\a
OSC4-6: A color it cannot parse stops the rest
\e]4;1;nosuch;2;red\a
\e]4;1;?;2;?\a
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a\e]4;2;rgb:0000/cdcd/0000\a
OSC4-7: RIS resets the palette
\e]4;1;red\a
\ec
\e]4;1;?\a
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a
OSC4-8: So does DECSTR
\e]4;1;red\a
\e[!p
\e]4;1;?\a
|____|
reply \e]4;1;rgb:cdcd/0000/0000\a