[PR #1881] Fix interpretation of DECSTBM margin parameters #24695

Closed
opened 2026-01-31 09:04:48 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/1881

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/1881 **State:** closed **Merged:** Yes --- <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request When setting the scroll margins with the [DECSTBM](https://vt100.net/docs/vt510-rm/DECSTBM.html) 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. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #1849 * [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 * [x] 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: #1849 <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## 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. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## 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.
claunia added the pull-request label 2026-01-31 09:04:48 +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#24695