From 66c2a69d1d979164dad61b5d87217236a2b713d9 Mon Sep 17 00:00:00 2001 From: "Dan Thompson (SBS)" Date: Mon, 5 Aug 2019 22:39:38 -0700 Subject: [PATCH] Update TextAttribute operations to support XTPUSHSGR/XTPOPSGR. The XTPUSHSGR / XTPOPSGR control sequences support restoring just a portion of saved text attributes (such as "just the foreground color"). This commit introduces operations to support that. --- src/buffer/out/TextAttribute.cpp | 56 +++++++++++++++++-- src/buffer/out/TextAttribute.hpp | 14 ++++- .../out/ut_textbuffer/TextAttributeTests.cpp | 10 ++-- .../ut_adapter/Adapter.UnitTests.vcxproj | 3 + 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/buffer/out/TextAttribute.cpp b/src/buffer/out/TextAttribute.cpp index c6ac011543e..6006461aa4b 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: @@ -155,7 +181,12 @@ void TextAttribute::SetColor(const COLORREF rgbColor, const bool fIsForeground) } } -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); } @@ -190,16 +221,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); @@ -210,6 +246,16 @@ void TextAttribute::Debolden() noexcept _SetBoldness(false); } +void TextAttribute::EnableUnderline() noexcept +{ + SetBottomHorizontalDisplayed(true); +} + +void TextAttribute::DisableUnderline() noexcept +{ + SetBottomHorizontalDisplayed(false); +} + void TextAttribute::SetExtendedAttributes(const ExtendedAttributes attrs) noexcept { _extendedAttrs = attrs; diff --git a/src/buffer/out/TextAttribute.hpp b/src/buffer/out/TextAttribute.hpp index ff0bce8073f..3200e308d8e 100644 --- a/src/buffer/out/TextAttribute.hpp +++ b/src/buffer/out/TextAttribute.hpp @@ -97,6 +97,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; @@ -104,8 +107,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; @@ -122,6 +126,8 @@ class TextAttribute final void Embolden() noexcept; void Debolden() noexcept; + void EnableUnderline() noexcept; + void DisableUnderline() noexcept; void Invert() noexcept; @@ -139,6 +145,9 @@ class TextAttribute final return WI_IsFlagSet(_extendedAttrs, ExtendedAttributes::Bold); } + bool IsUnderline() const noexcept; + bool IsReverseVideo() const noexcept; + constexpr ExtendedAttributes GetExtendedAttributes() const noexcept { return _extendedAttrs; @@ -168,7 +177,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 da6d89ab65d..ea1456f5c88 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 f58693e6800..2e902c3fa47 100644 --- a/src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj +++ b/src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj @@ -54,6 +54,9 @@ {dcf55140-ef6a-4736-a403-957e4f7430bb} + + {0cf235bd-2da0-407e-90ee-c467e8bbc714} +