Merge the legacy and extended attributes #18498

Open
opened 2026-01-31 06:15:53 +00:00 by claunia · 0 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?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18498