diff --git a/src/buffer/out/TextAttribute.cpp b/src/buffer/out/TextAttribute.cpp index 0c964b848e94..bdd2458a0f69 100644 --- a/src/buffer/out/TextAttribute.cpp +++ b/src/buffer/out/TextAttribute.cpp @@ -18,7 +18,7 @@ COLORREF TextAttribute::CalculateRgbForeground(std::basic_string_view COLORREF defaultFgColor, COLORREF defaultBgColor) const noexcept { - return _IsReverseVideo() ? _GetRgbBackground(colorTable, defaultBgColor) : _GetRgbForeground(colorTable, defaultFgColor); + return IsReverseVideo() ? _GetRgbBackground(colorTable, defaultBgColor) : _GetRgbForeground(colorTable, defaultFgColor); } // Routine Description: @@ -31,7 +31,33 @@ COLORREF TextAttribute::CalculateRgbBackground(std::basic_string_view COLORREF defaultFgColor, COLORREF defaultBgColor) const noexcept { - return _IsReverseVideo() ? _GetRgbForeground(colorTable, defaultFgColor) : _GetRgbBackground(colorTable, defaultBgColor); + return IsReverseVideo() ? _GetRgbForeground(colorTable, defaultFgColor) : _GetRgbBackground(colorTable, defaultBgColor); +} + +// Routine Description: +// - Makes this TextAttribute's foreground color the same as the other one. +// Arguments: +// - The TextAttribute to copy the foreground color from +// Return Value: +// - +void TextAttribute::SetForegroundFrom(const TextAttribute& other) noexcept +{ + _foreground = other._foreground; + WI_ClearAllFlags(_wAttrLegacy, FG_ATTRS); + _wAttrLegacy |= (other._wAttrLegacy & FG_ATTRS); +} + +// Routine Description: +// - Makes this TextAttribute's background color the same as the other one. +// Arguments: +// - The TextAttribute to copy the background color from +// Return Value: +// - +void TextAttribute::SetBackgroundFrom(const TextAttribute& other) noexcept +{ + _background = other._background; + WI_ClearAllFlags(_wAttrLegacy, BG_ATTRS); + _wAttrLegacy |= (other._wAttrLegacy & BG_ATTRS); } // Routine Description: @@ -160,7 +186,12 @@ bool TextAttribute::IsBold() const noexcept return _isBold; } -bool TextAttribute::_IsReverseVideo() const noexcept +bool TextAttribute::IsUnderline() const noexcept +{ + return IsBottomHorizontalDisplayed(); +} + +bool TextAttribute::IsReverseVideo() const noexcept { return WI_IsFlagSet(_wAttrLegacy, COMMON_LVB_REVERSE_VIDEO); } @@ -195,16 +226,21 @@ bool TextAttribute::IsRightVerticalDisplayed() const noexcept return WI_IsFlagSet(_wAttrLegacy, COMMON_LVB_GRID_RVERTICAL); } -void TextAttribute::SetLeftVerticalDisplayed(const bool isDisplayed) noexcept +void TextAttribute::SetLeftVerticalDisplayed(bool isDisplayed) noexcept { WI_UpdateFlag(_wAttrLegacy, COMMON_LVB_GRID_LVERTICAL, isDisplayed); } -void TextAttribute::SetRightVerticalDisplayed(const bool isDisplayed) noexcept +void TextAttribute::SetRightVerticalDisplayed(bool isDisplayed) noexcept { WI_UpdateFlag(_wAttrLegacy, COMMON_LVB_GRID_RVERTICAL, isDisplayed); } +void TextAttribute::SetBottomHorizontalDisplayed(bool isDisplayed) noexcept +{ + WI_UpdateFlag(_wAttrLegacy, COMMON_LVB_UNDERSCORE, isDisplayed); +} + void TextAttribute::Embolden() noexcept { _SetBoldness(true); @@ -215,6 +251,16 @@ void TextAttribute::Debolden() noexcept _SetBoldness(false); } +void TextAttribute::EnableUnderline() noexcept +{ + SetBottomHorizontalDisplayed(true); +} + +void TextAttribute::DisableUnderline() noexcept +{ + SetBottomHorizontalDisplayed(false); +} + // Routine Description: // - swaps foreground and background color void TextAttribute::Invert() noexcept diff --git a/src/buffer/out/TextAttribute.hpp b/src/buffer/out/TextAttribute.hpp index eb8cc6111dfa..d16ae8a88ae9 100644 --- a/src/buffer/out/TextAttribute.hpp +++ b/src/buffer/out/TextAttribute.hpp @@ -95,6 +95,9 @@ class TextAttribute final COLORREF defaultFgColor, COLORREF defaultBgColor) const noexcept; + void SetForegroundFrom(const TextAttribute& other) noexcept; + void SetBackgroundFrom(const TextAttribute& other) noexcept; + bool IsLeadingByte() const noexcept; bool IsTrailingByte() const noexcept; bool IsTopHorizontalDisplayed() const noexcept; @@ -102,8 +105,9 @@ class TextAttribute final bool IsLeftVerticalDisplayed() const noexcept; bool IsRightVerticalDisplayed() const noexcept; - void SetLeftVerticalDisplayed(const bool isDisplayed) noexcept; - void SetRightVerticalDisplayed(const bool isDisplayed) noexcept; + void SetLeftVerticalDisplayed(bool isDisplayed) noexcept; + void SetRightVerticalDisplayed(bool isDisplayed) noexcept; + void SetBottomHorizontalDisplayed(bool isDisplayed) noexcept; void SetFromLegacy(const WORD wLegacy) noexcept; @@ -120,6 +124,8 @@ class TextAttribute final void Embolden() noexcept; void Debolden() noexcept; + void EnableUnderline() noexcept; + void DisableUnderline() noexcept; void Invert() noexcept; @@ -132,6 +138,8 @@ class TextAttribute final bool IsLegacy() const noexcept; bool IsBold() const noexcept; + bool IsUnderline() const noexcept; + bool IsReverseVideo() const noexcept; void SetForeground(const COLORREF rgbForeground) noexcept; void SetBackground(const COLORREF rgbBackground) noexcept; @@ -153,7 +161,6 @@ class TextAttribute final COLORREF defaultColor) const noexcept; COLORREF _GetRgbBackground(std::basic_string_view colorTable, COLORREF defaultColor) const noexcept; - bool _IsReverseVideo() const noexcept; void _SetBoldness(const bool isBold) noexcept; WORD _wAttrLegacy; diff --git a/src/buffer/out/ut_textbuffer/TextAttributeTests.cpp b/src/buffer/out/ut_textbuffer/TextAttributeTests.cpp index da6d89ab65d5..ea1456f5c880 100644 --- a/src/buffer/out/ut_textbuffer/TextAttributeTests.cpp +++ b/src/buffer/out/ut_textbuffer/TextAttributeTests.cpp @@ -138,7 +138,7 @@ void TextAttributeTests::TestTextAttributeColorGetters() // verify that calculated foreground/background are the same as the direct // values when reverse video is not set - VERIFY_IS_FALSE(attr._IsReverseVideo()); + VERIFY_IS_FALSE(attr.IsReverseVideo()); VERIFY_ARE_EQUAL(red, attr._GetRgbForeground(view, _defaultFg)); VERIFY_ARE_EQUAL(red, attr.CalculateRgbForeground(view, _defaultFg, _defaultBg)); @@ -166,7 +166,7 @@ void TextAttributeTests::TestReverseDefaultColors() // verify that calculated foreground/background are the same as the direct // values when reverse video is not set - VERIFY_IS_FALSE(attr._IsReverseVideo()); + VERIFY_IS_FALSE(attr.IsReverseVideo()); VERIFY_ARE_EQUAL(_defaultFg, attr._GetRgbForeground(view, _defaultFg)); VERIFY_ARE_EQUAL(_defaultFg, attr.CalculateRgbForeground(view, _defaultFg, _defaultBg)); @@ -177,7 +177,7 @@ void TextAttributeTests::TestReverseDefaultColors() // with reverse video set, calucated foreground/background values should be // switched while getters stay the same attr.SetMetaAttributes(COMMON_LVB_REVERSE_VIDEO); - VERIFY_IS_TRUE(attr._IsReverseVideo()); + VERIFY_IS_TRUE(attr.IsReverseVideo()); VERIFY_ARE_EQUAL(_defaultFg, attr._GetRgbForeground(view, _defaultFg)); VERIFY_ARE_EQUAL(_defaultBg, attr.CalculateRgbForeground(view, _defaultFg, _defaultBg)); @@ -186,7 +186,7 @@ void TextAttributeTests::TestReverseDefaultColors() VERIFY_ARE_EQUAL(_defaultFg, attr.CalculateRgbBackground(view, _defaultFg, _defaultBg)); attr.SetForeground(red); - VERIFY_IS_TRUE(attr._IsReverseVideo()); + VERIFY_IS_TRUE(attr.IsReverseVideo()); VERIFY_ARE_EQUAL(red, attr._GetRgbForeground(view, _defaultFg)); VERIFY_ARE_EQUAL(_defaultBg, attr.CalculateRgbForeground(view, _defaultFg, _defaultBg)); @@ -195,7 +195,7 @@ void TextAttributeTests::TestReverseDefaultColors() VERIFY_ARE_EQUAL(red, attr.CalculateRgbBackground(view, _defaultFg, _defaultBg)); attr.Invert(); - VERIFY_IS_FALSE(attr._IsReverseVideo()); + VERIFY_IS_FALSE(attr.IsReverseVideo()); attr.SetDefaultForeground(); attr.SetBackground(green); diff --git a/src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj b/src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj index 2a0b48f38680..0dc21e602c49 100644 --- a/src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj +++ b/src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj @@ -46,6 +46,9 @@ {dcf55140-ef6a-4736-a403-957e4f7430bb} + + {0cf235bd-2da0-407e-90ee-c467e8bbc714} + {6AF01638-84CF-4B65-9870-484DFFCAC772} @@ -63,4 +66,4 @@ - \ No newline at end of file +