Skip to main content

XTPUSHCOLORS/XTPOPCOLORS

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Experimental

XTPUSHCOLORS and XTPOPCOLORS are XTerm extensions that save and restore the terminal's color palette using a stack.

Syntax​

CSI # p          XTPUSHCOLORS — Push color palette onto stack
CSI Ps # q XTPOPCOLORS — Pop color palette from stack
CSI # R XTREPORTCOLORS — Report palette stack depth
Formal syntax
(* Push current palette onto stack *)
XTPUSHCOLORS   = 0x1b, "[", "#", "p" ;

(* Pop palette from stack *)
XTPOPCOLORS    = 0x1b, "[", [ Ps ], "#", "q" ;

(* Report current stack depth *)
XTREPORTCOLORS = 0x1b, "[", "#", "R" ;

(* Report response *)
XTREPORTCOLORS-response = 0x1b, "[", Pn, "#", "Q" ;

Ps             = digit, { digit } ;                (* stack entry to restore, default: pop top *)
Pn             = digit, { digit } ;                (* current stack depth *)
digit          = "0" | "1" | "2" | "3" | "4"
             | "5" | "6" | "7" | "8" | "9" ;

Parameters​

SequenceParameterDescription
XTPOPCOLORSPsStack entry index to restore (default: pop the most recent entry)

Response (XTREPORTCOLORS)​

The terminal responds with CSI Pn # Q where Pn is the number of entries currently on the palette stack.

Description​

Per XTerm documentation, XTPUSHCOLORS saves the current color palette (all 256 indexed colors plus the dynamic colors like foreground, background, and cursor color) onto an internal stack. XTPOPCOLORS restores a previously saved palette.

The stack has a limited depth (typically 10 entries in XTerm). Pushing beyond the limit silently fails.

XTPOPCOLORS with no parameter pops the most recent entry, removing it from the stack. With a parameter Ps, it restores that specific stack entry without removing any entries.

XTREPORTCOLORS queries the current depth of the palette stack, allowing applications to check whether saves are available before popping.

These sequences are useful for applications that temporarily modify the terminal's color palette (such as theming or color scheme previews) and want to cleanly restore the original colors on exit.

Examples​

# Save current color palette
printf '\e[#p'

# Modify some colors (e.g., set color 1 to bright red via OSC 4)
printf '\e]4;1;rgb:ff/00/00\e\\'

# Restore original color palette
printf '\e[#q'

# Query stack depth (response: ESC [ Pn # Q)
printf '\e[#R'

Specifications​

SpecificationSection
XTerm ctlseqs—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✗No
Bobcat✓0.9.0Supported via TerminalCtrl library
contour✓v0.3.2.202
foot✓YesImplemented at csi.c:2124-2196, supports both XTPUSHCOLORS and XTPOPCOLORS
Ghostty✗NoColor palette stack operations not implemented
iTerm2✓YesColor palette stack push/pop implemented via XTERMCC_XTPUSHCOLORS and XTERMCC_XTPOPCOLORS tokens (CSI # P and CSI # Q).
Kitty✓YesImplemented via CSI # p and CSI # Q
Konsole✗NoNo implementation found for XTPUSHCOLORS/XTPOPCOLORS (CSI # p/q)
mintty✓YesImplemented at src/termout.c:3319-3325. Supports XTPUSHCOLORS (CSI # P), XTPOPCOLORS (CSI # Q), and XTREPORTCOLORS (CSI # R).
mlterm✗NoCSI # p/q not implemented
PuTTY✗NoColor palette stack (CSI # p/q) not implemented
Rio✗No
rxvt-unicode✗No
st✗No
terminology✗NoNo implementation found for color palette stack operations
VT100✗No
VTE✗NoDefined in parser but implementation is empty stub
WezTerm✗No
Windows Terminal✗NoNo evidence of XTPUSHCOLORS/XTPOPCOLORS implementation found
xterm✓xterm-385
xterm.js✗NoTests marked as skipped with TODO
Multiplexers
cy✗No
GNU Screen✗NoCSI # p/q not implemented
tmux✗NoColor palette stack not implemented; only title stack available
tuios✗No
Zellij✗No

See also​