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

Code before:
                }
            }
            // Elevate on NewTerminalArgs is an optional value, so the default
            // value (null) doesn't override a profile's value. Note that
            // elevate:false in an already elevated terminal does nothing - the
            // profile will still be launched elevated.
            if (newTerminalArgs.Elevate())
            {
                defaultSettings.Elevate(newTerminalArgs.Elevate().Value());
            }
        }

        return settingsPair;
    }

    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();

        const auto requestedTheme = currentTheme.RequestedTheme();
        const auto defaultName = appearance.ColorSchemeName();
        auto darkName = appearance.DarkColorSchemeName();
        auto lightName = appearance.LightColorSchemeName();

        // If the darkName does not equal the default name, it means the setting change came from the UI or its a bad name. Either will process the same.
        if (darkName != defaultName && requestedTheme != winrt::Windows::UI::Xaml::ElementTheme::Default)
        {
            // if this is a bad name, move on to checking the theme to select the proper default color scheme name.
            if (const auto scheme = schemes.TryLookup(defaultName))
            {
                ApplyColorScheme(scheme);
            }
            else
            {
                const auto& schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName;
                if (const auto scheme = schemes.TryLookup(schemeName))
                {
                    ApplyColorScheme(scheme);
                }
            }
        }
        // system theme selected, set the color scheme based off of the system theme.
        else if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default)
        {
            const auto& schemeName = Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark ? darkName : lightName;
            if (const auto scheme = schemes.TryLookup(schemeName))
            {
                ApplyColorScheme(scheme);

Review comment (suggestion):
```suggestion
        const auto darkName = appearance.DarkColorSchemeName();
        const auto lightName = appearance.LightColorSchemeName();
```

Code after:
                }
            }
            // Elevate on NewTerminalArgs is an optional value, so the default
            // value (null) doesn't override a profile's value. Note that
            // elevate:false in an already elevated terminal does nothing - the
            // profile will still be launched elevated.
            if (newTerminalArgs.Elevate())
            {
                defaultSettings.Elevate(newTerminalArgs.Elevate().Value());
            }
        }

        return settingsPair;
    }

    // I'm not even joking, this is the recommended way to do this:
    // https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes#know-when-dark-mode-is-enabled
    bool _isSystemInDarkTheme()
    {
        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()))
            {