[PR #15054] [MERGED] Update DECSC/DECRC to match the newer DEC terminals #30380

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/15054
Author: @j4james
Created: 3/28/2023
Status: Merged
Merged: 3/28/2023
Merged by: @DHowett

Base: mainHead: fix-decsc-decrc


📝 Commits (2)

  • 8bdd942 Update DECSC/DECRC to use level 4+ DEC algorithm.
  • 5d74ee5 Update unit tests to cover new algorithm.

📊 Changes

2 files changed (+14 additions, -22 deletions)

View changed files

📝 src/host/ut_host/ScreenBufferTests.cpp (+4 -4)
📝 src/terminal/adapter/adaptDispatch.cpp (+10 -18)

📄 Description

Summary of the Pull Request

When saving and restoring the cursor position with origin mode enabled,
we originally matched the behavior of the early DEC terminals, which
stored the position as an absolute offset. But if the margin boundaries
were changed prior to restoring the position, that could result in the
cursor being outside the margins, potentially with negative coordinates.

Our implementation avoided that bug by clamping the coordinates back
into range, but that's not how DEC ultimately fixed the issue. Starting
with the VT420, they began using relative coordinates (i.e. relative to
the margin origin), so a restored position could never end up negative.
This PR updates our implementation to match that newer behavior.

Validation Steps Performed

Thank to testing performed by @al20878, we know this was the algorithm
used on the VT420, VT520, and VT525, and I've manually confirmed that
our implementation now matches their behavior.

I've also updated the CursorSaveRestore unit test which previously
covered our clamping behavior - it's now being used to confirm that
we're correctly using relative offsets when restoring the cursor.

PR Checklist


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/15054 **Author:** [@j4james](https://github.com/j4james) **Created:** 3/28/2023 **Status:** ✅ Merged **Merged:** 3/28/2023 **Merged by:** [@DHowett](https://github.com/DHowett) **Base:** `main` ← **Head:** `fix-decsc-decrc` --- ### 📝 Commits (2) - [`8bdd942`](https://github.com/microsoft/terminal/commit/8bdd9420f73b60577cb7b42eda6555201e5a38ec) Update DECSC/DECRC to use level 4+ DEC algorithm. - [`5d74ee5`](https://github.com/microsoft/terminal/commit/5d74ee5325e72da5d862b17439428760d0d6e8db) Update unit tests to cover new algorithm. ### 📊 Changes **2 files changed** (+14 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+4 -4) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+10 -18) </details> ### 📄 Description ## Summary of the Pull Request When saving and restoring the cursor position with origin mode enabled, we originally matched the behavior of the early DEC terminals, which stored the position as an absolute offset. But if the margin boundaries were changed prior to restoring the position, that could result in the cursor being outside the margins, potentially with negative coordinates. Our implementation avoided that bug by clamping the coordinates back into range, but that's not how DEC ultimately fixed the issue. Starting with the VT420, they began using relative coordinates (i.e. relative to the margin origin), so a restored position could never end up negative. This PR updates our implementation to match that newer behavior. ## Validation Steps Performed Thank to testing performed by @al20878, we know this was the algorithm used on the VT420, VT520, and VT525, and I've manually confirmed that our implementation now matches their behavior. I've also updated the `CursorSaveRestore` unit test which previously covered our clamping behavior - it's now being used to confirm that we're correctly using relative offsets when restoring the cursor. ## PR Checklist - [x] Closes #15048 - [x] Tests added/passed - [ ] Documentation updated - [ ] Schema updated (if necessary) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:40:29 +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#30380