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

Merge the legacy and extended attributes #14036

Merged
1 commit merged into from
Sep 20, 2022

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Sep 19, 2022

This PR attempts to simplify the TextAttribute class by merging the
two fields that were previously storing the "legacy" attributes and the
"extended" attributes separately.

When the TextAttribute class is initialized with a legacy value, we
were masking off the META_ATTRS bits to store in the _wAttrLegacy
field, and then additionally clearing the COMMON_LVB_SBCSDBCS bits,
so there were only 5 bits that were actually used in the end. We also
had an additional _extendedAttrs field holding other VT attributes,
which only used 8 of its available 16 bits.

In this PR I've now merged the the two sets of attributes into one enum,
so they all fit in a single 16-bit value. The legacy attributes retain
the same bit positions they originally had, so we can mask them off from
an incoming legacy value as we did before. I've just simplified the
process somewhat by creating a USED_META_ATTRS mask that covers the
exact subset of meta attributes that we care about.

The new enum that holds the combined attributes has now been named
CharacterAttributes rather than ExtendedAttributes, since that seems
to be the term typically used in VT documentation. This covers both
rendition/visual attributes and logical attributes (not yet used, but we
will need them at some point to support selective erase operations).

While making these changes I also noticed the IsLeadingByte and
IsTrailingByte methods weren't actually used anywhere, and weren't
correctly implemented anyway, so I've removed those now.

Validation Steps Performed

I've manually run a number of attribute test scripts which cover both
legacy and VT operations, and everything still appears to be working
correctly.

Closes #14031

@ghost ghost added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Sep 19, 2022
@j4james j4james marked this pull request as ready for review September 19, 2022 15:37
@@ -7,7 +7,7 @@

// Keeping TextColor compact helps us keeping TextAttribute compact,
// which in turn ensures that our buffer memory usage is low.
static_assert(sizeof(TextAttribute) == 14);
static_assert(sizeof(TextAttribute) == 12);
Copy link
Member

Choose a reason for hiding this comment

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

A memory savings of 2 megabytes, assuming that every column in every row in the default conhost buffer had 120 different attributes. 😁

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.

I'm 100% here for this. Thank you so much!

@lhecker lhecker added Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. and removed Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. labels Sep 20, 2022
@ghost
Copy link

ghost commented Sep 20, 2022

Hello @lhecker!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 1ce22a8 into microsoft:main Sep 20, 2022
@j4james j4james deleted the refactor-text-attributes branch October 11, 2022 08:57
@ghost
Copy link

ghost commented Jan 24, 2023

🎉Windows Terminal Preview v1.17.1023 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge the legacy and extended attributes
3 participants