DECSC (ESC 7) doesn't save the character set and SGR attributes #216

Open
opened 2026-01-30 21:46:01 +00:00 by claunia · 0 comments
Owner

Originally created by @j4james on GitHub (Apr 4, 2018).

Originally assigned to: @j4james on GitHub.

  • Your Windows build number:

Microsoft Windows [Version 10.0.16299.309]

  • What you're doing and what's happening:

I'm trying to use the DECSC/DECRC escape sequences to save and restore the rendering state. According to the VT100 docs, the DECSC sequence (ESC 7) causes the cursor position, graphic rendition, and character set to be saved, and the DECRC sequence (ESC 8) causes the previously saved cursor position, graphic rendition, and character set to be restored.

The test case below sets the text color to red, designates the line drawing character set, and then attempts to save the state with DECSC. It then outputs a few characters to move the cursor position, resets the color to the defaults, reset the character set to ASCII, and restores the state with DECRC. At this point it outputs the string "lwkmvj", which should display something discernible from the active character set.

printf "\033[31m\033(0\0337------\033[m\033(B\0338lwkmvj\033[m\033(B\n"

I've tried this on a couple of Linux terminals, and in most cases the output is red text using the line drawing character set:

image

On Windows, though, the cursor position is correctly restored, but the text color is just the default, and the character set is still ASCII:

image

  • What's wrong / what should be happening instead:

Considering what the VT100 docs specify for the behaviour of DECSC/DECRC, I would have expected the SGR attributes and character set to be saved, and not just the cursor position. For some of the more advanced VT terminals there may be other states that ought to be saved, but this ought to be enough for VT100 compatibility at least.

Note that the ANSISYSSC/ANSISYSRC sequences are probably different. Since those are assumedly meant to be compatible with the original DOS behaviour, it makes sense for them to only restore the cursor position. I have seen some Linux terminal emulators treat them as synonyms for DECSC/DECRC, but I believe that is likely a mistake.

Originally created by @j4james on GitHub (Apr 4, 2018). Originally assigned to: @j4james on GitHub. * Your Windows build number: Microsoft Windows [Version 10.0.16299.309] * What you're doing and what's happening: I'm trying to use the DECSC/DECRC escape sequences to save and restore the rendering state. According to the VT100 docs, the DECSC sequence (`ESC 7`) causes the cursor position, graphic rendition, and character set to be saved, and the DECRC sequence (`ESC 8`) causes the previously saved cursor position, graphic rendition, and character set to be restored. The test case below sets the text color to red, designates the line drawing character set, and then attempts to save the state with DECSC. It then outputs a few characters to move the cursor position, resets the color to the defaults, reset the character set to ASCII, and restores the state with DECRC. At this point it outputs the string "lwkmvj", which should display something discernible from the active character set. printf "\033[31m\033(0\0337------\033[m\033(B\0338lwkmvj\033[m\033(B\n" I've tried this on a couple of Linux terminals, and in most cases the output is red text using the line drawing character set: ![image](https://user-images.githubusercontent.com/4181424/38328614-4a74fbf8-3843-11e8-995f-3e9face4d8ec.png) On Windows, though, the cursor position is correctly restored, but the text color is just the default, and the character set is still ASCII: ![image](https://user-images.githubusercontent.com/4181424/38328896-03d39f1e-3844-11e8-85c2-7f8b8dbe7dc1.png) * What's wrong / what should be happening instead: Considering what the VT100 docs specify for the behaviour of DECSC/DECRC, I would have expected the SGR attributes and character set to be saved, and not just the cursor position. For some of the more advanced VT terminals there may be other states that ought to be saved, but this ought to be enough for VT100 compatibility at least. Note that the ANSISYSSC/ANSISYSRC sequences are probably different. Since those are assumedly meant to be compatible with the original DOS behaviour, it makes sense for them to only restore the cursor position. I have seen some Linux terminal emulators treat them as synonyms for DECSC/DECRC, but I believe that is likely a mistake.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#216