[PR #15269] Preserve active attributes during VT resize operations #30567

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

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

State: closed
Merged: Yes


Summary of the Pull Request

When the screen is resized in ConHost via a VT escape sequence, the
active text attributes could end up being corrupted if they were set to
something that the legacy console APIs didn't support (e.g. RGB colors).
This PR fixes that issue.

Detailed Description of the Pull Request / Additional comments

The way a resize is implemented is by retrieving the buffer information
with GetConsoleScreenBufferInfoEx, updating the size fields, and then
writing the data back out again with SetConsoleScreenBufferInfoEx.
However, this also results in the active attributes being updated via
the wAttributes field, and that's only capable of representing legacy
console attributes.

We address this by saving the full TextAttribute value before it gets
corrupted in the SetConsoleScreenBufferInfoEx call, and then restore
it again afterwards.

Validation Steps Performed

I've added a unit test to verify the attributes are correctly preserved
for all VT resize operations, and I've also manually confirmed the test
case in #2540 is now working as expected.

PR Checklist

**Original Pull Request:** https://github.com/microsoft/terminal/pull/15269 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request When the screen is resized in ConHost via a VT escape sequence, the active text attributes could end up being corrupted if they were set to something that the legacy console APIs didn't support (e.g. RGB colors). This PR fixes that issue. ## Detailed Description of the Pull Request / Additional comments The way a resize is implemented is by retrieving the buffer information with `GetConsoleScreenBufferInfoEx`, updating the size fields, and then writing the data back out again with `SetConsoleScreenBufferInfoEx`. However, this also results in the active attributes being updated via the `wAttributes` field, and that's only capable of representing legacy console attributes. We address this by saving the full `TextAttribute` value before it gets corrupted in the `SetConsoleScreenBufferInfoEx` call, and then restore it again afterwards. ## Validation Steps Performed I've added a unit test to verify the attributes are correctly preserved for all VT resize operations, and I've also manually confirmed the test case in #2540 is now working as expected. ## PR Checklist - [x] Closes #2540 - [x] Tests added/passed - [ ] Documentation updated - [ ] Schema updated (if necessary)
claunia added the pull-request label 2026-01-31 09:41:35 +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#30567