[PR #1331] Support VT100 DECOM Origin Mode #24592

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

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

State: closed
Merged: Yes


Summary of the Pull Request

This adds support for the DECOM (origin mode) escape sequence, which controls whether cursor positioning is relative to the margins of the scrolling region, or independent of the scrolling region (the original behaviour). Tested manually, with Vttest, and with some unit tests.

PR Checklist

  • Closes Ctrl arrow keys don't behave as expected (#132)
  • CLA signed. If not, go over here and sign the CLA
  • 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: #132

Detailed Description of the Pull Request / Additional comments

This adds two state variables to the AdaptDispatch class to track the origin mode and a saved copy of the origin mode for use with the Save/Restore Cursor commands (DECSC/DECRC). When the origin mode is relative, adjustments are then made to the line number in the _CursorMovePosition and _CursorPositionReport methods to account for the margin offset (this is a slight change from my initial proposal, which was to make those adjustments in the methods that called _CursorMovePosition).

It's a bit complicated when it comes to restoring the saved origin mode in the CursorRestorePosition method, because the saved cursor position is always absolute, so we have to temporarily set the origin mode to the absolute mode before restoring the cursor, and then afterwards restore the actual saved origin mode. But I think that complication is justified if it allows us to keep the origin adjustments centralized in the _CursorMovePosition method (which may one day need to support left/right margins too).

Other changes include updating the SoftReset method to reset the origin mode and the saved origin mode, and reordering the HardReset method to call the SoftReset before resetting the cursor position to home (this makes sure that the home position is absolute, and not relative to the previous margins).

I also updated _DoDECCOLMHelper to reset the origin mode when changing between 80 and 132 column modes. I couldn't find a spec reference for this, but I thought it made sense given that the margins are being reset there. And, as far as I can tell, that's what Xterm is doing too.

Validation Steps Performed

I've added a basic "state machine" unit test which validates that the set/reset escape sequences trigger the SetOriginMode call, and some "screen buffer" units tests which validate various interactions between the origin mode, the margins, and the cursor positioning. I've also done quite a lot of manual testing, not all of which I've been able to replicate in the unit tests (e.g. cursor position reporting).

I've run a couple of the Vttest suites that are dependent on origin mode support and noted that they were at least improved, if not fully working yet (because of other VT features not yet implemented). This includes screens 3 and 4 of the Test of cursor movements, and screens 11 and 12 of the Test of screen features.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/1331 **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 This adds support for the [DECOM (origin mode)](https://vt100.net/docs/vt100-ug/chapter3.html#DECOM) escape sequence, which controls whether cursor positioning is relative to the margins of the scrolling region, or independent of the scrolling region (the original behaviour). Tested manually, with [Vttest](https://invisible-island.net/vttest/), and with some unit tests. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #132 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [x] 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: #132 <!-- 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 adds two state variables to the `AdaptDispatch` class to track the origin mode and a saved copy of the origin mode for use with the Save/Restore Cursor commands (DECSC/DECRC). When the origin mode is relative, adjustments are then made to the line number in the `_CursorMovePosition` and `_CursorPositionReport` methods to account for the margin offset (this is a slight change from my initial proposal, which was to make those adjustments in the methods that called `_CursorMovePosition`). It's a bit complicated when it comes to restoring the saved origin mode in the `CursorRestorePosition` method, because the saved cursor position is always absolute, so we have to temporarily set the origin mode to the absolute mode before restoring the cursor, and then afterwards restore the actual saved origin mode. But I think that complication is justified if it allows us to keep the origin adjustments centralized in the `_CursorMovePosition` method (which may one day need to support left/right margins too). Other changes include updating the `SoftReset` method to reset the origin mode and the saved origin mode, and reordering the `HardReset` method to call the `SoftReset` before resetting the cursor position to home (this makes sure that the home position is absolute, and not relative to the previous margins). I also updated `_DoDECCOLMHelper` to reset the origin mode when changing between 80 and 132 column modes. I couldn't find a spec reference for this, but I thought it made sense given that the margins are being reset there. And, as far as I can tell, that's what Xterm is doing too. <!-- 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 basic "state machine" unit test which validates that the set/reset escape sequences trigger the `SetOriginMode` call, and some "screen buffer" units tests which validate various interactions between the origin mode, the margins, and the cursor positioning. I've also done quite a lot of manual testing, not all of which I've been able to replicate in the unit tests (e.g. cursor position reporting). I've run a couple of the [Vttest](https://invisible-island.net/vttest/) suites that are dependent on origin mode support and noted that they were at least improved, if not fully working yet (because of other VT features not yet implemented). This includes screens 3 and 4 of the _Test of cursor movements_, and screens 11 and 12 of the _Test of screen features_.
claunia added the pull-request label 2026-01-31 09:04:14 +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#24592