Compare commits

...

1 Commits

Author SHA1 Message Date
Leonard Hecker
5bfa47ec33 Simplify passing color tables 2023-08-29 19:15:35 +02:00
6 changed files with 68 additions and 112 deletions

View File

@@ -27,10 +27,25 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
return _ColorTable.at(index);
}
void SetColorTableEntry(int32_t index,
winrt::Microsoft::Terminal::Core::Color color) noexcept
winrt::Microsoft::Terminal::Core::Scheme ToCoreScheme() const noexcept
{
_ColorTable.at(index) = color;
winrt::Microsoft::Terminal::Core::Scheme coreScheme{};
coreScheme.Foreground = DefaultForeground();
coreScheme.Background = DefaultBackground();
coreScheme.CursorColor = CursorColor();
coreScheme.SelectionBackground = SelectionBackground();
std::copy_n(_ColorTable.data(), COLOR_TABLE_SIZE, &coreScheme.Black);
return coreScheme;
}
void ApplyCoreScheme(const winrt::Microsoft::Terminal::Core::Scheme& scheme) noexcept
{
_DefaultForeground = til::color{ scheme.Foreground };
_DefaultBackground = til::color{ scheme.Background };
_CursorColor = til::color{ scheme.CursorColor };
_SelectionBackground = til::color{ scheme.SelectionBackground };
std::copy_n(&scheme.Black, COLOR_TABLE_SIZE, _ColorTable.data());
}
ControlAppearance(Control::IControlAppearance appearance)

View File

@@ -2010,27 +2010,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// back.
if (HasUnfocusedAppearance())
{
s.Foreground = _settings->FocusedAppearance()->DefaultForeground();
s.Background = _settings->FocusedAppearance()->DefaultBackground();
s.CursorColor = _settings->FocusedAppearance()->CursorColor();
s.Black = _settings->FocusedAppearance()->GetColorTableEntry(0);
s.Red = _settings->FocusedAppearance()->GetColorTableEntry(1);
s.Green = _settings->FocusedAppearance()->GetColorTableEntry(2);
s.Yellow = _settings->FocusedAppearance()->GetColorTableEntry(3);
s.Blue = _settings->FocusedAppearance()->GetColorTableEntry(4);
s.Purple = _settings->FocusedAppearance()->GetColorTableEntry(5);
s.Cyan = _settings->FocusedAppearance()->GetColorTableEntry(6);
s.White = _settings->FocusedAppearance()->GetColorTableEntry(7);
s.BrightBlack = _settings->FocusedAppearance()->GetColorTableEntry(8);
s.BrightRed = _settings->FocusedAppearance()->GetColorTableEntry(9);
s.BrightGreen = _settings->FocusedAppearance()->GetColorTableEntry(10);
s.BrightYellow = _settings->FocusedAppearance()->GetColorTableEntry(11);
s.BrightBlue = _settings->FocusedAppearance()->GetColorTableEntry(12);
s.BrightPurple = _settings->FocusedAppearance()->GetColorTableEntry(13);
s.BrightCyan = _settings->FocusedAppearance()->GetColorTableEntry(14);
s.BrightWhite = _settings->FocusedAppearance()->GetColorTableEntry(15);
s = _settings->UnfocusedAppearance()->ToCoreScheme();
}
else
{
@@ -2057,34 +2037,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - <none>
void ControlCore::ColorScheme(const Core::Scheme& scheme)
{
auto l{ _terminal->LockForWriting() };
_settings->FocusedAppearance()->DefaultForeground(scheme.Foreground);
_settings->FocusedAppearance()->DefaultBackground(scheme.Background);
_settings->FocusedAppearance()->CursorColor(scheme.CursorColor);
_settings->FocusedAppearance()->SelectionBackground(scheme.SelectionBackground);
_settings->FocusedAppearance()->SetColorTableEntry(0, scheme.Black);
_settings->FocusedAppearance()->SetColorTableEntry(1, scheme.Red);
_settings->FocusedAppearance()->SetColorTableEntry(2, scheme.Green);
_settings->FocusedAppearance()->SetColorTableEntry(3, scheme.Yellow);
_settings->FocusedAppearance()->SetColorTableEntry(4, scheme.Blue);
_settings->FocusedAppearance()->SetColorTableEntry(5, scheme.Purple);
_settings->FocusedAppearance()->SetColorTableEntry(6, scheme.Cyan);
_settings->FocusedAppearance()->SetColorTableEntry(7, scheme.White);
_settings->FocusedAppearance()->SetColorTableEntry(8, scheme.BrightBlack);
_settings->FocusedAppearance()->SetColorTableEntry(9, scheme.BrightRed);
_settings->FocusedAppearance()->SetColorTableEntry(10, scheme.BrightGreen);
_settings->FocusedAppearance()->SetColorTableEntry(11, scheme.BrightYellow);
_settings->FocusedAppearance()->SetColorTableEntry(12, scheme.BrightBlue);
_settings->FocusedAppearance()->SetColorTableEntry(13, scheme.BrightPurple);
_settings->FocusedAppearance()->SetColorTableEntry(14, scheme.BrightCyan);
_settings->FocusedAppearance()->SetColorTableEntry(15, scheme.BrightWhite);
_settings->FocusedAppearance()->ApplyCoreScheme(scheme);
const auto lock = _terminal->LockForWriting();
_terminal->ApplyScheme(scheme);
_renderEngine->SetSelectionBackground(til::color{ _settings->SelectionBackground() });
_renderer->TriggerRedrawAll(true);
}

View File

@@ -1266,56 +1266,45 @@ void Microsoft::Terminal::Core::Terminal::CompletionsChangedCallback(std::functi
Scheme Terminal::GetColorScheme() const
{
Scheme s;
const auto& renderSettings = GetRenderSettings();
s.Foreground = til::color{ _renderSettings.GetColorAlias(ColorAlias::DefaultForeground) };
s.Background = til::color{ _renderSettings.GetColorAlias(ColorAlias::DefaultBackground) };
Scheme s;
s.Foreground = til::color{ renderSettings.GetColorAlias(ColorAlias::DefaultForeground) };
s.Background = til::color{ renderSettings.GetColorAlias(ColorAlias::DefaultBackground) };
// SelectionBackground is stored in the ControlAppearance
s.CursorColor = til::color{ _renderSettings.GetColorTableEntry(TextColor::CURSOR_COLOR) };
s.CursorColor = til::color{ renderSettings.GetColorTableEntry(TextColor::CURSOR_COLOR) };
auto target = &s.Black;
// Scheme stores the 16 basic VT colors as members, but they're conceptually a list. Their order is well defined.
#pragma warning(suppress : 26481) // Don't use pointer arithmetic. Use span instead (bounds.1).
for (size_t i = 0; i < 16; ++i, ++target)
{
*target = til::color{ renderSettings.GetColorTableEntry(i) };
}
s.Black = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_BLACK) };
s.Red = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_RED) };
s.Green = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_GREEN) };
s.Yellow = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_YELLOW) };
s.Blue = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_BLUE) };
s.Purple = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_MAGENTA) };
s.Cyan = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_CYAN) };
s.White = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_WHITE) };
s.BrightBlack = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_BLACK) };
s.BrightRed = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_RED) };
s.BrightGreen = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_GREEN) };
s.BrightYellow = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_YELLOW) };
s.BrightBlue = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_BLUE) };
s.BrightPurple = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_MAGENTA) };
s.BrightCyan = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_CYAN) };
s.BrightWhite = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_WHITE) };
return s;
}
void Terminal::ApplyScheme(const Scheme& colorScheme)
{
_renderSettings.SetColorAlias(ColorAlias::DefaultForeground, TextColor::DEFAULT_FOREGROUND, til::color{ colorScheme.Foreground });
_renderSettings.SetColorAlias(ColorAlias::DefaultBackground, TextColor::DEFAULT_BACKGROUND, til::color{ colorScheme.Background });
auto& renderSettings = GetRenderSettings();
_renderSettings.SetColorTableEntry(TextColor::DARK_BLACK, til::color{ colorScheme.Black });
_renderSettings.SetColorTableEntry(TextColor::DARK_RED, til::color{ colorScheme.Red });
_renderSettings.SetColorTableEntry(TextColor::DARK_GREEN, til::color{ colorScheme.Green });
_renderSettings.SetColorTableEntry(TextColor::DARK_YELLOW, til::color{ colorScheme.Yellow });
_renderSettings.SetColorTableEntry(TextColor::DARK_BLUE, til::color{ colorScheme.Blue });
_renderSettings.SetColorTableEntry(TextColor::DARK_MAGENTA, til::color{ colorScheme.Purple });
_renderSettings.SetColorTableEntry(TextColor::DARK_CYAN, til::color{ colorScheme.Cyan });
_renderSettings.SetColorTableEntry(TextColor::DARK_WHITE, til::color{ colorScheme.White });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_BLACK, til::color{ colorScheme.BrightBlack });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_RED, til::color{ colorScheme.BrightRed });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_GREEN, til::color{ colorScheme.BrightGreen });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_YELLOW, til::color{ colorScheme.BrightYellow });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_BLUE, til::color{ colorScheme.BrightBlue });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_MAGENTA, til::color{ colorScheme.BrightPurple });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_CYAN, til::color{ colorScheme.BrightCyan });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_WHITE, til::color{ colorScheme.BrightWhite });
renderSettings.SetColorAlias(ColorAlias::DefaultForeground, TextColor::DEFAULT_FOREGROUND, til::color{ colorScheme.Foreground });
renderSettings.SetColorAlias(ColorAlias::DefaultBackground, TextColor::DEFAULT_BACKGROUND, til::color{ colorScheme.Background });
_renderSettings.SetColorTableEntry(TextColor::CURSOR_COLOR, til::color{ colorScheme.CursorColor });
renderSettings.SetColorTableEntry(TextColor::CURSOR_COLOR, til::color{ colorScheme.CursorColor });
// Go home MSVC, you're drunk.
#pragma warning(suppress : 26429) // Symbol 'source' is never tested for nullness, it can be marked as not_null (f.23).
auto source = &colorScheme.Black;
// Scheme stores the 16 basic VT colors as members, but they're conceptually a list. Their order is well defined.
#pragma warning(suppress : 26481) // Don't use pointer arithmetic. Use span instead (bounds.1).
for (size_t i = 0; i < 16; ++i, ++source)
{
renderSettings.SetColorTableEntry(i, til::color{ *source });
}
// Tell the control that the scrollbar has somehow changed. Used as a
// workaround to force the control to redraw any scrollbar marks whose color

View File

@@ -164,27 +164,20 @@ void ColorScheme::SetColorTableEntry(uint8_t index, const Core::Color& value) no
winrt::Microsoft::Terminal::Core::Scheme ColorScheme::ToCoreScheme() const noexcept
{
winrt::Microsoft::Terminal::Core::Scheme coreScheme{};
coreScheme.Foreground = Foreground();
coreScheme.Background = Background();
coreScheme.CursorColor = CursorColor();
coreScheme.SelectionBackground = SelectionBackground();
coreScheme.Black = Table()[0];
coreScheme.Red = Table()[1];
coreScheme.Green = Table()[2];
coreScheme.Yellow = Table()[3];
coreScheme.Blue = Table()[4];
coreScheme.Purple = Table()[5];
coreScheme.Cyan = Table()[6];
coreScheme.White = Table()[7];
coreScheme.BrightBlack = Table()[8];
coreScheme.BrightRed = Table()[9];
coreScheme.BrightGreen = Table()[10];
coreScheme.BrightYellow = Table()[11];
coreScheme.BrightBlue = Table()[12];
coreScheme.BrightPurple = Table()[13];
coreScheme.BrightCyan = Table()[14];
coreScheme.BrightWhite = Table()[15];
return coreScheme;
Core::Scheme scheme{};
scheme.Foreground = Foreground();
scheme.Background = Background();
scheme.CursorColor = CursorColor();
scheme.SelectionBackground = SelectionBackground();
std::copy_n(_table.data(), COLOR_TABLE_SIZE, &scheme.Black);
return scheme;
}
void ColorScheme::ApplyCoreScheme(const Core::Scheme& scheme) noexcept
{
_Foreground = scheme.Foreground;
_Background = scheme.Background;
_CursorColor = scheme.CursorColor;
_SelectionBackground = scheme.SelectionBackground;
std::copy_n(&scheme.Black, COLOR_TABLE_SIZE, _table.data());
}

View File

@@ -46,7 +46,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static com_ptr<ColorScheme> FromJson(const Json::Value& json);
Json::Value ToJson() const;
winrt::Microsoft::Terminal::Core::Scheme ToCoreScheme() const noexcept;
Core::Scheme ToCoreScheme() const noexcept;
void ApplyCoreScheme(const Core::Scheme& scheme) noexcept;
com_array<Core::Color> Table() const noexcept;
void SetColorTableEntry(uint8_t index, const Core::Color& value) noexcept;

View File

@@ -21,5 +21,6 @@ namespace Microsoft.Terminal.Settings.Model
void SetColorTableEntry(UInt8 index, Microsoft.Terminal.Core.Color value);
Microsoft.Terminal.Core.Scheme ToCoreScheme();
void ApplyCoreScheme(Microsoft.Terminal.Core.Scheme scheme);
}
}