Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable the setting to adjust the colors of indistinguishable text #13343

Merged
9 commits merged into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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", false)
X(bool, AdjustIndistinguishableColors, "adjustIndistinguishableColors", true)
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

// Intentionally omitted Appearance settings:
// * ForegroundKey, BackgroundKey, SelectionBackgroundKey, CursorColorKey: all optional colors
Expand Down
27 changes: 22 additions & 5 deletions src/renderer/base/RenderSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -79,15 +80,19 @@ 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<COLORREF, 18> colorTableWithDefaults;
std::array<COLORREF, 19> 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);
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

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)
{
Expand Down Expand Up @@ -203,18 +208,30 @@ std::pair<COLORREF, COLORREF> RenderSettings::GetAttributeColors(const TextAttri
if (Feature_AdjustIndistinguishableText::IsEnabled() &&
GetRenderMode(Mode::DistinguishableColors) &&
!dimFg &&
!brightenFg &&
!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 (brightenFg)
{
// There is a special case for intense here - we need to get the bright version of the foreground color
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
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/inc/RenderSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Microsoft::Console::Render
til::enumset<Mode> _renderMode{ Mode::BlinkAllowed, Mode::IntenseIsBright };
std::array<COLORREF, TextColor::TABLE_SIZE> _colorTable;
std::array<size_t, static_cast<size_t>(ColorAlias::ENUM_COUNT)> _colorAliasIndices;
std::array<std::array<COLORREF, 18>, 18> _adjustedForegroundColors;
std::array<std::array<COLORREF, 19>, 19> _adjustedForegroundColors;
size_t _blinkCycle = 0;
mutable bool _blinkIsInUse = false;
bool _blinkShouldBeFaint = false;
Expand Down
5 changes: 5 additions & 0 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

// 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
Expand Down