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

Closed
opened 2026-01-30 21:46:06 +00:00 by claunia · 3 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.
Author
Owner

@egmontkob commented on GitHub (Oct 6, 2019):

I confirm this issue.

Things to save/restore include (at least):

  • colors and visual attributes (bold, underlined etc.)
  • charset designated to the G0 slot (e.g. \e(B for normal, \e(0 for line drawing)
  • charset designated to the G1 etc. slots [not supported by WT]
  • shift in/out state (^N vs ^O), that is, whether G0 or G1 is used, and presumably the same for G2/G3 as GL/GR too (the details are unclear to me here) [not supported by WT]

And they should also be saved/restored on SCOSC/SCORC (\e[s, \e[u).

This issue is part of the reason for the failure on vttest -> 2. Test of screen features -> Test of the SAVE/RESTORE CURSOR feature (last screen). The other reason is emitting noise on ^N/^O rather than staying silent.

Loosely related:

VTE counterpart of this issue

Discusson on how this entire business of charsets should be obsoleted in favor of stateless UTF-8, but probably can't due to legacy apps. Maybe WT only supporting G0 and not G1 was an intentional step in this direction? Note however that PuTTY just recently, in version 0.71 implemented line drawing mode (supporting G0 and G1).

@egmontkob commented on GitHub (Oct 6, 2019): I confirm this issue. Things to save/restore include (at least): - colors and visual attributes (bold, underlined etc.) - charset designated to the G0 slot (e.g. `\e(B` for normal, `\e(0` for line drawing) - charset designated to the G1 etc. slots [not supported by WT] - shift in/out state (`^N` vs `^O`), that is, whether G0 or G1 is used, and presumably the same for G2/G3 as GL/GR too (the details are unclear to me here) [not supported by WT] And they should also be saved/restored on SCOSC/SCORC (`\e[s`, `\e[u`). This issue is part of the reason for the failure on `vttest` -> `2. Test of screen features` -> `Test of the SAVE/RESTORE CURSOR feature` (last screen). The other reason is emitting noise on `^N`/`^O` rather than staying silent. Loosely related: [VTE counterpart of this issue](https://bugzilla.gnome.org/show_bug.cgi?id=731205) [Discusson](https://bugzilla.gnome.org/show_bug.cgi?id=787228) on how this entire business of charsets should be obsoleted in favor of stateless UTF-8, but probably can't due to legacy apps. Maybe WT only supporting G0 and not G1 was an intentional step in this direction? Note however that PuTTY just recently, in version 0.71 implemented line drawing mode (supporting G0 and G1).
Author
Owner

@j4james commented on GitHub (Oct 6, 2019):

Discusson on how this entire business of charsets should be obsoleted in favor of stateless UTF-8, but probably can't due to legacy apps.

I definitely wouldn't want to drop the DEC charset support. Personally my priorities are to get the DEC standards working first, and then other standards and proprietary extensions would depend on compatibility requirements and/or user demand.

To that end, I'd suggest raising a separate issue for the DOCS sequences as a way to gauge interest. While I think that functionality could be useful, the last time I looked it wasn't that widely supported, so I don't imagine there's an urgent need for it.

@j4james commented on GitHub (Oct 6, 2019): >Discusson on how this entire business of charsets should be obsoleted in favor of stateless UTF-8, but probably can't due to legacy apps. I definitely wouldn't want to drop the DEC charset support. Personally my priorities are to get the DEC standards working first, and then other standards and proprietary extensions would depend on compatibility requirements and/or user demand. To that end, I'd suggest raising a separate issue for the DOCS sequences as a way to gauge interest. While I think that functionality could be useful, the last time I looked it wasn't that widely supported, so I don't imagine there's an urgent need for it.
Author
Owner

@ghost commented on GitHub (Nov 26, 2019):

:tada:This issue was addressed in #3160, which has now been successfully released as Windows Terminal Preview v0.7.3291.0.🎉

Handy links:

@ghost commented on GitHub (Nov 26, 2019): :tada:This issue was addressed in #3160, which has now been successfully released as `Windows Terminal Preview v0.7.3291.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.7.3291.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#218