Skip to content

XTPUSHSGR — push SGR stack (CSI # {)

Category: modes · Baseline: rich · Tags: Xterm Extensions · Specification ↗

ESC [ # {
XTPUSHSGR pushes the current SGR (Select Graphic Rendition) state onto an internal stack. The sequence is CSI # { (or CSI Pt # { with a parameter mask to push only specific attributes). XTPOPSGR (CSI # }) pops the most recent state. This solves a recurring TUI problem: a function that wants to set its own SGR state, render some output, and restore the caller's state. Without push/pop, the function would need to query SGR via DECRQSS, save the result, and write it back — far more error-prone and slower. SGR push/pop also enables nested attribute scopes (e.g., bold inside an italic block) without losing state. Introduced by xterm in patch #357 (2018), now adopted by Ghostty, foot, Contour, and other modern terminals. Often paired with XTPUSHCOLORS (CSI # P) for a complete "push graphics state" idiom.
How this is testedautomated
Send \x1b[#{ (XTPUSHSGR), verify the sequence is consumed and the terminal stays responsive.

The same probe runs against headless backends (via Termless) and real terminal apps (via a daemon launched in each terminal). This lets us distinguish parser correctness from rendering correctness.

Analysis2026-04-06

Supported by 8 of 9 terminals (89%). Not supported by: Alacritty. Part of the Rich TUI baseline. Notes: Alacritty: SGR stack not implemented by alacritty.

Supported by 9 of 14 backends (64%)

Terminal Applications

TerminalVersionSupportNotes
iTerm23.6.9✓ yesSequence consumed; terminal responsive
Ghostty1.3.1✓ yesSequence consumed; terminal responsive
Terminal.app2.15✓ yesSequence consumed; terminal responsive
Kitty0.46.2✓ yesSGR stack not exposed via Python batch bridge
VS Code1.113.0? unknown
Warp0.2026.03.18.08.24.03? unknown
Cursor2.6.21? unknown

Headless Backends

Parser correctness only — a means the parser accepts the sequence.

BackendVersionSupportNotes
vt100.js0.2.1✓ yes
vterm0.2.0✓ yes
xterm.js5.5.0✓ yes
WezTerm0.1.0-fork.5~ partialSGR stack not exposed in headless mode; sequence consumed silently
Alacritty0.26.0✗ noSGR stack not implemented by alacritty