diff --git a/src/cascadia/TerminalSettingsModel/MTSMSettings.h b/src/cascadia/TerminalSettingsModel/MTSMSettings.h index c7abda9a29a..4e95a026d7d 100644 --- a/src/cascadia/TerminalSettingsModel/MTSMSettings.h +++ b/src/cascadia/TerminalSettingsModel/MTSMSettings.h @@ -110,7 +110,7 @@ Author(s): X(hstring, ColorSchemeName, "colorScheme", L"Campbell") \ X(hstring, BackgroundImagePath, "backgroundImage") \ X(Model::IntenseStyle, IntenseTextStyle, "intenseTextStyle", Model::IntenseStyle::Bright) \ - X(bool, AdjustIndistinguishableColors, "adjustIndistinguishableColors", true) + X(bool, AdjustIndistinguishableColors, "adjustIndistinguishableColors", false) // Intentionally omitted Appearance settings: // * ForegroundKey, BackgroundKey, SelectionBackgroundKey, CursorColorKey: all optional colors diff --git a/src/features.xml b/src/features.xml index a8db865ddc7..00ca5a8bea0 100644 --- a/src/features.xml +++ b/src/features.xml @@ -79,10 +79,7 @@ Feature_AdjustIndistinguishableText If enabled, the foreground color will, when necessary, be automatically adjusted to make it more visible. - AlwaysDisabled - - Dev - + AlwaysEnabled diff --git a/src/renderer/base/RenderSettings.cpp b/src/renderer/base/RenderSettings.cpp index fab1f7dc10e..1e3aaed19c4 100644 --- a/src/renderer/base/RenderSettings.cpp +++ b/src/renderer/base/RenderSettings.cpp @@ -13,6 +13,7 @@ using Microsoft::Console::Utils::InitializeColorTable; static constexpr size_t AdjustedFgIndex{ 16 }; static constexpr size_t AdjustedBgIndex{ 17 }; +static constexpr size_t AdjustedBrightFgIndex{ 18 }; RenderSettings::RenderSettings() noexcept { @@ -77,17 +78,21 @@ void RenderSettings::ResetColorTable() noexcept // color pair to the adjusted foreground for that color pair void RenderSettings::MakeAdjustedColorArray() noexcept { - // The color table has 16 colors, but the adjusted color table needs to be 18 - // to include the default background and default foreground colors - std::array colorTableWithDefaults; + // The color table has 16 colors, but the adjusted color table needs to be 19 + // to include the default background, default foreground and bright default foreground colors + std::array colorTableWithDefaults; std::copy_n(std::begin(_colorTable), 16, std::begin(colorTableWithDefaults)); colorTableWithDefaults[AdjustedFgIndex] = GetColorAlias(ColorAlias::DefaultForeground); colorTableWithDefaults[AdjustedBgIndex] = GetColorAlias(ColorAlias::DefaultBackground); - for (auto fgIndex = 0; fgIndex < 18; ++fgIndex) + // We need to use TextColor to calculate the bright default fg + TextColor defaultFg; + colorTableWithDefaults[AdjustedBrightFgIndex] = defaultFg.GetColor(_colorTable, GetColorAliasIndex(ColorAlias::DefaultForeground), true); + + for (auto fgIndex = 0; fgIndex < 19; ++fgIndex) { const auto fg = til::at(colorTableWithDefaults, fgIndex); - for (auto bgIndex = 0; bgIndex < 18; ++bgIndex) + for (auto bgIndex = 0; bgIndex < 19; ++bgIndex) { if (fgIndex == bgIndex) { @@ -196,22 +201,30 @@ std::pair RenderSettings::GetAttributeColors(const TextAttri if (Feature_AdjustIndistinguishableText::IsEnabled() && GetRenderMode(Mode::DistinguishableColors) && !dimFg && + !attr.IsInvisible() && (fgTextColor.IsDefault() || fgTextColor.IsLegacy()) && (bgTextColor.IsDefault() || bgTextColor.IsLegacy())) { const auto bgIndex = bgTextColor.IsDefault() ? AdjustedBgIndex : bgTextColor.GetIndex(); auto fgIndex = fgTextColor.IsDefault() ? AdjustedFgIndex : fgTextColor.GetIndex(); - if (fgTextColor.IsIndex16() && (fgIndex < 8) && brightenFg) + if (brightenFg) { // There is a special case for intense here - we need to get the bright version of the foreground color - fgIndex += 8; + if (fgTextColor.IsIndex16() && (fgIndex < 8)) + { + fgIndex += 8; + } + else if (fgTextColor.IsDefault()) + { + fgIndex = AdjustedBrightFgIndex; + } } if (swapFgAndBg) { const auto fg = _adjustedForegroundColors[fgIndex][bgIndex]; - const auto bg = fgTextColor.GetColor(_colorTable, defaultFgIndex); + const auto bg = fgTextColor.GetColor(_colorTable, defaultFgIndex, brightenFg); return { fg, bg }; } else diff --git a/src/renderer/inc/RenderSettings.hpp b/src/renderer/inc/RenderSettings.hpp index 110075b2969..a201fad263d 100644 --- a/src/renderer/inc/RenderSettings.hpp +++ b/src/renderer/inc/RenderSettings.hpp @@ -47,7 +47,7 @@ namespace Microsoft::Console::Render til::enumset _renderMode{ Mode::BlinkAllowed, Mode::IntenseIsBright }; std::array _colorTable; std::array(ColorAlias::ENUM_COUNT)> _colorAliasIndices; - std::array, 18> _adjustedForegroundColors; + std::array, 19> _adjustedForegroundColors; size_t _blinkCycle = 0; mutable bool _blinkIsInUse = false; bool _blinkShouldBeFaint = false; diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index 6b2a7488ad7..3404f3b3c25 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2221,6 +2221,11 @@ bool AdaptDispatch::SetClipboard(const std::wstring_view content) bool AdaptDispatch::SetColorTableEntry(const size_t tableIndex, const DWORD dwColor) { _renderSettings.SetColorTableEntry(tableIndex, dwColor); + if (_renderSettings.GetRenderMode(RenderSettings::Mode::DistinguishableColors)) + { + // Re-calculate the adjusted colors now that one of the entries has been changed + _renderSettings.MakeAdjustedColorArray(); + } // If we're a conpty, always return false, so that we send the updated color // value to the terminal. Still handle the sequence so apps that use @@ -2286,6 +2291,11 @@ bool AdaptDispatch::AssignColor(const DispatchTypes::ColorItem item, const VTInt case DispatchTypes::ColorItem::NormalText: _renderSettings.SetColorAliasIndex(ColorAlias::DefaultForeground, fgIndex); _renderSettings.SetColorAliasIndex(ColorAlias::DefaultBackground, bgIndex); + if (_renderSettings.GetRenderMode(RenderSettings::Mode::DistinguishableColors)) + { + // Re-calculate the adjusted colors now that these aliases have been changed + _renderSettings.MakeAdjustedColorArray(); + } break; case DispatchTypes::ColorItem::WindowFrame: _renderSettings.SetColorAliasIndex(ColorAlias::FrameForeground, fgIndex);