Skip to main content
ansicode

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[\x1b[5n (status request) \x1b[6n (cursor pos request)
\\033[\033[5n / \033[6n
\\e[\e[5n / \e[6n
ESC [ESC [ Ps n
hex1b 5b <Ps> 6e

Description

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

bash
# 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"
python
import sys; sys.stdout.write('\x1b[6n')   # reply arrives on stdin in raw mode
go
fmt.Print("\x1b[6n")
javascript
process.stdout.write('\x1b[6n')
c
printf("\x1b[6n"); fflush(stdout); /* parse <row>;<col>R from stdin */

Used in

Real-world tools that emit this sequence — anchors the bytes to commands you've already used.

  • vim, neovim startup probes`:checkhealth` emits `\x1b[6n` to confirm cursor-position reporting works before enabling block-cursor / mouse features
  • resize(1) (xterm utility)the canonical implementation of "discover terminal size without ioctl" — moves cursor to `\x1b[9999;9999H`, emits DSR-6n, parses the reply, exports `COLUMNS` and `LINES`
  • stty -a fallback probesraw `printf '\033[6n'` + bounded `read` is the portable fallback for cases where `TIOCGWINSZ` isn't available (CI runners, serial consoles)
  • powerlevel10k, starship right-promptscomplex multi-line prompts use DSR-6n to reconcile their wcwidth estimate against the terminal's actual cursor advance
  • asciinema, ttyrec — capture DSR replies in the recorded session so playback is dimension-accurate

Frequently asked

Short answers to the questions developers actually search for this sequence.

I sent \x1b[6n but never get a reply — what's wrong?
Three usual causes. (1) The tty is in cooked mode — the reply (\x1b[<row>;<col>R) arrives on stdin and the line discipline holds it until you press Enter. Switch to raw or stty -icanon min 0 time N for a non-blocking read with timeout. (2) The read happens *before* the reply lands — the terminal answer can take dozens of milliseconds, so always pair the request with a bounded read (or select() with timeout) and a fallback. (3) You're inside tmux/screen without passthrough — the multiplexer answers on behalf of the inner pane and may report its own size instead of the host terminal's; for the host you need passthrough or a direct query before the multiplexer attaches. Always implement a 200 ms timeout + ioctl(TIOCGWINSZ) fallback so a missing reply doesn't hang the program.
Should I use DSR \x1b[6n or DA \x1b[c to detect terminal capabilities?
Neither directly — they answer different questions. DSR-6n returns the cursor position, useful for measuring screen size (with the \x1b[9999;9999H trick) but says nothing about feature support. DA (\x1b[c) returns a device-attributes string identifying the emulator class (?1;2c, ?64;..., etc.) — a coarse capability hint but not feature-specific. For "does this terminal support synchronized output / focus events / SGR mouse?" you want DECRQM (\x1b[?<mode>$p, see the decrqm slug) which asks about a specific DEC private mode and gets a 0/1/2/3/4 answer. Use the three together when fingerprinting: DA for class, DECRQM for per-feature gates, DSR-6n for size when TIOCGWINSZ isn't available.

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
yes
GNU screen
yes

Related sequences

In the family cookbook

CSI cookbook · 4. Queries — DA, DA2, DSR, DECRQM