Skip to main content
ansicode

DECRQSS — Request Selection or Setting (DCS $ q ... ST)

Ask the terminal to report the current value of any SGR / mode / margin / cursor-shape setting — the catch-all DCS query.

Byte forms

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

\\x1b[\x1bP$q<P>\x1b\\
\\033[\033P$q<P>\033\\
\\e[\eP$q<P>\e\\
ESC [ESC P $ q <P> ESC \
hex1b 50 24 71 ... 1b 5c

Description

Request Selection or Setting. A DCS frame whose intermediate is `$` (0x24) and final is `q` (0x71); the body `<P>` names the setting whose value the application wants reported. Common probes: `\x1bP$qm\x1b\\` asks for the active SGR attributes (terminal replies `\x1bP1$rm\x1b\\` listing the current colour/style stack), `\x1bP$q r\x1b\\` (the literal sequence `$ q SP r`) reports DECSTBM scroll-region margins, `\x1bP$q" p\x1b\\` reports the DECSCL conformance level, `\x1bP$q" q\x1b\\` reports DECSCA character protection, and `\x1bP$q q\x1b\\` (` SP q`) reports the active DECSCUSR cursor shape. The reply uses the same DCS shape — leading byte `1` (valid + supported) or `0` (invalid request), then `$r`, the requested-setting bytes, and ST. Modern apps use DECRQSS in startup probes so they can restore the terminal's pre-existing state when they exit — `vim`'s `t_RV` autodetection, `bat`'s syntax-theme picker, and `kitty kitten themes` all rely on it.

Spec citation: xterm-ctlseqs (DECRQSS, DCS $ q Pt ST)

Examples

bash
# Ask for the current SGR attributes; reply lands on stdin in raw mode.\nstty -echo raw min 0 time 5\nprintf '\033P$qm\033\\'; IFS= read -r -t 1 -d '\\' REPLY; stty sane\necho "DECRQSS m reply: $REPLY"
python
import sys; sys.stdout.write('\x1bP$qm\x1b\\\\')   # reply arrives on stdin
go
fmt.Print("\x1bP$qm\x1b\\\\")   // request current SGR
javascript
process.stdout.write('\x1bP$qm\x1b\\\\')   // request current SGR; read process.stdin
c
printf("\x1bP$qm\x1b\\\\"); fflush(stdout); /* read DCS reply from stdin */

Terminal support

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

Related sequences

In the family cookbook

DCS cookbook · 3. Asking the terminal questions — DECRQSS, terminfo cap, DECRQTSR, DECRQUPSS, cursor-style