diff --git a/src/cascadia/TerminalSettingsModel/ColorScheme.cpp b/src/cascadia/TerminalSettingsModel/ColorScheme.cpp index 0d55c405b79..62f405e48fb 100644 --- a/src/cascadia/TerminalSettingsModel/ColorScheme.cpp +++ b/src/cascadia/TerminalSettingsModel/ColorScheme.cpp @@ -21,24 +21,30 @@ static constexpr std::string_view BackgroundKey{ "background" }; static constexpr std::string_view SelectionBackgroundKey{ "selectionBackground" }; static constexpr std::string_view CursorColorKey{ "cursorColor" }; -static constexpr std::array TableColors = { - "black", - "red", - "green", - "yellow", - "blue", - "purple", - "cyan", - "white", - "brightBlack", - "brightRed", - "brightGreen", - "brightYellow", - "brightBlue", - "brightPurple", - "brightCyan", - "brightWhite" -}; +static constexpr size_t ColorSchemeExpectedSize = 16; +static constexpr std::array, 18> TableColorsMapping{ { + // Primary color mappings + { "black", 0 }, + { "red", 1 }, + { "green", 2 }, + { "yellow", 3 }, + { "blue", 4 }, + { "purple", 5 }, + { "cyan", 6 }, + { "white", 7 }, + { "brightBlack", 8 }, + { "brightRed", 9 }, + { "brightGreen", 10 }, + { "brightYellow", 11 }, + { "brightBlue", 12 }, + { "brightPurple", 13 }, + { "brightCyan", 14 }, + { "brightWhite", 15 }, + + // Alternate color mappings (GH#11456) + { "magenta", 5 }, + { "brightMagenta", 13 }, +} }; ColorScheme::ColorScheme() noexcept : ColorScheme{ winrt::hstring{} } @@ -98,11 +104,18 @@ bool ColorScheme::_layerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, CursorColorKey, _CursorColor); // Required fields - for (unsigned int i = 0; i < TableColors.size(); ++i) + size_t colorCount = 0; + for (const auto& [key, index] : TableColorsMapping) { - isValid &= JsonUtils::GetValueForKey(json, til::at(TableColors, i), til::at(_table, i)); + colorCount += JsonUtils::GetValueForKey(json, key, til::at(_table, index)); + if (colorCount == ColorSchemeExpectedSize) + { + break; + } } + isValid &= (colorCount == 16); // Valid schemes should have exactly 16 colors + return isValid; } @@ -122,9 +135,10 @@ Json::Value ColorScheme::ToJson() const JsonUtils::SetValueForKey(json, SelectionBackgroundKey, _SelectionBackground); JsonUtils::SetValueForKey(json, CursorColorKey, _CursorColor); - for (unsigned int i = 0; i < TableColors.size(); ++i) + for (size_t i = 0; i < ColorSchemeExpectedSize; ++i) { - JsonUtils::SetValueForKey(json, til::at(TableColors, i), til::at(_table, i)); + const auto& key = til::at(TableColorsMapping, i).first; + JsonUtils::SetValueForKey(json, key, til::at(_table, i)); } return json;