Skip to main content
ansicode

DECCARA / DECRARA — Change / Reverse attributes in rectangular area (`CSI Pt;Pl;Pb;Pr;Ps;… $ r` / `$ t`)

Set or XOR SGR attributes across a rectangle of cells without rewriting any character data — the rectangular-attribute siblings of the copy/fill/erase ops in dec-rect-ops.

Byte forms

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

\\x1b[\x1b[<Pt>;<Pl>;<Pb>;<Pr>;<Ps>;…$r (DECCARA) \x1b[<Pt>;<Pl>;<Pb>;<Pr>;<Ps>;…$t (DECRARA)
\\033[\033[3;5;10;30;1;7$r
\\e[\e[3;5;10;30;1;7$r
ESC [ESC [ Pt ; Pl ; Pb ; Pr ; Ps … $ r / $ t
hex1b 5b ... 24 72 / 24 74

Description

DECCARA — *Change Attributes in Rectangular Area* — and DECRARA — *Reverse Attributes in Rectangular Area* — round out the DEC rectangular-operation family (the others — DECCRA copy, DECFRA fill, DECERA erase, DECSERA selective erase — are documented in dec-rect-ops).

Geometry: Pt;Pl;Pb;Pr are the rectangle's top row, left column, bottom row, right column (all 1-indexed, inclusive). The same rect-ops conventions from decsace apply — DECSACE selects whether 'rectangle' means strictly the cell-rectangle (block) or wraps line-by-line (stream).

Attribute list: Ps;… is an SGR-style list of attribute selectors. The repertoire is DEC's reduced SGR set: 0 = clear all attributes, 1 = bold, 4 = underline, 5 = blink, 7 = reverse video, 22 = bold off, 24 = underline off, 25 = blink off, 27 = reverse off. Standard 8-color fg/bg (30–37 / 40–47) and ECMA-48 extended-color (38;5;n, 48;2;r;g;b) are honoured by xterm-class emulators; pure DEC hardware ignored them. Empty Ps;… (just \x1b[Pt;Pl;Pb;Pr$r) is treated as 0 = clear.

Semantic difference: - DECCARA ($ r) — *sets* the listed attributes on every cell. Unlisted attributes are LEFT UNCHANGED (it's not a full SGR overwrite — it's selective). To replace all attributes, lead with 0 then re-list (e.g. \x1b[1;1;24;80;0;1;7$r clears then applies bold + reverse). - DECRARA ($ t) — *XORs* the listed attributes on every cell. A cell that was bold becomes non-bold; one that wasn't becomes bold. Used by some screen renderers to implement a 'flash this region' UX without saving + restoring cell state.

No character data is touched — both ops only modify the attribute layer at each cell. This is the killer feature: a diff highlighter can re-attribute a line block without retyping the chars, and a focus-mode TUI can dim the non-focused panes by XORing dim across them.

DECSACE coupling: when DECSACE has selected stream-mode (\x1b[2*x), the same DECCARA / DECRARA call interprets Pt;Pl as a single stream-start position and Pb;Pr as a stream-end position — the affected cells are every cell between the two positions following normal text flow, not a block. Use \x1b[0*x (or omit) to keep block semantics. See decsace.

Coverage: xterm = full both ops including extended colour. Kitty = full DECCARA, DECRARA partial. WezTerm / Ghostty = full. Konsole = full. iTerm2 = partial (extended colour not honoured in DECCARA). Alacritty = no-op (silently consumed). Windows Terminal = no-op pre-1.20; partial DECCARA after. macOS Terminal / Linux console / cmd / ConPTY = no-op.

Recommended use: yes for xterm-class emulators with explicit feature probe (DECRQM ?92 aka DECSACE — see decsace, plus xtversion for emulator family check). For portable code, simulate via DECCRA + write-with-SGR or by stream-mode SGR over the cells.

Spec citation: DEC VT510 RM (DECCARA / DECRARA) / xterm-ctlseqs (CSI ... $ r / $ t)

Parameters

Pt;Pl;Pb;PrTop row, left col, bottom row, right col (1-indexed inclusive). Stream- vs block-semantics chosen by DECSACE.
Ps;…SGR-style attribute selectors. Common: 0 clear, 1 bold, 4 underline, 5 blink, 7 reverse, 22/24/25/27 off-variants, 30–37 / 40–47 colours, 38;5;n / 48;2;r;g;b extended. Empty list = clear.

Examples

bash
# Set bold + reverse on rows 3-10, cols 5-30 without touching characters.\nprintf '\\033[3;5;10;30;0;1;7$r'
python
import sys\n# XOR underline on a one-line ribbon (rows 1, cols 1..80) — 'flash on'.\nsys.stdout.write('\\x1b[1;1;1;80;4$t')\nsys.stdout.flush()
go
// 'Dim non-focused panes' — XOR SGR 2 (dim) over the unselected region.\nfmt.Print(\"\\x1b[1;1;24;40;2$t\")     // dim left half\n// later, to undim, XOR again with same selector:\nfmt.Print(\"\\x1b[1;1;24;40;2$t\")
javascript
// Highlight diff hunk: reverse-video lines 12-15 across full width.\nprocess.stdout.write('\\x1b[12;1;15;80;7$r');
c
/* Replace all attrs in rect with red-on-default. */\nprintf(\"\\x1b[%d;%d;%d;%d;0;31$r\", t, l, b, r);

Terminal support

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

Related sequences