Merge the legacy and extended attributes #18501

Closed
opened 2026-01-31 06:15:57 +00:00 by claunia · 4 comments
Owner

Originally created by @j4james on GitHub (Sep 18, 2022).

Description of the new feature/enhancement

In order to implement #14029, there was a need to add another bit in the ExtendedAttributes enum, and it occurred to me while looking at that code that it might be a good time to do something refactoring there first.

At the moment we've got two attribute fields in the TextAttribute class: _wAttrLegacy, which only uses 5 of its available 16 bits; and _extendedAttrs, which uses 8 of its available 16 bits. If we merged the two together into a single 16-bit field, we'd still have 3 bits to spare, and the TextAttribute class would be two bytes smaller.

Proposed technical implementation details (optional)

The idea would be to drop the legacy attributes, and replace the existing ExtendedAttributes enum with something like this:

enum class CharacterAttributes : uint16_t
{
    Normal = 0x00,
    Intense = 0x01,
    Italics = 0x02,
    Blinking = 0x04,
    Invisible = 0x08,
    CrossedOut = 0x10,
    Underlined = 0x20,
    DoublyUnderlined = 0x40,
    Faint = 0x80,
    Unused1 = 0x100,
    Unused2 = 0x200,
    TopGridline = COMMON_LVB_GRID_HORIZONTAL, // 0x400
    LeftGridline = COMMON_LVB_GRID_LVERTICAL, // 0x800
    RightGridline = COMMON_LVB_GRID_RVERTICAL, // 0x1000
    Unused3 = 0x2000,
    ReverseVideo = COMMON_LVB_REVERSE_VIDEO, // 0x4000
    BottomGridline = COMMON_LVB_UNDERSCORE // 0x8000
};

The added legacy bits are in the exact same position they were in the original field, so when initializing the TextAttribute class from a legacy value, we just have to mask out the relevant bits and write them directly to this field. Same approach works when converting from a TextAttribute back to a legacy value.

What do you think? Can I put together a PR with this change?

Originally created by @j4james on GitHub (Sep 18, 2022). # Description of the new feature/enhancement In order to implement #14029, there was a need to add another bit in the `ExtendedAttributes` enum, and it occurred to me while looking at that code that it might be a good time to do something refactoring there first. At the moment we've got two attribute fields in the `TextAttribute` class: `_wAttrLegacy`, which only uses 5 of its available 16 bits; and `_extendedAttrs`, which uses 8 of its available 16 bits. If we merged the two together into a single 16-bit field, we'd still have 3 bits to spare, and the `TextAttribute` class would be two bytes smaller. # Proposed technical implementation details (optional) The idea would be to drop the legacy attributes, and replace the existing [`ExtendedAttributes`](https://github.com/microsoft/terminal/blob/0d17769b89a77991ac26f3b24596c4262d9f9332/src/inc/conattrs.hpp#L11-L22) enum with something like this: ```cpp enum class CharacterAttributes : uint16_t { Normal = 0x00, Intense = 0x01, Italics = 0x02, Blinking = 0x04, Invisible = 0x08, CrossedOut = 0x10, Underlined = 0x20, DoublyUnderlined = 0x40, Faint = 0x80, Unused1 = 0x100, Unused2 = 0x200, TopGridline = COMMON_LVB_GRID_HORIZONTAL, // 0x400 LeftGridline = COMMON_LVB_GRID_LVERTICAL, // 0x800 RightGridline = COMMON_LVB_GRID_RVERTICAL, // 0x1000 Unused3 = 0x2000, ReverseVideo = COMMON_LVB_REVERSE_VIDEO, // 0x4000 BottomGridline = COMMON_LVB_UNDERSCORE // 0x8000 }; ``` The added legacy bits are in the exact same position they were in the original field, so when initializing the `TextAttribute` class from a legacy value, we just have to mask out the relevant bits and write them directly to this field. Same approach works when converting from a `TextAttribute` back to a legacy value. What do you think? Can I put together a PR with this change?
Author
Owner

@lhecker commented on GitHub (Sep 19, 2022):

I've considered merging them as well in the past, but simply haven't had time for it yet. I like it. 👍

@lhecker commented on GitHub (Sep 19, 2022): I've considered merging them as well in the past, but simply haven't had time for it yet. I like it. 👍
Author
Owner

@DHowett commented on GitHub (Sep 19, 2022):

This shouldn't impact our ability to expand it to 32 bits later, right?

As long as none of the legacy API operations are impacted (either by gaining new unexpected abilities or by losing them,) I'm totally cool with it. Thanks for proposing!

@DHowett commented on GitHub (Sep 19, 2022): This shouldn't impact our ability to expand it to 32 bits later, right? As long as none of the legacy API operations are impacted (either by gaining new unexpected abilities or by losing them,) I'm totally cool with it. Thanks for proposing!
Author
Owner

@j4james commented on GitHub (Sep 19, 2022):

This shouldn't impact our ability to expand it to 32 bits later, right?

I don't think so. We may have to reorder the fields to get the alignment right, but that shouldn't be an issue.

As long as none of the legacy API operations are impacted

Yeah, they shouldn't be. The code which handles the conversion to and from legacy attributes is almost identical to what it was before.

@j4james commented on GitHub (Sep 19, 2022): > This shouldn't impact our ability to expand it to 32 bits later, right? I don't think so. We may have to reorder the fields to get the alignment right, but that shouldn't be an issue. > As long as none of the legacy API operations are impacted Yeah, they shouldn't be. The code which handles the conversion to and from legacy attributes is almost identical to what it was before.
Author
Owner

@ghost commented on GitHub (Jan 24, 2023):

:tada:This issue was addressed in #14036, which has now been successfully released as Windows Terminal Preview v1.17.1023.🎉

Handy links:

@ghost commented on GitHub (Jan 24, 2023): :tada:This issue was addressed in #14036, which has now been successfully released as `Windows Terminal Preview v1.17.1023`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.17.1023) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18501