-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for the DECSCNM Screen Mode #3773
Comments
I think it's used by some apps to achieve a visual bell. Terminfo describes Probably the same question applies as for the per-character reverse mode (SGR 7): if combined with the "bright" attribute is it the foreground or the background to be brightened? I don't think it really matters. Probably the simplest is just to XOR the per-character "reverse" bit with this global flag, and have whatever comes out of that. In my opinion emitting this sequence, even for the purpose of a visual bell, is a terrible practice. The timing is unreliable across a remote connection. The sudden switch between such different colors, especially if repeated a couple of times, could perhaps even trigger epileptic seizure in some people. I think apps should emit the regular BEL, and it should be a user setting of the terminal whether they want audible or visual bell (or both or none), whereas the visual can be implemented in more sophisticated ways, e.g. a smooth transition back and forth between normal and reverse video, or a(n animated) bell icon symbol showing up in the tab bar, etc. I've also seen apps toggling this global reverse mode back and forth without a delay in between, expecting to achieve a visual bell effect – like, what? You might also want to look at this bug in "screen": https://savannah.gnu.org/bugs/?52545, just to give you an idea how broken sometimes it is implemented in practice. That being said, of course it's okay to support this feature in the terminal and blame the apps that actually use it. :) |
I did not know that. Thank you! In fact I see we already have a bug report for visual bell support from way back (#72), which probably means this can be closed as a dup.
Yep. Based on my reading of the spec that was my conclusion too. The way our code is structured it doesn't work out exactly like that, but the end result is the same.
Agreed. And I'm convinced we already have an issue with a suggestion along those lines although I can't find it right now.
Yeah, I was just testing the visible bell-style in bash that was mentioned in issue #72, and that's exactly what happened - my |
Haha, I totally did not remember that there was this #72 which I even commented on :-D |
## 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.
🎉This issue was addressed in #3817, which has now been successfully released as Handy links: |
The original purpose of the screen mode setting is laid out in the user guides, not in the programmers' references. The VT420 user guide, for example, explains that it is for "viewing comfort" and is to "improve readability". It's really a user preference, configurable in SETUP. It is one of the lockable user preferences, meaning that DECSCNM from a host might not do anything at all. Note that terminal emulators do not do what real terminals did. XTerm has a long tradition of swapping "light" and "dark", and others have copied it, for starters. But then they don't even behave the same as one another when it comes to DECSCNM. Some swap foreground and background; some swap colour indexes 0 and 7; and some only reverse default-coloured text. |
Description of the new feature/enhancement
The
DECSCNM
(screen mode) escape sequence is a DEC private mode for switching the display between normal and reverse - often referred to as dark and light backgrounds on monochrome terminals. I doubt it's widely used in practice, but it's needed to pass some of the tests in the Vttest suite.In the DEC STD 070 manual, the behaviour of the
DECSCNM
mode is described as follows:I take that to mean that the background attributes of a cell will be used to render the text foreground and the foreground attributes will be used for the background. This seems to be how it's implemented in Konsole and the Linux virtual terminal, but there is quite a lot of variation in how other terminals interpret it. Without a clear consensus, though, I'd be inclined to follow the standard. As long as it passes Vttest, I don't think it really matters.
Proposed technical implementation details
Looking at the conhost side of things, I think this can be achieved with a new flag in the
Settings
class, and then updates to theLookupForegroundColor
andLookupBackgroundColor
methods, to switch the returned foreground and background colors when the flag is set. This seems to be enough to make the renderer draw everything with the correct colors, including underlines.We'll also need a new private API in the
ConGetSet
interface, which can be called from theAdaptDispatch
class to actually toggle the mode, and trigger a redraw of the display. And theHardReset
implementation should probably be updated to reset the mode back to normal.As for the Windows Terminal, my preliminary tests suggest it doesn't require anything special. Whatever is rendered on the conhost side seems to be passed through correctly via conpty as well.
The text was updated successfully, but these errors were encountered: