move out of text attribute

This commit is contained in:
Pankaj Bhojwani 2021-09-13 11:20:35 -07:00
parent fdd80177ba
commit 23445c7407
3 changed files with 44 additions and 43 deletions

View file

@ -104,38 +104,15 @@ std::pair<COLORREF, COLORREF> TextAttribute::CalculateRgbColors(const std::array
const COLORREF defaultBgColor,
const bool reverseScreenMode,
const bool blinkingIsFaint,
const bool boldIsBright,
const std::optional<std::array<std::array<COLORREF, 18>, 18>>& adjustedForegroundColors) const noexcept
const bool boldIsBright) const noexcept
{
COLORREF fg;
auto fg = _foreground.GetColor(colorTable, defaultFgColor, boldIsBright && IsBold());
auto bg = _background.GetColor(colorTable, defaultBgColor);
bool reversed{ false };
if (adjustedForegroundColors.has_value() &&
(_background.IsDefault() || _background.IsLegacy()) &&
(_foreground.IsDefault() || _foreground.IsLegacy()))
{
auto bgIndex = _background.IsDefault() ? 16 : _background.GetIndex();
auto fgIndex = _foreground.IsDefault() ? 17 : _foreground.GetIndex();
if (IsReverseVideo() ^ reverseScreenMode)
{
bg = _foreground.GetColor(colorTable, defaultFgColor);
fg = adjustedForegroundColors.value()[fgIndex][bgIndex];
reversed = true;
}
else
{
fg = adjustedForegroundColors.value()[bgIndex][fgIndex];
}
}
else
{
fg = _foreground.GetColor(colorTable, defaultFgColor, boldIsBright && IsBold());
}
if (IsFaint() || (IsBlinking() && blinkingIsFaint))
{
fg = (fg >> 1) & 0x7F7F7F; // Divide foreground color components by two.
}
if (IsReverseVideo() ^ reverseScreenMode && !reversed)
if (IsReverseVideo() ^ reverseScreenMode)
{
std::swap(fg, bg);
}

View file

@ -69,8 +69,7 @@ public:
const COLORREF defaultBgColor,
const bool reverseScreenMode = false,
const bool blinkingIsFaint = false,
const bool boldIsBright = true,
const std::optional<std::array<std::array<COLORREF, 18>, 18>>& adjustedForegroundColors = std::nullopt) const noexcept;
const bool boldIsBright = true) const noexcept;
bool IsLeadingByte() const noexcept;
bool IsTrailingByte() const noexcept;

View file

@ -45,22 +45,47 @@ const TextAttribute Terminal::GetDefaultBrushColors() noexcept
std::pair<COLORREF, COLORREF> Terminal::GetAttributeColors(const TextAttribute& attr) const noexcept
{
std::pair<COLORREF, COLORREF> colors;
_blinkingState.RecordBlinkingUsage(attr);
auto colors = _perceptualColorNudging ? attr.CalculateRgbColors(
_colorTable,
_defaultFg,
_defaultBg,
_screenReversed,
_blinkingState.IsBlinkingFaint(),
_intenseIsBright,
_adjustedForegroundColors) :
attr.CalculateRgbColors(
_colorTable,
_defaultFg,
_defaultBg,
_screenReversed,
_blinkingState.IsBlinkingFaint(),
_intenseIsBright);
const auto fgTextColor = attr.GetForeground();
const auto bgTextColor = attr.GetBackground();
// We want to nudge the foreground color to make it more perceivable only for the
// default color pairs within the color table
if (_perceptualColorNudging &&
!(attr.IsFaint() || (attr.IsBlinking() && _blinkingState.IsBlinkingFaint())) &&
(fgTextColor.IsDefault() || fgTextColor.IsLegacy()) &&
(bgTextColor.IsDefault() || bgTextColor.IsLegacy()))
{
auto bgIndex = bgTextColor.IsDefault() ? 16 : bgTextColor.GetIndex();
auto fgIndex = fgTextColor.IsDefault() ? 17 : fgTextColor.GetIndex();
if (fgTextColor.IsIndex16() && (fgIndex < 8) && attr.IsBold() && _intenseIsBright)
{
// There is a special case for bold here - we need to get the bright version of the foreground color
fgIndex += 8;
}
if (attr.IsReverseVideo() ^ _screenReversed)
{
colors.first = _adjustedForegroundColors[fgIndex][bgIndex];
colors.second = fgTextColor.GetColor(_colorTable, _defaultFg);
}
else
{
colors.first = _adjustedForegroundColors[bgIndex][fgIndex];
colors.second = bgTextColor.GetColor(_colorTable, _defaultBg);
}
}
else
{
colors = attr.CalculateRgbColors(_colorTable,
_defaultFg,
_defaultBg,
_screenReversed,
_blinkingState.IsBlinkingFaint(),
_intenseIsBright);
}
colors.first |= 0xff000000;
// We only care about alpha for the default BG (which enables acrylic)
// If the bg isn't the default bg color, or reverse video is enabled, make it fully opaque.