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

Preserve active attributes during VT resize operations #15269

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Apr 30, 2023

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

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-VT Virtual Terminal sequence support Priority-1 A description (P1) Product-Conhost For issues in the Console codebase labels Apr 30, 2023
@j4james j4james marked this pull request as ready for review April 30, 2023 02:54
@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label May 1, 2023
@zadjii-msft zadjii-msft added this to the Terminal v1.18 milestone May 1, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit 8c28e13 into microsoft:main May 2, 2023
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly short! I love fixes where the tests's bigger than the product code :D

@j4james j4james deleted the fix-attributes-on-resize branch May 30, 2023 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-VT Virtual Terminal sequence support AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Certain SGR attributes are not preserved after a resize sequence
4 participants