Skip to main content
ansicode

DECSTR side-effects — exactly which modes `\x1b[!p` resets

Reference enumeration of every DEC mode / attribute that DECSTR (soft reset) restores to its default — what gets cleared, what survives, and where xterm vs kitty vs iTerm2 diverge.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[!p
\\033[\033[!p
\\e[\e[!p
ESC [ESC [ ! p
hex1b 5b 21 70

Description

Companion reference to `decstr-soft-reset` — same byte sequence (`\x1b[!p`), expanded into the full side-effect manifest from DEC VT510 RM §8.4.1. Use this page when the question is **'will DECSTR clobber my X?'** rather than **'how do I emit a soft reset?'**. **DECSTR does NOT touch**: - screen contents (main or alt — survives) - scrollback buffer (survives) - alt-screen saved snapshot (survives) - window title / icon name (set via OSC 0/2 — survives) - character set definitions in G0..G3 (definitions survive; the active GL/GR pointers reset — see below) - macro definitions (DECDMAC entries survive — see `dcs-decdmac`) - user keys (DECUDK entries survive — see `dcs-decudk`) - cursor position (preserved at the cell it was on) **DECSTR DOES reset, to the listed default**: - **IRM** (Insert / Replace mode, `\x1b[4h/l`) → Replace - **DECOM** (Origin Mode, `?6h/l` — see `dec-origin-mode`) → Off (absolute) - **DECAWM** (Auto-Wrap Mode, `?7h/l` — see `dec-line-wrap`) → On - **DECNRCM** (National Replacement Char Mode, `?42h/l`) → Off - **DECNKM** (Numeric / Application Keypad — see `deckpam-deckpnm`) → Numeric - **KAM** (Keyboard Action Mode, `\x1b[2h/l`) → Unlocked - **DECSCA** (Select Character Protection — see `decsca`) → All chars unprotected - **DECSCNM** (Screen Mode reverse video, `?5h/l` — see `decscnm`) → Normal (off) - **DECTCEM** (Text Cursor Enable, `?25h/l` — see `cursor-visibility`) → On (cursor visible) - **DECCKM** (Cursor Keys Mode, `?1h/l`) → Normal - **DECRLM** (Right-to-Left Mode, `?34h/l`) → Off - **DECSCUSR** (Cursor Shape — see `dec-cursor-shape`) → implementation default (usually blinking block, `\x1b[0 q`) - **DECSTBM** (Top/Bottom Margins — see `decstbm`) → Full screen (rows 1 .. height) - **DECSLRM** (Left/Right Margins — see `decslrm`) → Full screen (cols 1 .. width), only when DECLRMM is on - **SGR** (all character attributes — colour, bold, italic, etc.) → Default (`\x1b[0m`) - **DECSC saved cursor state** → Cleared (popped to empty) - **GL / GR mappings** → GL → G0, GR → G2 (canonical defaults) - **Selective erase state** → Disabled **Vendor divergence** to know about when shipping DECSTR-emitting code: - **xterm**, **kitty**, **alacritty**, **wezterm**, **ghostty**, **konsole**: match the spec table exactly. - **iTerm2**: does **not** reset DECSCUSR — the cursor shape persists across `\x1b[!p`. If you need to also restore cursor shape, send `\x1b[0 q` explicitly after DECSTR. - **Windows Terminal**: pre-1.20 builds do not reset DECSLRM. Modern builds match spec. - **Linux console** (kernel `vt`): treats DECSTR as RIS-lite on older kernels — clears screen and scrollback too. Don't rely on scrollback survival. - **macOS Terminal**: silently ignores the DECSCA reset (selective erase protection persists). - **cmd.exe / ConPTY**: implements partially; SGR + DECTCEM reset, most others ignored. **When to reach for DECSTR vs RIS**: DECSTR preserves user-visible screen + scrollback; RIS (see `ris-reset`) wipes them. For 'I just exited a TUI in unknown state — recover gracefully without losing context' → DECSTR. For 'user typed `reset` because their terminal is wedged' → RIS (which is what the `reset` shell command actually emits via terminfo `rs1`). **Defensive pattern** when shipping a TUI that wants to leave the terminal pristine on exit: ``` startup: snapshot via DECRQSS what we care about (SGR, cursor shape, margins, mouse modes) exit (defer / signal handler): emit \x1b[!p # soft reset clears most state emit \x1b[0 q # force cursor shape (iTerm2 fallback) emit \x1b[?1l\x1b> # cursor keys + keypad normalised (extra safety) emit \x1b[?25h # cursor visible (paranoia — DECSTR already does this) ```

Spec citation: DEC VT510 RM §8.4.1 (DECSTR side-effect table) / xterm-ctlseqs

Examples

bash
# Soft reset — preserves screen + scrollback. Side-effects as listed above.\nprintf '\\033[!p'
python
# Probe DECSCUSR after DECSTR to verify cursor-shape reset (catches iTerm2).\nimport sys\nsys.stdout.write('\\x1b[!p\\x1bP$q q\\x1b\\\\')\nsys.stdout.flush()
go
// Defensive exit: soft reset + explicit cursor shape + visible cursor.\nfunc restoreTerminal() {\n    fmt.Print(\"\\x1b[!p\")    // DECSTR\n    fmt.Print(\"\\x1b[0 q\")   // cursor shape -> default (iTerm2)\n    fmt.Print(\"\\x1b[?25h\")  // cursor visible (paranoia)\n}
javascript
// On Node TUI exit, leave terminal pristine for the user's shell.\nprocess.on('exit', () => {\n  process.stdout.write('\\x1b[!p\\x1b[0 q\\x1b[?25h');\n});
c
/* DECSTR keeps screen but you may want to also clear scroll-region\n * since DECSTBM resets to full-screen. */\nprintf(\"\\x1b[!p\");\nprintf(\"\\x1b[H\");  /* cursor home — DECSTR leaves it where it was */\nfflush(stdout);

Terminal support

xterm
yes
Linux console (fbcon)
partial
macOS Terminal.app
partial
iTerm2
partial
Windows Terminal
partial
cmd.exe / ConPTY
partial
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
yes
Konsole
yes
tmux
no
GNU screen
no

Related sequences