From ceeaadc3110c1b531db19c4ca9fa86d16a05f0ae Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 7 Jul 2020 12:01:42 -0500 Subject: [PATCH] Add some trace logging concerning which schemes are in use (#6803) ## Summary of the Pull Request Let's try and figure out just how many people are actually using Solarized. I emailed @DHowett about this a week ago, but otherwise we don't really have any other tasks for this. ## PR Checklist * [x] I work here * [n/a] Requires documentation to be updated --- src/cascadia/TerminalApp/CascadiaSettings.cpp | 27 +++++++++++++++++++ src/cascadia/TerminalApp/CascadiaSettings.h | 1 + src/cascadia/TerminalApp/Profile.cpp | 2 +- src/cascadia/TerminalApp/Profile.h | 2 +- src/cascadia/TerminalApp/TerminalPage.cpp | 8 ++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/CascadiaSettings.cpp b/src/cascadia/TerminalApp/CascadiaSettings.cpp index 9c8c709172..6a38214c47 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettings.cpp @@ -718,3 +718,30 @@ std::string CascadiaSettings::_ApplyFirstRunChangesToSettingsTemplate(std::strin return finalSettings; } + +// Method Description: +// - Lookup the color scheme for a given profile. If the profile doesn't exist, +// or the scheme name listed in the profile doesn't correspond to a scheme, +// this will return `nullptr`. +// Arguments: +// - profileGuid: the GUID of the profile to find the scheme for. +// Return Value: +// - a non-owning pointer to the scheme. +const ColorScheme* CascadiaSettings::GetColorSchemeForProfile(const GUID profileGuid) const +{ + auto* profile = FindProfile(profileGuid); + if (!profile) + { + return nullptr; + } + auto schemeName = profile->GetSchemeName().has_value() ? profile->GetSchemeName().value() : L"\0"; + auto scheme = _globals.GetColorSchemes().find(schemeName); + if (scheme != _globals.GetColorSchemes().end()) + { + return &scheme->second; + } + else + { + return nullptr; + } +} diff --git a/src/cascadia/TerminalApp/CascadiaSettings.h b/src/cascadia/TerminalApp/CascadiaSettings.h index 8bf65b926b..bed41c0d62 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.h +++ b/src/cascadia/TerminalApp/CascadiaSettings.h @@ -70,6 +70,7 @@ public: static std::filesystem::path GetDefaultSettingsPath(); const Profile* FindProfile(GUID profileGuid) const noexcept; + const ColorScheme* GetColorSchemeForProfile(const GUID profileGuid) const; std::vector& GetWarnings(); diff --git a/src/cascadia/TerminalApp/Profile.cpp b/src/cascadia/TerminalApp/Profile.cpp index 40c367c630..5ee40fd27a 100644 --- a/src/cascadia/TerminalApp/Profile.cpp +++ b/src/cascadia/TerminalApp/Profile.cpp @@ -551,7 +551,7 @@ void Profile::SetColorScheme(std::optional schemeName) noexcept _schemeName = std::move(schemeName); } -std::optional& Profile::GetSchemeName() noexcept +const std::optional& Profile::GetSchemeName() const noexcept { return _schemeName; } diff --git a/src/cascadia/TerminalApp/Profile.h b/src/cascadia/TerminalApp/Profile.h index 76518b4da3..bd48592157 100644 --- a/src/cascadia/TerminalApp/Profile.h +++ b/src/cascadia/TerminalApp/Profile.h @@ -71,7 +71,7 @@ public: void SetGuid(GUID guid) noexcept { _guid = guid; } void SetFontFace(std::wstring fontFace) noexcept; void SetColorScheme(std::optional schemeName) noexcept; - std::optional& GetSchemeName() noexcept; + const std::optional& GetSchemeName() const noexcept; void SetTabTitle(std::wstring tabTitle) noexcept; void SetSuppressApplicationTitle(bool suppressApplicationTitle) noexcept; void SetAcrylicOpacity(double opacity) noexcept; diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 829c363909..59fa97b499 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -554,6 +554,13 @@ namespace winrt::TerminalApp::implementation const bool usedManualProfile = (newTerminalArgs != nullptr) && (newTerminalArgs.ProfileIndex() != nullptr || newTerminalArgs.Profile().empty()); + + // Lookup the name of the color scheme used by this profile. + const auto* scheme = _settings->GetColorSchemeForProfile(profileGuid); + // If they explicitly specified `null` as the scheme (indicating _no_ scheme), log + // that as the empty string. + const auto schemeName = scheme ? scheme->GetName() : L"\0"; + TraceLoggingWrite( g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider "TabInformation", @@ -565,6 +572,7 @@ namespace winrt::TerminalApp::implementation TraceLoggingBool(settings.UseAcrylic(), "UseAcrylic", "The acrylic preference from the settings"), TraceLoggingFloat64(settings.TintOpacity(), "TintOpacity", "Opacity preference from the settings"), TraceLoggingWideString(settings.FontFace().c_str(), "FontFace", "Font face chosen in the settings"), + TraceLoggingWideString(schemeName.data(), "SchemeName", "Color scheme set in the settings"), TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance)); }