Skip to content

DECSCA — Select Character Protection Attribute

SequenceCSI <n> " q
Bytes0x1B 0x5B <n> 0x22 0x71
MnemonicDECSCA
Otty support

Description

Marks subsequently written characters as protected or erasable. Protected cells are skipped by the selective-erase sequences DECSED (CSI ? <n> J) and DECSEL (CSI ? <n> K); ordinary ED / EL ignore the attribute and erase everything.

<n>Effect
0Characters are erasable (default)
1Characters are protected from selective erase
2Characters are erasable (same as 0)

The attribute sticks to the cursor and applies to every character written until changed, so a typical use is "turn protection on, draw a fixed frame/labels, turn it off, then let the app selectively erase the editable region without disturbing the frame".

Interaction with other state

  • Independent of SGR. SGR 0 (reset attributes) does not clear protection — only DECSCA 0 / 2, a soft reset (DECSTR), or a full reset (RIS) do.
  • Saved with the cursor. DECSC / DECRC save and restore the protection state along with the cursor.
  • Erasing a protected cell through any path leaves the replacement cell unprotected.

Example

bash
# Draw a protected label, then prove a selective erase spares it.
printf '\e[2J\e[H'
printf '\e[1"q'        # protect on
printf 'LABEL: '
printf '\e[0"q'        # protect off
printf 'value-to-erase'
printf '\e[?2J'        # DECSED — 'value-to-erase' clears, 'LABEL: ' remains
  • EDCSI ? <n> J is DECSED, the selective erase-in-display.
  • ELCSI ? <n> K is DECSEL, the selective erase-in-line.
  • DECSTR — soft reset clears the protection attribute.

Otty