DSR — Device Status Report (CSI 5n / CSI 6n)
Ask for terminal status (5n) or the current cursor position (6n) — the reverse channel TUIs use to size the terminal.
Byte forms
Every common string-literal form so you can paste-and-search either direction.
\x1b[5n (status request) \x1b[6n (cursor pos request)\033[5n / \033[6n\e[5n / \e[6nESC [ Ps n1b 5b <Ps> 6eDescription
Device Status Report. The application sends a request; the terminal answers on stdin. **`\x1b[5n`** — "are you OK?". Reply: `\x1b[0n` (ready) or `\x1b[3n` (malfunction). Used as a liveness check after enabling exotic modes. **`\x1b[6n`** (a.k.a. CPR — Cursor Position Report) — "where is the cursor?". Reply: `\x1b[<row>;<col>R`. The classic trick to discover terminal size without TIOCGWINSZ is to move the cursor to the end of the screen (`\x1b[9999;9999H`), DSR-6n, parse the reply, then restore. Modern apps prefer `ioctl(TIOCGWINSZ)` + `SIGWINCH` for resizes, but DSR-6n remains the only portable answer on systems without that ioctl (over raw serial, certain CI environments). xterm extension: `\x1b[?6n` returns the cursor position constrained by the origin-mode flag (DECOM).
Spec citation: ECMA-48 §8.3.35 (DSR) / xterm-ctlseqs
Examples
# Discover terminal size without TIOCGWINSZ:\nstty -echo raw min 0 time 5\nprintf '\033[s\033[9999;9999H\033[6n\033[u'\nIFS=';' read -r -d R esc_row col; stty sane\necho "rows=${esc_row#*[} cols=$col"import sys; sys.stdout.write('\x1b[6n') # reply arrives on stdin in raw modefmt.Print("\x1b[6n")process.stdout.write('\x1b[6n')printf("\x1b[6n"); fflush(stdout); /* parse <row>;<col>R from stdin */Terminal support
- xterm
- yes
- Linux console (fbcon)
- yes
- macOS Terminal.app
- yes
- iTerm2
- yes
- Windows Terminal
- yes
- cmd.exe / ConPTY
- yes
- kitty
- yes
- alacritty
- yes
- WezTerm
- yes
- Ghostty
- yes
- GNOME Terminal
- yes
- Konsole
- yes
- tmux
- no
- GNU screen
- no
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | no | no |