[PR #3817] [MERGED] Add support for the DECSCNM screen mode #25520

Open
opened 2026-01-31 09:10:02 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/3817
Author: @j4james
Created: 12/3/2019
Status: Merged
Merged: 1/22/2020
Merged by: @undefined

Base: masterHead: feature-decscnm


📝 Commits (8)

  • 3f198a4 Add a setting for reversing the background and foreground colors when rendering the screen.
  • dacae4f Add a private API in the ConGetSet interface to toggle the reverse sceen setting and trigger a redraw of the screen.
  • 4b3ba4d Add support for the DECSCNM private mode escape sequence to toggle the sceen mode.
  • a6675a8 Add a state machine test to confirm the DECSCNM escape sequence is dispatched correctly.
  • b48f72d Add a screen buffer test to confirm the mode change switches the interpretation of the colors.
  • f844780 Set the screen mode back to normal when an RIS hard reset is triggered.
  • 259c3ed Make the TermDispatch::SetScreenMode method noexcept, to pass the new audit mode.
  • e5edb7c Add braces around if/else blocks.

📊 Changes

15 files changed (+169 additions, -2 deletions)

View changed files

📝 src/host/getset.cpp (+29 -0)
📝 src/host/getset.h (+2 -0)
📝 src/host/outputStream.cpp (+13 -0)
📝 src/host/outputStream.hpp (+2 -0)
📝 src/host/settings.cpp (+26 -2)
📝 src/host/settings.hpp (+4 -0)
📝 src/host/ut_host/ScreenBufferTests.cpp (+29 -0)
📝 src/terminal/adapter/DispatchTypes.hpp (+1 -0)
📝 src/terminal/adapter/ITermDispatch.hpp (+1 -0)
📝 src/terminal/adapter/adaptDispatch.cpp (+21 -0)
📝 src/terminal/adapter/adaptDispatch.hpp (+1 -0)
📝 src/terminal/adapter/conGetSet.hpp (+2 -0)
📝 src/terminal/adapter/termDispatch.hpp (+1 -0)
📝 src/terminal/adapter/ut_adapter/adapterTest.cpp (+7 -0)
📝 src/terminal/parser/ut_parser/OutputEngineTest.cpp (+30 -0)

📄 Description

Summary of the Pull Request

This adds support for the DECSCNM private mode escape sequence, which toggles the display between normal and reverse screen modes. When reversed, the background and foreground colors are switched. Tested manually, with Vttest, and with some new unit tests.

References

This also fixes issue #72 for the most part, although if you toggle the mode too fast, there is no discernible flash.

PR Checklist

  • Closes Window does not react to PowerToys (#3773)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

I've implemented this as a new flag in the Settings class, along with updates to the LookupForegroundColor and LookupBackgroundColor methods, to switch the returned foreground and background colors when that flag is set.

It also required a new private API in the ConGetSet interface to toggle the setting. And that API is then called from the AdaptDispatch class when the screen mode escape sequence is received.

The last thing needed was to add a step to the HardReset method, to reset the mode back to normal, which is one of the RIS requirements.

Note that this does currently work in the Windows Terminal, but once #2661 is implemented that may no longer be the case. It might become necessary to let the mode change sequences pass through conpty, and handle the color reversing on the client side.

Validation Steps Performed

I've added a state machine test to make sure the escape sequence is dispatched correctly, and a screen buffer test to confirm that the mode change does alter the interpretation of colors as expected.

I've also confirmed that the various "light background" tests in Vttest now display correctly, and that the tput flash command (in a bash shell) does actually cause the screen to flash.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/3817 **Author:** [@j4james](https://github.com/j4james) **Created:** 12/3/2019 **Status:** ✅ Merged **Merged:** 1/22/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `feature-decscnm` --- ### 📝 Commits (8) - [`3f198a4`](https://github.com/microsoft/terminal/commit/3f198a4263eb8de632453ea0048423271eb47003) Add a setting for reversing the background and foreground colors when rendering the screen. - [`dacae4f`](https://github.com/microsoft/terminal/commit/dacae4facf4eabae7fded2dbacc14686583bd909) Add a private API in the ConGetSet interface to toggle the reverse sceen setting and trigger a redraw of the screen. - [`4b3ba4d`](https://github.com/microsoft/terminal/commit/4b3ba4d9e33f211be9c30dddde1758ef01e3c2ab) Add support for the DECSCNM private mode escape sequence to toggle the sceen mode. - [`a6675a8`](https://github.com/microsoft/terminal/commit/a6675a84ba424bbad8dce7573e51cf5cc1111ebc) Add a state machine test to confirm the DECSCNM escape sequence is dispatched correctly. - [`b48f72d`](https://github.com/microsoft/terminal/commit/b48f72d53f7adc8a7a8a3e1fd970fff135f346a6) Add a screen buffer test to confirm the mode change switches the interpretation of the colors. - [`f844780`](https://github.com/microsoft/terminal/commit/f844780451fc747ad51ceb2e6c1103d9864c51cc) Set the screen mode back to normal when an RIS hard reset is triggered. - [`259c3ed`](https://github.com/microsoft/terminal/commit/259c3ed73187d44ec6ddc7979832262b718fb1a6) Make the TermDispatch::SetScreenMode method noexcept, to pass the new audit mode. - [`e5edb7c`](https://github.com/microsoft/terminal/commit/e5edb7ccccaf65ffdcd7ce024511a47b0f449c1c) Add braces around if/else blocks. ### 📊 Changes **15 files changed** (+169 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/host/getset.cpp` (+29 -0) 📝 `src/host/getset.h` (+2 -0) 📝 `src/host/outputStream.cpp` (+13 -0) 📝 `src/host/outputStream.hpp` (+2 -0) 📝 `src/host/settings.cpp` (+26 -2) 📝 `src/host/settings.hpp` (+4 -0) 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+29 -0) 📝 `src/terminal/adapter/DispatchTypes.hpp` (+1 -0) 📝 `src/terminal/adapter/ITermDispatch.hpp` (+1 -0) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+21 -0) 📝 `src/terminal/adapter/adaptDispatch.hpp` (+1 -0) 📝 `src/terminal/adapter/conGetSet.hpp` (+2 -0) 📝 `src/terminal/adapter/termDispatch.hpp` (+1 -0) 📝 `src/terminal/adapter/ut_adapter/adapterTest.cpp` (+7 -0) 📝 `src/terminal/parser/ut_parser/OutputEngineTest.cpp` (+30 -0) </details> ### 📄 Description ## Summary of the Pull Request This adds support for the [`DECSCNM`](https://vt100.net/docs/vt510-rm/DECSCNM.html) private mode escape sequence, which toggles the display between normal and reverse screen modes. When reversed, the background and foreground colors are switched. Tested manually, with [Vttest](https://invisible-island.net/vttest/), and with some new unit tests. ## References This also fixes issue #72 for the most part, although if you toggle the mode too fast, there is no discernible flash. ## PR Checklist * [x] Closes #3773 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments I've implemented this as a new flag in the `Settings` class, along with updates to the `LookupForegroundColor` and `LookupBackgroundColor` methods, to switch the returned foreground and background colors when that flag is set. It also required a new private API in the `ConGetSet` interface to toggle the setting. And that API is then called from the `AdaptDispatch` class when the screen mode escape sequence is received. The last thing needed was to add a step to the `HardReset` method, to reset the mode back to normal, which is one of the `RIS` requirements. Note that this does currently work in the Windows Terminal, but once #2661 is implemented that may no longer be the case. It might become necessary to let the mode change sequences pass through conpty, and handle the color reversing on the client side. ## Validation Steps Performed I've added a state machine test to make sure the escape sequence is dispatched correctly, and a screen buffer test to confirm that the mode change does alter the interpretation of colors as expected. I've also confirmed that the various "light background" tests in Vttest now display correctly, and that the `tput flash` command (in a bash shell) does actually cause the screen to flash. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:10:02 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25520