From 1aa2849d9426086db7587679725f859867447100 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 21 Oct 2021 15:53:22 -0500 Subject: [PATCH] you've seen WINRT_PROPERTY now get ready for RUNTIME_PROPERTY and as soon ad I typed that out I realized that WINRT_PROPERTY already has setters and setting an optional override gets me nothing sure I could stealth the new value in underneath the runtime value, so reloading the settings doesn't reset font size, colors, etc I could but it sure does feel like overkill for "refactor but don't change anything" --- .../TerminalControl/ControlAppearance.h | 29 +++++++++++++- src/cascadia/TerminalControl/ControlCore.cpp | 40 +++++++++---------- src/cascadia/TerminalControl/TermControl.cpp | 14 +++---- 3 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlAppearance.h b/src/cascadia/TerminalControl/ControlAppearance.h index b806a014d..85439840f 100644 --- a/src/cascadia/TerminalControl/ControlAppearance.h +++ b/src/cascadia/TerminalControl/ControlAppearance.h @@ -9,20 +9,45 @@ Licensed under the MIT license. #include #include +#define RUNTIME_PROPERTY(type, name, setting, ...) \ +private: \ + type _##name{ __VA_ARGS__ }; \ + std::optional _runtime##name{ std::nullopt }; \ + \ +public: \ + void name(const type newValue) { _runtime##name = newValue; } \ + \ + type name() const { return _runtime##name ? *_runtime##name : _##name; } + namespace winrt::Microsoft::Terminal::Control::implementation { struct ControlAppearance : public winrt::implements { -#define SETTINGS_GEN(type, name, ...) WINRT_PROPERTY(type, name, __VA_ARGS__); +#define SETTINGS_GEN(type, name, ...) RUNTIME_PROPERTY(type, name, __VA_ARGS__); CORE_APPEARANCE_SETTINGS(SETTINGS_GEN) CONTROL_APPEARANCE_SETTINGS(SETTINGS_GEN) #undef SETTINGS_GEN private: + // Color Table is special because it's an array std::array _ColorTable; + // Color table is _extra_ special because each individual color is + // overridable, not the whole array. + std::array, COLOR_TABLE_SIZE> _runtimeColorTable; + public: - winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept { return _ColorTable.at(index); } + winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept + { + return _runtimeColorTable.at(index) ? *_runtimeColorTable.at(index) : + _ColorTable.at(index); + } + void SetColorTableEntry(int32_t index, + winrt::Microsoft::Terminal::Core::Color color) noexcept + { + _runtimeColorTable.at(index) = color; + } + std::array ColorTable() { return _ColorTable; } void ColorTable(std::array /*colors*/) {} diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 6b851190f..e8f26e71d 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1610,10 +1610,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation { _terminal->ApplyScheme(scheme); - // _settings->FocusedAppearance()->DefaultForeground(colorScheme.Foreground); - // _settings->FocusedAppearance()->DefaultBackground(colorScheme.Background); - // _settings->FocusedAppearance()->CursorColor(colorScheme.CursorColor); - // _settings->FocusedAppearance()->SelectionBackground(colorScheme.SelectionBackground); + _settings->FocusedAppearance()->DefaultForeground(scheme.Foreground); + _settings->FocusedAppearance()->DefaultBackground(scheme.Background); + _settings->FocusedAppearance()->CursorColor(scheme.CursorColor); + _settings->FocusedAppearance()->SelectionBackground(scheme.SelectionBackground); // // _defaultFg = colorScheme.Foreground; // // // Set the default background as transparent to prevent the @@ -1621,22 +1621,22 @@ namespace winrt::Microsoft::Terminal::Control::implementation // // til::color newBackgroundColor{ colorScheme.Background }; // // _defaultBg = newBackgroundColor.with_alpha(0); - // _settings->FocusedAppearance()->Table()[0] = scheme.Black; - // _settings->FocusedAppearance()->Table()[1] = scheme.Red; - // _settings->FocusedAppearance()->Table()[2] = scheme.Green; - // _settings->FocusedAppearance()->Table()[3] = scheme.Yellow; - // _settings->FocusedAppearance()->Table()[4] = scheme.Blue; - // _settings->FocusedAppearance()->Table()[5] = scheme.Purple; - // _settings->FocusedAppearance()->Table()[6] = scheme.Cyan; - // _settings->FocusedAppearance()->Table()[7] = scheme.White; - // _settings->FocusedAppearance()->Table()[8] = scheme.BrightBlack; - // _settings->FocusedAppearance()->Table()[9] = scheme.BrightRed; - // _settings->FocusedAppearance()->Table()[10] = scheme.BrightGreen; - // _settings->FocusedAppearance()->Table()[11] = scheme.BrightYellow; - // _settings->FocusedAppearance()->Table()[12] = scheme.BrightBlue; - // _settings->FocusedAppearance()->Table()[13] = scheme.BrightPurple; - // _settings->FocusedAppearance()->Table()[14] = scheme.BrightCyan; - // _settings->FocusedAppearance()->Table()[15] = scheme.BrightWhite; + _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); // _buffer->GetCursor().SetColor(til::color{ colorScheme.CursorColor }); diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 22d70e09b..3d0e22e07 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -1501,13 +1501,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation _blinkTimer->Start(); } - // // Only update the appearance here if an unfocused config exists - - // // if an unfocused config does not exist then we never would have switched - // // appearances anyway so there's no need to switch back upon gaining focus - // if (_core.UnfocusedAppearance()) - // { - // UpdateAppearance(_core.FocusedAppearance()); - // } + // Only update the appearance here if an unfocused config exists - + // if an unfocused config does not exist then we never would have switched + // appearances anyway so there's no need to switch back upon gaining focus + if (_core.UnfocusedAppearance()) + { + UpdateAppearance(_core.FocusedAppearance()); + } } // Method Description: