DECSTR Soft Terminal Reset
Put the modes and settings a program may have changed back to their defaults, leaving the screen alone.
CSI ! p
- DEC STD 070
- §4, ch. 5 Soft Terminal Reset, p. 31
- VT220
- §4.18.1 Soft Terminal Reset (DECSTR)
- VT510
- DECSTR—Soft Terminal Reset
DECSTR is the reset a program sends: it puts back the state a program may have changed, and leaves what is on the screen and where the cursor is. RIS, the full reset, also erases the screen and restores the user’s own settings, and both DEC STD 070 and the VT510 manual recommend DECSTR instead.
DEC STD 070 lists what DECSTR resets, and the VT510 manual’s table agrees:
- the top and bottom margins, to the whole screen, and the left and right margins likewise;
- the current rendition, to normal, and the selective erase attribute (DECSCA), to erasable;
- the character sets and which are in use, to their defaults;
- the saved cursor (DECSC), to its default, the home position;
- insert mode (IRM), to replace;
- origin mode (DECOM), to absolute;
- the cursor (DECTCEM), to shown;
- the keyboard: cursor key mode, keypad mode, keyboard action mode.
It also lists what DECSTR leaves alone: the data on the screen, the cursor position (“DECSTR has no affect on the Active Position”), the tab stops, column mode, screen mode, new line mode and line attributes.
Auto wrap mode is where the sources part. DEC STD 070 sets it to “Auto Wrap Off (NVM if present)”, the user’s stored setting when there is one, and the VT510 manual’s table says “No autowrap”. xterm leaves it on, and esctest2’s test_DECSTR_DECAWM checks that autowrap is still on afterwards. libghostty-vt sets it back to its default, which is on. There is no case for it here.
libghostty-vt’s DECSTR (softReset in Terminal.zig) resets everything in DEC STD 070’s list, and, as xterm’s does, the cursor style, the color palette (OSC 4), modifyOtherKeys and which display DECSASD has selected.
Support
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | Yes | §4.18.1 Soft Terminal Reset (DECSTR) |
| VT510 | manual, 1st ed., 1993 | Yes | DECSTR |
| xterm | patch 412, xterm-411a | Yes | leaves autowrap on |
| libghostty-vt | 919dca5 | Yes | leaves autowrap on |
| kitty | 0.49.1, run in a VM | Yes | passes the 7 cases that show it working |
| foot | 1.28.0, run in a VM | Partly | fails DECSTR-7 of the 6 cases that show it working |
| pyte | 0.8.2, run as a library | No | fails the 7 cases that show it working |
| xterm.js headless | 6.0.0, run as a library | Yes | passes the 7 cases that show it working |
| alacritty_terminal | 0.26.0, run as a library | Partly | fails DECSTR-2, DECSTR-3, DECSTR-4, DECSTR-5 and 2 more of the 7 cases that show it working |
| ConEmu | build 230724, its documentation | No | not in ANSI escape codes |
| rxvt-unicode | 9.31, run in a VM | Partly | fails DECSTR-1, DECSTR-7 of the 7 cases that show it working |
| VTE | 0.84.1, run as a library | Partly | fails DECSTR-7 of the 6 cases that show it working |
Validation
DECSTR-1: The screen and the cursor stay
AB
\e[2;3H
\e[!p
|AB___|
|_____|
cursor 2,3
DECSTR-2: Insert mode is reset
ABC
\e[4h # insert mode
\e[!p
\e[1;1H
X # replaces A
|XBC__|
DEC STD 070, the VT510 manual and esctest2’s test_DECSTR_IRM all reset IRM to replace, so the X replaces A rather than being inserted before it.
DECSTR-3: Origin mode is reset
\e[2;3r # region is lines 2 and 3
\e[?6h # origin mode
\e[!p
\e[1;1H # the corner of the screen again
X
|X____|
|_____|
|_____|
DEC STD 070, the VT510 manual and esctest2’s test_DECSTR_DECOM reset origin mode to absolute, so CSI 1 ; 1 H goes to the corner of the screen rather than the top of the region, line 2.
DECSTR-4: The rendition is reset
\e[1;31m # bold red
\e[!p
A
|A____|
attr 1,1 plain
Both manuals reset the rendition to normal, so the A is neither bold nor red.
DECSTR-5: The margins are reset
1\r\n2\r\n3\r\n4
\e[2;3r # region is lines 2 and 3
\e[!p
\e[3;1H
\n # would scroll lines 2 and 3 if the region were still set
X
|1____|
|2____|
|3____|
|X____|
DEC STD 070, the VT510 manual and esctest2’s test_DECSTR_STBM reset the margins to the whole screen, so the line feed moves the cursor to line 4 rather than scrolling lines 2 and 3.
DECSTR-6: The cursor is shown again
\e[?25l # hide the cursor
\e[!p
|_____|
cursor-visible yes
DEC STD 070 turns the cursor on, “ignore NVM”, and the VT510 manual’s table says “Cursor enabled”.
DECSTR-7: The saved cursor goes back to its default
\e[2;3H
\e7 # save the cursor at 2,3
\e[!p
\e8 # restore it
X
|X____|
|_____|
The VT510 manual’s table resets the saved cursor state to the home position, and esctest2’s test_DECSTR_DECSC checks that a restore afterwards goes there, rather than to 2,3.