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

Fix interpretation of DECSTBM margin parameters #1881

Merged
merged 3 commits into from
Jul 10, 2019

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Jul 8, 2019

Summary of the Pull Request

When setting the scroll margins with the DECSTBM escape sequence, some of the edge cases are interpreted incorrectly. If the top margin is equal to the bottom margin, or the bottom margin is greater than the screen height, the command should be ignored, but at the moment it isn't. This PR fixes those cases.

Tested manually and with additional adapter unit tests.

PR Checklist

Detailed Description of the Pull Request / Additional comments

This is a slight rewrite of the AdaptDispatch::_DoSetTopBottomScrollingMargins method which I think should be a little easier to follow.

  • Step 1: Translate the default (zero) values - default top is 1, and default bottom is the screen height.
  • Step 2: Check whether the values are valid, i.e. top is less than bottom, and bottom is less than or equal to the screen height.
  • Step 3a: If valid, check whether the range covers the full height of the screen, in which case the margins are cleared (i.e. set to 0,0).
  • Step 3b: If valid but not full screen, subtract 1 from the values to translate from the VT 1-based coordinate system to the internal 0-based coordinates.

Validation Steps Performed

I've added a few more unit tests to the ScrollMarginsTest in adapterTest.cpp to validate the specific edge cases that were previously incorrect: the top margin being equal to the bottom margin, the top margin being out of range, and the bottom margin being out of range. There was also a weird range of 1,0 which should have cleared the margins but didn't.

While adding these tests, I noticed a couple of the existing tests weren't correct. They were meant to be testing whether certain full screen ranges would clear the margins, but the expected values weren't correctly set, and the tested ranges weren't covering the full screen. So while the tests passed, they weren't actually testing what they claimed to be. This PR also includes fixes for those tests.

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.

:shipit:

@miniksa miniksa merged commit 594a7e4 into microsoft:master Jul 10, 2019
@j4james j4james deleted the fix-margin-parameters branch July 10, 2019 23:12
mcpiroman pushed a commit to mcpiroman/terminal that referenced this pull request Jul 23, 2019
* Fix DECSTBM parameter interpretation to ignore invalid ranges, and clear the margins on all full screen ranges.

* Add additional scroll margin adapter tests to verify the parameter configurations that were previously incorrect.

* Fix scroll margin adapter tests that weren't actually verifying the conditions that they claimed to be testing.
@ghost
Copy link

ghost commented Aug 3, 2019

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

Handy links:

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.

Incorrect interpretation of DECSTBM parameters
3 participants