Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/TerminalSettings.cpp (C++)

Code before:
        _CursorShape = appearance.CursorShape();
        _CursorHeight = appearance.CursorHeight();
        // coming from UI or there is a bad colorscheme name
        if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName() && currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(2))
        {
            if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName()))
            {
                ApplyColorScheme(scheme);
            }
            else if (const auto defaultScheme = schemes.TryLookup(appearance.DarkColorSchemeName()))
            {
                ApplyColorScheme(defaultScheme);
            }
        }
        // coming from UI or there is a bad colorscheme name
        else if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName() && currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(1))
        {
            if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName()))
            {
                ApplyColorScheme(scheme);
            }
            else if (const auto defaultScheme = schemes.TryLookup(appearance.LightColorSchemeName()))
            {
                ApplyColorScheme(defaultScheme);
            }
        }
        // good color schemename
        else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(2))
        {
            if (!appearance.DarkColorSchemeName().empty())
            {
                if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName()))
                {
                    ApplyColorScheme(scheme);
                }
            }
        }
        // good color schemename
        else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(1))
        {
            if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName()))
            {
                ApplyColorScheme(scheme);
            }
        }
        // good color schemename, but default app theme (apps way of saying check the system theme). This diverts to checking system theme
        else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(0) && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark)
        {
            if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName()))
            {
                ApplyColorScheme(scheme);

Review comment (performance):
I think you might be able to use the same code deduplication technique here. Something along...
```cpp
const auto requestedTheme = currentTheme.RequestedTheme();
const auto defaultName = appearance.ColorSchemeName();
auto darkName = appearance.DarkColorSchemeName();
auto lightName = appearance.LightColorSchemeName();

if (!darkName)
{
    darkName = defaultName;
}
if (!lightName)
{
    lightName = defaultName;
}

const auto& chosenName = requestedTheme == ElementTheme::Dark ? darkName : lightName;

if (const auto scheme = schemes.TryLookup(chosenName))
{
    ApplyColorScheme(scheme);
}
```

I'm generally trying to avoid calling WinRT methods twice since cppwinrt is slow and bloaty.

Code after:
        static auto isColorLight = [](const Windows::UI::Color& clr) -> bool {
            return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
        };
        return isColorLight(Windows::UI::ViewManagement::UISettings().GetColorValue(Windows::UI::ViewManagement::UIColorType::Foreground));
    }

    void TerminalSettings::_ApplyAppearanceSettings(const IAppearanceConfig& appearance,
                                                    const Windows::Foundation::Collections::IMapView<winrt::hstring, ColorScheme>& schemes,
                                                    const winrt::Microsoft::Terminal::Settings::Model::Theme currentTheme)
    {
        _CursorShape = appearance.CursorShape();
        _CursorHeight = appearance.CursorHeight();

        auto requestedTheme = currentTheme.RequestedTheme();
        if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default)
        {
            requestedTheme = _isSystemInDarkTheme() ?
                                 winrt::Windows::UI::Xaml::ElementTheme::Dark :
                                 winrt::Windows::UI::Xaml::ElementTheme::Light;
        }

        switch (requestedTheme)
        {
        case winrt::Windows::UI::Xaml::ElementTheme::Light:
            if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName()))
            {
                ApplyColorScheme(scheme);
            }
            break;
        case winrt::Windows::UI::Xaml::ElementTheme::Dark:
            if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName()))
            {
                ApplyColorScheme(scheme);
            }
            break;
        case winrt::Windows::UI::Xaml::ElementTheme::Default:
            // This shouldn't happen!
            break;
        }

        if (appearance.Foreground())
        {
            _DefaultForeground = til::color{ appearance.Foreground().Value() };
        }
        if (appearance.Background())
        {
            _DefaultBackground = til::color{ appearance.Background().Value() };
        }
        if (appearance.SelectionBackground())
        {
            _SelectionBackground = til::color{ appearance.SelectionBackground().Value() };