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

Make the RIS command clear the display and scrollback correctly #2367

Merged
merged 5 commits into from
Aug 28, 2019

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Aug 8, 2019

Summary of the Pull Request

When the scrollback buffer is empty, the RIS escape sequence (Reset to Initial State) will fail to clear the screen, or reset any of the state. And when there is something in the scrollback, it doesn't get cleared completely, and the screen may get filled with the wrong background color (it should use the default color, but it actually uses the previously active background color). This PR attempts to fix those issues.

PR Checklist

Detailed Description of the Pull Request / Additional comments

The initial failure is caused by the SCREEN_INFORMATION::WriteRect method throwing an exception when passed an empty viewport. And the reason it's passed an empty viewport is because that's what the Viewport::Subtract method returns when the result of the subtraction is nothing. The PR fixes the problem by making the Viewport::Subtract method actually return nothing in that situation.

This is a change in the defined behavior that also required the associated viewport tests to be updated. However, it does seem a sensible change, since the Subtract method never returns empty viewports under any other circumstances. And the only place the method seems to be used is in the ScrollRegion implementation, where the previous behavior is guaranteed to throw an exception.

The other issues are fixed simply by changing the order in which things are reset in the AdaptDispatch::HardReset method. The call to SoftReset needed to be made first, so that the SGR attributes would be reset before the screen was cleared, thus making sure that the default background color would be used. And the screen needed to be cleared before the scrollback was erased, otherwise the last view of the screen would be retained in the scrollback buffer.

These changes also required existing adapter tests to be updated, but not because of a change in the expected behaviour. It's just that certain tests relied on the SoftReset happening later in the order, so weren't expecting it to be called if say the scrollback erase had failed. It doesn't seem like the tests were deliberately trying to verify that the SoftReset hadn't been called.

Validation Steps Performed

In addition to the updates to existing tests, this PR also add a new screen buffer test which verifies the display and scrollback are correctly cleared under the conditions that were previously failing.

j4james added 3 commits August 8, 2019 23:38
…ound color is used, and clear the display before the scrollback, to prevent the last content being retained.
@DHowett-MSFT DHowett-MSFT requested a review from miniksa August 9, 2019 00:19
@DHowett-MSFT
Copy link
Contributor

Since @miniksa's the original author of the "SomeViewports" machinery, I've tagged him for review. He's out of the office currently. :)

@DHowett-MSFT
Copy link
Contributor

I believe that the only other place Viewport::Subtract is used will be okay with receiving 0 viewports instead of 1 0x0 viewport, because it would have fallen into WriteRect and .. thrown an exception?

@j4james
Copy link
Collaborator Author

j4james commented Aug 9, 2019

What I'm saying is that the ScrollRegion method is the one and only place that Viewport::Subtract is used (at least as far as I could determine). And with the previous behaviour - returning 1 empty viewport - it was guaranteed to throw an exception there (that's what cause the RIS to fail). So unless I've missed some other place it's being used, I can't see any reason why we'd want to retain that behaviour.

@DHowett-MSFT
Copy link
Contributor

Whoops, chalk that up to my poor reading skills. Thanks!

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me, and if the rest of the tests pass, then I'm pretty sure the change to Viewport::Subtract is probably fine, though @miniksa would be the one to know for sure.

src/types/viewport.cpp Show resolved Hide resolved
@DHowett-MSFT
Copy link
Contributor

Sorry, I clicked "re-request review" because it was next to Michael's name, but then it may have done it for Mike as well. thanks github

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still approve

@DHowett-MSFT DHowett-MSFT added the Needs-Second It's a PR that needs another sign-off label Aug 26, 2019
@ghost ghost requested review from carlos-zamora and DHowett-MSFT August 26, 2019 22:58
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the Subtract change. You're right that was only really for the context of scroll operations and I follow your reasoning on why it's OK to change.

Thank you. This is a great change and you provided excellent research and reasoning behind making it. Makes my life as a reviewer easy.

EDIT: I approved with comments because they're minor. Fix them or don't, it's not a big deal. Thanks.

src/host/ut_host/ScreenBufferTests.cpp Show resolved Hide resolved
src/terminal/adapter/adaptDispatch.cpp Outdated Show resolved Hide resolved
src/types/viewport.cpp Show resolved Hide resolved
@miniksa miniksa removed the Needs-Second It's a PR that needs another sign-off label Aug 27, 2019
…der, and a more useful failure log in the screen buffer test.
@j4james
Copy link
Collaborator Author

j4james commented Aug 28, 2019

It looks like the x86 unit tests have timed out again. The build bot clearly hates me.

@DHowett-MSFT
Copy link
Contributor

Taking the N-1 results. 😄 Thanks for the contribution!

@DHowett-MSFT DHowett-MSFT merged commit 974e95e into microsoft:master Aug 28, 2019
DHowett-MSFT pushed a commit that referenced this pull request Sep 3, 2019
When the scrollback buffer is empty, the RIS escape sequence (Reset to Initial
State) will fail to clear the screen, or reset any of the state. And when there
is something in the scrollback, it doesn't get cleared completely, and the
screen may get filled with the wrong background color (it should use the
default color, but it actually uses the previously active background color).
This commit attempts to fix those issues.

The initial failure is caused by the `SCREEN_INFORMATION::WriteRect` method
throwing an exception when passed an empty viewport. And the reason it's passed
an empty viewport is because that's what the `Viewport::Subtract` method
returns when the result of the subtraction is nothing.  The PR fixes the
problem by making the `Viewport::Subtract` method actually return nothing in
that situation.

This is a change in the defined behavior that also required the associated
viewport tests to be updated. However, it does seem a sensible change, since
the `Subtract` method never returns empty viewports under any other
circumstances. And the only place the method seems to be used is in the
`ScrollRegion` implementation, where the previous behavior is guaranteed to
throw an exception.

The other issues are fixed simply by changing the order in which things are
reset in the `AdaptDispatch::HardReset` method. The call to `SoftReset` needed
to be made first, so that the SGR attributes would be reset before the screen
was cleared, thus making sure that the default background color would be used.
And the screen needed to be cleared before the scrollback was erased, otherwise
the last view of the screen would be retained in the scrollback buffer.

These changes also required existing adapter tests to be updated, but not
because of a change in the expected behaviour. It's just that certain tests
relied on the `SoftReset` happening later in the order, so weren't expecting it
to be called if say the scrollback erase had failed. It doesn't seem like the
tests were deliberately trying to verify that the SoftReset _hadn't_ been
called.

In addition to the updates to existing tests, this PR also add a new screen
buffer test which verifies the display and scrollback are correctly cleared
under the conditions that were previously failing.

Fixes #2307.

(cherry picked from commit 974e95e)
@j4james j4james deleted the fix-hard-reset branch September 11, 2019 16:22
@ghost
Copy link

ghost commented Sep 24, 2019

🎉Windows Terminal Preview v0.5.2661.0 has been released which incorporates this pull request.:tada:

Handy links:

@DHowett-MSFT
Copy link
Contributor

This went out for conhost in insider build 19002! Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RIS reset doesn't clear the display and scrollback correctly
4 participants