Skip to content
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 DECSCNM in Windows Terminal #6809

Merged
2 commits merged into from
Jul 9, 2020

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Jul 7, 2020

Summary of the Pull Request

This PR adds full support for the DECSCNM reverse screen mode in the Windows Terminal to align with the implementation in conhost.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

The AdaptDispatch::SetScreenMode now checks if it's in conpty mode and simply returns false to force a pass-through of the mode change. And the TerminalDispatch now has its own SetScreenMode implementation that tracks any changes to the reversed state, and triggers a redraw in the renderer.

To make the renderer work, we just needed to update the GetForegroundColor and GetBackgroundColor methods of the terminal's IRenderData implementation to check the reversed state, and switch the colors being calculated, the same way the LookupForegroundColor and LookupBackgroundColor methods work in the conhost Settings class.

Validation Steps Performed

I've manually tested the DECSCNM functionality for Windows Terminal in Vttest, and also with some of my own test scripts.

@ghost ghost added Area-VT Virtual Terminal sequence support Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Jul 7, 2020
@j4james
Copy link
Collaborator Author

j4james commented Jul 7, 2020

Note that the refactoring in this PR isn't strictly necessary to get the DECSCNM working, so if you have any objections to that, or you'd prefer it in a separate PR, it can easily be removed - we'd just need to keep the first two commits.

@j4james j4james marked this pull request as ready for review July 7, 2020 01:05
@DHowett
Copy link
Member

DHowett commented Jul 7, 2020

You’re a mind reader with these refactors! Just from a change atomicity standpoint I’d like to have the refactor go in as a separate PR, but I’m not glued to that idea and the team may overrule me :)

@j4james
Copy link
Collaborator Author

j4james commented Jul 7, 2020

Just from a change atomicity standpoint I’d like to have the refactor go in as a separate PR, but I’m not glued to that idea and the team may overrule me :)

No problem. I'm happy to do that. Just let me know one way or the other.

@DHowett
Copy link
Member

DHowett commented Jul 7, 2020

Let’s just split it up, it’s probably easier than waiting for a review cycle. 😄 thanks for being flexible

@j4james
Copy link
Collaborator Author

j4james commented Jul 7, 2020

FYI, I've just noticed that this PR exposes a bug in the "run of spaces" optimisation introduced in PR #4877. We're assuming that we don't need to send through foreground color changes on a run of spaces, because there's no text to be seen. That made perfect sense at the time, but that won't be true when the reversed screen mode is active. When that's the case, any spaces will be rendered with the foreground rather than background color, so it's essential that those foreground colors are actually passed through.

I'm not sure there's any way to keep that optimisation and also have the DECSCNM mode work correctly. Unless we go back to forcing a repaint when the mode changes, which somewhat defeats the purpose of passing it through. Should I just raise a followup issue for that, or do you think it's a blocking issue for this PR?

@DHowett
Copy link
Member

DHowett commented Jul 7, 2020

Is it possible to retain the optimization's fidelity by making conhost AND terminal aware of DECSCNM by doing the passthrough after we update conhost's state?

@j4james
Copy link
Collaborator Author

j4james commented Jul 7, 2020

Is it possible to retain the optimization's fidelity by making conhost AND terminal aware of DECSCNM by doing the passthrough after we update conhost's state?

That only helps if you also force a repaint of the entire screen. And even then it's not technically correct, because DECSCNM is like a palette setting - the client itself could potentially enable it without conhost knowing anything about it. That's probably unlikely, and usage of DECSCNM in general is fairly rare, so this is really an unfortunate edge case. It'd be horrible to lose a good optimisation just to make DECSCNM work. But I don't have any ideas other than leave it broken and hope nobody notices.

@DHowett
Copy link
Member

DHowett commented Jul 7, 2020

That explanation makes sense. Thanks 😄
I'm comfortable with "leave it broken and hope nobody notices."

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jul 9, 2020
@ghost
Copy link

ghost commented Jul 9, 2020

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 695ebff into microsoft:master Jul 9, 2020
ghost pushed a commit that referenced this pull request Jul 10, 2020
This is a refactoring of the renderer color calculations to simplify the
implementation, and to make it easier to support additional
color-altering rendition attributes in the future (e.g. _faint_ and
_conceal_).

## References

* This is a followup to PRs #3817 and #6809, which introduced additional
  complexity in the color calculations, and which suggested the need for
  refactoring. 

## Detailed Description of the Pull Request / Additional comments

When we added support for `DECSCNM`, that required the foreground and
background color lookup methods to be able to return the opposite of
what was requested when the reversed mode was set. That made those
methods unnecessarily complicated, and I thought we could simplify them
considerably just by combining the calculations into a single method
that derived both colors at the same time.

And since both conhost and Windows Terminal needed to perform the same
calculations, it also made sense to move that functionality into the
`TextAttribute` class, where it could easily be shared.

In general this way of doing things is a bit more efficient. However, it
does result in some unnecessary work when only one of the colors is
required, as is the case for the gridline painter. So to make that less
of an issue, I've reordered the gridline code a bit so it at least
avoids looking up the colors when no gridlines are needed.

## Validation Steps Performed

Because of the API changes, quite a lot of the unit tests had to be
updated. For example instead of verifying colors with two separate calls
to `LookupForegroundColor` and `LookupBackgroundColor`, that's now
achieved with a single `LookupAttributeColors` call, comparing against a
pair of values. The specifics of the tests haven't changed though, and
they're all still working as expected.

I've also manually confirmed that the various color sequences and
rendition attributes are rendering correctly with the new refactoring.
@j4james j4james deleted the feature-terminal-decscnm branch July 11, 2020 12:21
@ghost
Copy link

ghost commented Jul 22, 2020

🎉Windows Terminal Preview v1.2.2022.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for DECSCNM in Windows Terminal
4 participants