From a51091c615fe191c30512d358d6a5ce5241ca80c Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 27 Aug 2020 18:09:22 -0700 Subject: [PATCH] Make Profile a WinRT object (#7283) Profile is now a WinRT object in the TerminalApp project. As with ColorScheme, all of the serialization logic is not exposed via the idl. TerminalSetingsModel will handle it when it's all moved over. I removed the "Get" and "Set" prefixes from all of the Profile functions. It just makes more sense to use the `GETSET_PROPERTY` macro to do most of the work for us. `CloseOnExitMode` is now an enum off of the Profile.idl. `std::optional` got converted to `hstring` (as opposed to `IReference`). `IReference` is not valid to MIDL. ## References #7141 - Profile is a settings object #885 - this new settings object will be moved to a new TerminalSettingsModel project ## Validation Steps Performed - [x] Tests passed - [x] Deployment succeeded Closes #7435 --- .../LocalTests_TerminalApp/ProfileTests.cpp | 131 ++-- .../LocalTests_TerminalApp/SettingsTests.cpp | 651 +++++++++--------- src/cascadia/LocalTests_TerminalApp/pch.h | 17 +- .../TerminalApp/AzureCloudShellGenerator.cpp | 17 +- .../TerminalApp/AzureCloudShellGenerator.h | 4 +- src/cascadia/TerminalApp/CascadiaSettings.cpp | 87 +-- src/cascadia/TerminalApp/CascadiaSettings.h | 22 +- .../CascadiaSettingsSerialization.cpp | 32 +- src/cascadia/TerminalApp/Command.cpp | 6 +- src/cascadia/TerminalApp/Command.h | 4 +- .../TerminalApp/DefaultProfileUtils.cpp | 13 +- .../TerminalApp/DefaultProfileUtils.h | 2 +- .../TerminalApp/IDynamicProfileGenerator.h | 2 +- src/cascadia/TerminalApp/JsonUtils.h | 47 +- src/cascadia/TerminalApp/Pane.cpp | 6 +- .../PowershellCoreProfileGenerator.cpp | 19 +- .../PowershellCoreProfileGenerator.h | 2 +- src/cascadia/TerminalApp/Profile.cpp | 536 +++++--------- src/cascadia/TerminalApp/Profile.h | 222 +++--- src/cascadia/TerminalApp/Profile.idl | 70 ++ src/cascadia/TerminalApp/SettingsTypes.h | 7 - src/cascadia/TerminalApp/TelnetGenerator.h | 2 +- .../TerminalApp/TerminalAppLib.vcxproj | 9 +- .../TerminalAppLib.vcxproj.filters | 3 + src/cascadia/TerminalApp/TerminalPage.cpp | 42 +- src/cascadia/TerminalApp/TerminalPage.h | 2 +- .../TerminalSettingsSerializationHelpers.h | 4 +- .../TerminalApp/WslDistroGenerator.cpp | 13 +- src/cascadia/TerminalApp/WslDistroGenerator.h | 2 +- src/cascadia/ut_app/DynamicProfileTests.cpp | 344 ++++----- src/cascadia/ut_app/JsonTests.cpp | 40 +- .../ut_app/TestDynamicProfileGenerator.h | 6 +- src/cascadia/ut_app/precomp.h | 17 +- 33 files changed, 1158 insertions(+), 1223 deletions(-) create mode 100644 src/cascadia/TerminalApp/Profile.idl diff --git a/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp b/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp index c0064c6a3af..e3cf469f031 100644 --- a/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/ProfileTests.cpp @@ -9,6 +9,7 @@ using namespace Microsoft::Console; using namespace TerminalApp; +using namespace winrt::TerminalApp; using namespace WEX::Logging; using namespace WEX::TestExecution; using namespace WEX::Common; @@ -67,27 +68,27 @@ namespace TerminalAppLocalTests const auto profile2Json = VerifyParseSucceeded(profile2String); const auto profile3Json = VerifyParseSucceeded(profile3String); - const auto profile0 = Profile::FromJson(profile0Json); + const auto profile0 = implementation::Profile::FromJson(profile0Json); - VERIFY_IS_FALSE(profile0.ShouldBeLayered(profile1Json)); - VERIFY_IS_TRUE(profile0.ShouldBeLayered(profile2Json)); - VERIFY_IS_FALSE(profile0.ShouldBeLayered(profile3Json)); + VERIFY_IS_FALSE(profile0->ShouldBeLayered(profile1Json)); + VERIFY_IS_TRUE(profile0->ShouldBeLayered(profile2Json)); + VERIFY_IS_FALSE(profile0->ShouldBeLayered(profile3Json)); - const auto profile1 = Profile::FromJson(profile1Json); + const auto profile1 = implementation::Profile::FromJson(profile1Json); - VERIFY_IS_FALSE(profile1.ShouldBeLayered(profile0Json)); + VERIFY_IS_FALSE(profile1->ShouldBeLayered(profile0Json)); // A profile _can_ be layered with itself, though what's the point? - VERIFY_IS_TRUE(profile1.ShouldBeLayered(profile1Json)); - VERIFY_IS_FALSE(profile1.ShouldBeLayered(profile2Json)); - VERIFY_IS_FALSE(profile1.ShouldBeLayered(profile3Json)); + VERIFY_IS_TRUE(profile1->ShouldBeLayered(profile1Json)); + VERIFY_IS_FALSE(profile1->ShouldBeLayered(profile2Json)); + VERIFY_IS_FALSE(profile1->ShouldBeLayered(profile3Json)); - const auto profile3 = Profile::FromJson(profile3Json); + const auto profile3 = implementation::Profile::FromJson(profile3Json); - VERIFY_IS_FALSE(profile3.ShouldBeLayered(profile0Json)); + VERIFY_IS_FALSE(profile3->ShouldBeLayered(profile0Json)); // A profile _can_ be layered with itself, though what's the point? - VERIFY_IS_FALSE(profile3.ShouldBeLayered(profile1Json)); - VERIFY_IS_FALSE(profile3.ShouldBeLayered(profile2Json)); - VERIFY_IS_FALSE(profile3.ShouldBeLayered(profile3Json)); + VERIFY_IS_FALSE(profile3->ShouldBeLayered(profile1Json)); + VERIFY_IS_FALSE(profile3->ShouldBeLayered(profile2Json)); + VERIFY_IS_FALSE(profile3->ShouldBeLayered(profile3Json)); } void ProfileTests::LayerProfileProperties() @@ -116,55 +117,55 @@ namespace TerminalAppLocalTests const auto profile1Json = VerifyParseSucceeded(profile1String); const auto profile2Json = VerifyParseSucceeded(profile2String); - auto profile0 = Profile::FromJson(profile0Json); - VERIFY_IS_TRUE(profile0._defaultForeground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 0, 0, 0), profile0._defaultForeground.value()); + auto profile0 = implementation::Profile::FromJson(profile0Json); + VERIFY_IS_NOT_NULL(profile0->Foreground()); + VERIFY_ARE_EQUAL(til::color(0, 0, 0, 0), til::color{ profile0->Foreground().Value() }); - VERIFY_IS_TRUE(profile0._defaultBackground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 1, 1, 1), profile0._defaultBackground.value()); + VERIFY_IS_NOT_NULL(profile0->Background()); + VERIFY_ARE_EQUAL(til::color(1, 1, 1, 0), til::color{ profile0->Background().Value() }); - VERIFY_IS_TRUE(profile0._selectionBackground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 1, 1, 1), profile0._selectionBackground.value()); + VERIFY_IS_NOT_NULL(profile0->SelectionBackground()); + VERIFY_ARE_EQUAL(til::color(1, 1, 1, 0), til::color{ profile0->SelectionBackground().Value() }); - VERIFY_ARE_EQUAL(L"profile0", profile0._name); + VERIFY_ARE_EQUAL(L"profile0", profile0->Name()); - VERIFY_IS_FALSE(profile0._startingDirectory.has_value()); + VERIFY_IS_TRUE(profile0->StartingDirectory().empty()); Log::Comment(NoThrowString().Format( L"Layering profile1 on top of profile0")); - profile0.LayerJson(profile1Json); + profile0->LayerJson(profile1Json); - VERIFY_IS_TRUE(profile0._defaultForeground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 2, 2, 2), profile0._defaultForeground.value()); + VERIFY_IS_NOT_NULL(profile0->Foreground()); + VERIFY_ARE_EQUAL(til::color(2, 2, 2, 0), til::color{ profile0->Foreground().Value() }); - VERIFY_IS_TRUE(profile0._defaultBackground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 1, 1, 1), profile0._defaultBackground.value()); + VERIFY_IS_NOT_NULL(profile0->Background()); + VERIFY_ARE_EQUAL(til::color(1, 1, 1, 0), til::color{ profile0->Background().Value() }); - VERIFY_IS_TRUE(profile0._selectionBackground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 1, 1, 1), profile0._selectionBackground.value()); + VERIFY_IS_NOT_NULL(profile0->Background()); + VERIFY_ARE_EQUAL(til::color(1, 1, 1, 0), til::color{ profile0->Background().Value() }); - VERIFY_ARE_EQUAL(L"profile1", profile0._name); + VERIFY_ARE_EQUAL(L"profile1", profile0->Name()); - VERIFY_IS_TRUE(profile0._startingDirectory.has_value()); - VERIFY_ARE_EQUAL(L"C:/", profile0._startingDirectory.value()); + VERIFY_IS_FALSE(profile0->StartingDirectory().empty()); + VERIFY_ARE_EQUAL(L"C:/", profile0->StartingDirectory()); Log::Comment(NoThrowString().Format( L"Layering profile2 on top of (profile0+profile1)")); - profile0.LayerJson(profile2Json); + profile0->LayerJson(profile2Json); - VERIFY_IS_TRUE(profile0._defaultForeground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 3, 3, 3), profile0._defaultForeground.value()); + VERIFY_IS_NOT_NULL(profile0->Foreground()); + VERIFY_ARE_EQUAL(til::color(3, 3, 3, 0), til::color{ profile0->Foreground().Value() }); - VERIFY_IS_TRUE(profile0._defaultBackground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 1, 1, 1), profile0._defaultBackground.value()); + VERIFY_IS_NOT_NULL(profile0->Background()); + VERIFY_ARE_EQUAL(til::color(1, 1, 1, 0), til::color{ profile0->Background().Value() }); - VERIFY_IS_TRUE(profile0._selectionBackground.has_value()); - VERIFY_ARE_EQUAL(ARGB(0, 2, 2, 2), profile0._selectionBackground.value()); + VERIFY_IS_NOT_NULL(profile0->SelectionBackground()); + VERIFY_ARE_EQUAL(til::color(2, 2, 2, 0), til::color{ profile0->SelectionBackground().Value() }); - VERIFY_ARE_EQUAL(L"profile2", profile0._name); + VERIFY_ARE_EQUAL(L"profile2", profile0->Name()); - VERIFY_IS_TRUE(profile0._startingDirectory.has_value()); - VERIFY_ARE_EQUAL(L"C:/", profile0._startingDirectory.value()); + VERIFY_IS_FALSE(profile0->StartingDirectory().empty()); + VERIFY_ARE_EQUAL(L"C:/", profile0->StartingDirectory()); } void ProfileTests::LayerProfileIcon() @@ -194,33 +195,33 @@ namespace TerminalAppLocalTests const auto profile2Json = VerifyParseSucceeded(profile2String); const auto profile3Json = VerifyParseSucceeded(profile3String); - auto profile0 = Profile::FromJson(profile0Json); - VERIFY_IS_TRUE(profile0._icon.has_value()); - VERIFY_ARE_EQUAL(L"not-null.png", profile0._icon.value()); + auto profile0 = implementation::Profile::FromJson(profile0Json); + VERIFY_IS_FALSE(profile0->IconPath().empty()); + VERIFY_ARE_EQUAL(L"not-null.png", profile0->IconPath()); Log::Comment(NoThrowString().Format( L"Verify that layering an object the key set to null will clear the key")); - profile0.LayerJson(profile1Json); - VERIFY_IS_FALSE(profile0._icon.has_value()); + profile0->LayerJson(profile1Json); + VERIFY_IS_TRUE(profile0->IconPath().empty()); - profile0.LayerJson(profile2Json); - VERIFY_IS_FALSE(profile0._icon.has_value()); + profile0->LayerJson(profile2Json); + VERIFY_IS_TRUE(profile0->IconPath().empty()); - profile0.LayerJson(profile3Json); - VERIFY_IS_TRUE(profile0._icon.has_value()); - VERIFY_ARE_EQUAL(L"another-real.png", profile0._icon.value()); + profile0->LayerJson(profile3Json); + VERIFY_IS_FALSE(profile0->IconPath().empty()); + VERIFY_ARE_EQUAL(L"another-real.png", profile0->IconPath()); Log::Comment(NoThrowString().Format( L"Verify that layering an object _without_ the key will not clear the key")); - profile0.LayerJson(profile2Json); - VERIFY_IS_TRUE(profile0._icon.has_value()); - VERIFY_ARE_EQUAL(L"another-real.png", profile0._icon.value()); - - auto profile1 = Profile::FromJson(profile1Json); - VERIFY_IS_FALSE(profile1._icon.has_value()); - profile1.LayerJson(profile3Json); - VERIFY_IS_TRUE(profile1._icon.has_value()); - VERIFY_ARE_EQUAL(L"another-real.png", profile1._icon.value()); + profile0->LayerJson(profile2Json); + VERIFY_IS_FALSE(profile0->IconPath().empty()); + VERIFY_ARE_EQUAL(L"another-real.png", profile0->IconPath()); + + auto profile1 = implementation::Profile::FromJson(profile1Json); + VERIFY_IS_TRUE(profile1->IconPath().empty()); + profile1->LayerJson(profile3Json); + VERIFY_IS_FALSE(profile1->IconPath().empty()); + VERIFY_ARE_EQUAL(L"another-real.png", profile1->IconPath()); } void ProfileTests::LayerProfilesOnArray() @@ -284,7 +285,7 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile2Json)); VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile3Json)); VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile4Json)); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0)._name); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).Name()); settings._LayerOrCreateProfile(profile3Json); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); @@ -293,7 +294,7 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile2Json)); VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile3Json)); VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile4Json)); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(0)._name); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(0).Name()); settings._LayerOrCreateProfile(profile4Json); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); @@ -302,7 +303,7 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile2Json)); VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile3Json)); VERIFY_IS_NOT_NULL(settings._FindMatchingProfile(profile4Json)); - VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(0)._name); + VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(0).Name()); } } diff --git a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp index f72229526c0..e1dad5b8905 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -274,7 +274,7 @@ namespace TerminalAppLocalTests settings->_ValidateDefaultProfileExists(); VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.size()); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.size()); - VERIFY_ARE_EQUAL(settings->_globals.DefaultProfile(), settings->_profiles.at(0).GetGuid()); + VERIFY_ARE_EQUAL(winrt::guid{ settings->_globals.DefaultProfile() }, settings->_profiles.at(0).Guid()); } { // Case 2: Bad settings @@ -288,7 +288,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.at(0)); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.size()); - VERIFY_ARE_EQUAL(settings->_globals.DefaultProfile(), settings->_profiles.at(0).GetGuid()); + VERIFY_ARE_EQUAL(winrt::guid{ settings->_globals.DefaultProfile() }, settings->_profiles.at(0).Guid()); } { // Case 2: Bad settings @@ -302,7 +302,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingDefaultProfile, settings->_warnings.at(0)); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.size()); - VERIFY_ARE_EQUAL(settings->_globals.DefaultProfile(), settings->_profiles.at(0).GetGuid()); + VERIFY_ARE_EQUAL(winrt::guid{ settings->_globals.DefaultProfile() }, settings->_profiles.at(0).Guid()); } { // Case 4: Good settings, default profile is a string @@ -314,7 +314,7 @@ namespace TerminalAppLocalTests settings->_ValidateDefaultProfileExists(); VERIFY_ARE_EQUAL(static_cast(0), settings->_warnings.size()); VERIFY_ARE_EQUAL(static_cast(2), settings->_profiles.size()); - VERIFY_ARE_EQUAL(settings->_globals.DefaultProfile(), settings->_profiles.at(1).GetGuid()); + VERIFY_ARE_EQUAL(winrt::guid{ settings->_globals.DefaultProfile() }, settings->_profiles.at(1).Guid()); } } @@ -381,20 +381,20 @@ namespace TerminalAppLocalTests } ] })" }; - Profile profile0{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }; - profile0._name = L"profile0"; - Profile profile1{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }; - profile1._name = L"profile1"; - Profile profile2{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }; - profile2._name = L"profile2"; - Profile profile3{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }; - profile3._name = L"profile3"; - Profile profile4{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-6666-49a3-80bd-e8fdd045185c}") }; - profile4._name = L"profile4"; - Profile profile5{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }; - profile5._name = L"profile5"; - Profile profile6{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-7777-49a3-80bd-e8fdd045185c}") }; - profile6._name = L"profile6"; + Profile profile0 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }); + profile0.Name(L"profile0"); + Profile profile1 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }); + profile1.Name(L"profile1"); + Profile profile2 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }); + profile2.Name(L"profile2"); + Profile profile3 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }); + profile3.Name(L"profile3"); + Profile profile4 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-6666-49a3-80bd-e8fdd045185c}") }); + profile4.Name(L"profile4"); + Profile profile5 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }); + profile5.Name(L"profile5"); + Profile profile6 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-7777-49a3-80bd-e8fdd045185c}") }); + profile6.Name(L"profile6"); { // Case 1: Good settings @@ -425,7 +425,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings._warnings.at(0)); VERIFY_ARE_EQUAL(static_cast(1), settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).GetName()); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).Name()); } { // Case 3: Very bad settings @@ -447,10 +447,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::DuplicateProfile, settings._warnings.at(0)); VERIFY_ARE_EQUAL(static_cast(4), settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).GetName()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).GetName()); - VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(2).GetName()); - VERIFY_ARE_EQUAL(L"profile6", settings._profiles.at(3).GetName()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"profile6", settings._profiles.at(3).Name()); } } @@ -474,10 +474,10 @@ namespace TerminalAppLocalTests } ] })" }; - Profile profile4{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }; - profile4._name = L"profile4"; - Profile profile5{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }; - profile5._name = L"profile5"; + Profile profile4 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }); + profile4.Name(L"profile4"); + Profile profile5 = winrt::make(winrt::guid{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}") }); + profile5.Name(L"profile5"); // Case 2: Bad settings Log::Comment(NoThrowString().Format( @@ -496,10 +496,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::UnknownColorScheme, settings->_warnings.at(2)); VERIFY_ARE_EQUAL(3u, settings->_profiles.size()); - VERIFY_ARE_EQUAL(settings->_globals.DefaultProfile(), settings->_profiles.at(0).GetGuid()); - VERIFY_IS_TRUE(settings->_profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings->_profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings->_profiles.at(2)._guid.has_value()); + VERIFY_ARE_EQUAL(winrt::guid{ settings->_globals.DefaultProfile() }, settings->_profiles.at(0).Guid()); + VERIFY_IS_TRUE(settings->_profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings->_profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings->_profiles.at(2).HasGuid()); } void SettingsTests::LayerGlobalProperties() @@ -591,19 +591,19 @@ namespace TerminalAppLocalTests settings._ParseJsonString(defaultProfilesString, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1)._name); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1).Name()); settings._ParseJsonString(userProfiles0String, false); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1)._name); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1).Name()); settings._ReorderProfilesToMatchUserSettingsOrder(); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1)._name); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).Name()); } { @@ -614,21 +614,21 @@ namespace TerminalAppLocalTests settings._ParseJsonString(defaultProfilesString, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1)._name); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1).Name()); settings._ParseJsonString(userProfiles1String, false); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(2)._name); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(2).Name()); settings._ReorderProfilesToMatchUserSettingsOrder(); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(2)._name); + VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(2).Name()); } } @@ -692,24 +692,24 @@ namespace TerminalAppLocalTests settings._ParseJsonString(defaultProfilesString, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(false, settings._profiles.at(0)._hidden); - VERIFY_ARE_EQUAL(false, settings._profiles.at(1)._hidden); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(0).Hidden()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(1).Hidden()); settings._ParseJsonString(userProfiles0String, false); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(false, settings._profiles.at(0)._hidden); - VERIFY_ARE_EQUAL(true, settings._profiles.at(1)._hidden); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(0).Hidden()); + VERIFY_ARE_EQUAL(true, settings._profiles.at(1).Hidden()); settings._ReorderProfilesToMatchUserSettingsOrder(); settings._RemoveHiddenProfiles(); VERIFY_ARE_EQUAL(1u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(false, settings._profiles.at(0)._hidden); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(0).Hidden()); } { @@ -717,30 +717,30 @@ namespace TerminalAppLocalTests settings._ParseJsonString(defaultProfilesString, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(false, settings._profiles.at(0)._hidden); - VERIFY_ARE_EQUAL(false, settings._profiles.at(1)._hidden); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(0).Hidden()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(1).Hidden()); settings._ParseJsonString(userProfiles1String, false); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"profile6", settings._profiles.at(3)._name); - VERIFY_ARE_EQUAL(false, settings._profiles.at(0)._hidden); - VERIFY_ARE_EQUAL(true, settings._profiles.at(1)._hidden); - VERIFY_ARE_EQUAL(false, settings._profiles.at(2)._hidden); - VERIFY_ARE_EQUAL(true, settings._profiles.at(3)._hidden); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"profile6", settings._profiles.at(3).Name()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(0).Hidden()); + VERIFY_ARE_EQUAL(true, settings._profiles.at(1).Hidden()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(2).Hidden()); + VERIFY_ARE_EQUAL(true, settings._profiles.at(3).Hidden()); settings._ReorderProfilesToMatchUserSettingsOrder(); settings._RemoveHiddenProfiles(); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(false, settings._profiles.at(0)._hidden); - VERIFY_ARE_EQUAL(false, settings._profiles.at(1)._hidden); + VERIFY_ARE_EQUAL(L"profile5", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(0).Hidden()); + VERIFY_ARE_EQUAL(false, settings._profiles.at(1).Hidden()); } } @@ -781,62 +781,62 @@ namespace TerminalAppLocalTests const auto profile4Json = VerifyParseSucceeded(profile4String); const auto profile5Json = VerifyParseSucceeded(profile5String); - const auto profile0 = Profile::FromJson(profile0Json); - const auto profile1 = Profile::FromJson(profile1Json); - const auto profile2 = Profile::FromJson(profile2Json); - const auto profile3 = Profile::FromJson(profile3Json); - const auto profile4 = Profile::FromJson(profile4Json); - const auto profile5 = Profile::FromJson(profile5Json); + const auto profile0 = implementation::Profile::FromJson(profile0Json); + const auto profile1 = implementation::Profile::FromJson(profile1Json); + const auto profile2 = implementation::Profile::FromJson(profile2Json); + const auto profile3 = implementation::Profile::FromJson(profile3Json); + const auto profile4 = implementation::Profile::FromJson(profile4Json); + const auto profile5 = implementation::Profile::FromJson(profile5Json); - const GUID cmdGuid = Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}"); - const GUID nullGuid{ 0 }; + const winrt::guid cmdGuid{ Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}") }; + const winrt::guid nullGuid{}; - VERIFY_IS_FALSE(profile0._guid.has_value()); - VERIFY_IS_FALSE(profile1._guid.has_value()); - VERIFY_IS_FALSE(profile2._guid.has_value()); - VERIFY_IS_TRUE(profile3._guid.has_value()); - VERIFY_IS_TRUE(profile4._guid.has_value()); - VERIFY_IS_FALSE(profile5._guid.has_value()); + VERIFY_IS_FALSE(profile0->HasGuid()); + VERIFY_IS_FALSE(profile1->HasGuid()); + VERIFY_IS_FALSE(profile2->HasGuid()); + VERIFY_IS_TRUE(profile3->HasGuid()); + VERIFY_IS_TRUE(profile4->HasGuid()); + VERIFY_IS_FALSE(profile5->HasGuid()); - VERIFY_ARE_EQUAL(profile3.GetGuid(), nullGuid); - VERIFY_ARE_EQUAL(profile4.GetGuid(), cmdGuid); + VERIFY_ARE_EQUAL(profile3->Guid(), nullGuid); + VERIFY_ARE_EQUAL(profile4->Guid(), cmdGuid); CascadiaSettings settings; - settings._profiles.emplace_back(profile0); - settings._profiles.emplace_back(profile1); - settings._profiles.emplace_back(profile2); - settings._profiles.emplace_back(profile3); - settings._profiles.emplace_back(profile4); - settings._profiles.emplace_back(profile5); + settings._profiles.emplace_back(profile0.as()); + settings._profiles.emplace_back(profile1.as()); + settings._profiles.emplace_back(profile2.as()); + settings._profiles.emplace_back(profile3.as()); + settings._profiles.emplace_back(profile4.as()); + settings._profiles.emplace_back(profile5.as()); settings._ValidateProfilesHaveGuid(); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(4)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(5)._guid.has_value()); - - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).GetGuid(), nullGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1).GetGuid(), nullGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(2).GetGuid(), nullGuid); - VERIFY_ARE_EQUAL(settings._profiles.at(3).GetGuid(), nullGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(4).GetGuid(), nullGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(5).GetGuid(), nullGuid); - - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).GetGuid(), cmdGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1).GetGuid(), cmdGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(2).GetGuid(), cmdGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(3).GetGuid(), cmdGuid); - VERIFY_ARE_EQUAL(settings._profiles.at(4).GetGuid(), cmdGuid); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(5).GetGuid(), cmdGuid); - - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).GetGuid(), settings._profiles.at(2).GetGuid()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1).GetGuid(), settings._profiles.at(2).GetGuid()); - VERIFY_ARE_EQUAL(settings._profiles.at(2).GetGuid(), settings._profiles.at(2).GetGuid()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(3).GetGuid(), settings._profiles.at(2).GetGuid()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(4).GetGuid(), settings._profiles.at(2).GetGuid()); - VERIFY_ARE_EQUAL(settings._profiles.at(5).GetGuid(), settings._profiles.at(2).GetGuid()); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(3).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(4).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(5).HasGuid()); + + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).Guid(), nullGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1).Guid(), nullGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(2).Guid(), nullGuid); + VERIFY_ARE_EQUAL(settings._profiles.at(3).Guid(), nullGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(4).Guid(), nullGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(5).Guid(), nullGuid); + + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).Guid(), cmdGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1).Guid(), cmdGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(2).Guid(), cmdGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(3).Guid(), cmdGuid); + VERIFY_ARE_EQUAL(settings._profiles.at(4).Guid(), cmdGuid); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(5).Guid(), cmdGuid); + + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).Guid(), settings._profiles.at(2).Guid()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1).Guid(), settings._profiles.at(2).Guid()); + VERIFY_ARE_EQUAL(settings._profiles.at(2).Guid(), settings._profiles.at(2).Guid()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(3).Guid(), settings._profiles.at(2).Guid()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(4).Guid(), settings._profiles.at(2).Guid()); + VERIFY_ARE_EQUAL(settings._profiles.at(5).Guid(), settings._profiles.at(2).Guid()); } void SettingsTests::GeneratedGuidRoundtrips() @@ -850,28 +850,29 @@ namespace TerminalAppLocalTests })" }; const auto profile0Json = VerifyParseSucceeded(profileWithoutGuid); - const auto profile0 = Profile::FromJson(profile0Json); + const auto profile0 = implementation::Profile::FromJson(profile0Json); const GUID nullGuid{ 0 }; - VERIFY_IS_FALSE(profile0._guid.has_value()); + VERIFY_IS_FALSE(profile0->HasGuid()); - const auto serialized0Profile = profile0.GenerateStub(); - const auto profile1 = Profile::FromJson(serialized0Profile); - VERIFY_IS_FALSE(profile0._guid.has_value()); - VERIFY_ARE_EQUAL(profile1._guid.has_value(), profile0._guid.has_value()); + const auto serialized0Profile = profile0->GenerateStub(); + const auto profile1 = implementation::Profile::FromJson(serialized0Profile); + VERIFY_IS_FALSE(profile0->HasGuid()); + VERIFY_IS_FALSE(profile1->HasGuid()); CascadiaSettings settings; - settings._profiles.emplace_back(profile1); + settings._profiles.emplace_back(profile1.as()); settings._ValidateProfilesHaveGuid(); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); - const auto serialized1Profile = settings._profiles.at(0).GenerateStub(); + const auto profileImpl = winrt::get_self(settings._profiles.at(0)); + const auto serialized1Profile = profileImpl->GenerateStub(); - const auto profile2 = Profile::FromJson(serialized1Profile); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_ARE_EQUAL(settings._profiles.at(0)._guid.has_value(), profile2._guid.has_value()); - VERIFY_ARE_EQUAL(settings._profiles.at(0).GetGuid(), profile2.GetGuid()); + const auto profile2 = implementation::Profile::FromJson(serialized1Profile); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(profile2->HasGuid()); + VERIFY_ARE_EQUAL(settings._profiles.at(0).Guid(), profile2->Guid()); } void SettingsTests::TestAllValidationsWithNullGuids() @@ -900,14 +901,14 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(1)._guid.has_value()); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(1).HasGuid()); settings._ValidateSettings(); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); } void SettingsTests::TestReorderWithNullGuids() @@ -936,35 +937,35 @@ namespace TerminalAppLocalTests settings._ParseJsonString(DefaultJson, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1).Name()); settings._ParseJsonString(settings0String, false); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(3)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"cmdFromUserSettings", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(3)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(3).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"cmdFromUserSettings", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(3).Name()); settings._ValidateSettings(); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._guid.has_value()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"cmdFromUserSettings", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(3).HasGuid()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"cmdFromUserSettings", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3).Name()); } void SettingsTests::TestReorderingWithoutGuid() @@ -1037,35 +1038,35 @@ namespace TerminalAppLocalTests settings._ParseJsonString(DefaultJson, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1).Name()); settings._ParseJsonString(settings0String, false); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"ThisProfileShouldNotCrash", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"Ubuntu", settings._profiles.at(3)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(3).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileShouldNotCrash", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"Ubuntu", settings._profiles.at(3).Name()); settings._ValidateSettings(); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"ThisProfileShouldNotCrash", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"Ubuntu", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(3).HasGuid()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileShouldNotCrash", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"Ubuntu", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3).Name()); } void SettingsTests::TestLayeringNameOnlyProfiles() @@ -1098,10 +1099,10 @@ namespace TerminalAppLocalTests settings._ParseJsonString(DefaultJson, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1).Name()); Log::Comment(NoThrowString().Format( L"Parse the user settings")); @@ -1109,16 +1110,16 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(5u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(3)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(4)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"ThisProfileShouldNotLayer", settings._profiles.at(3)._name); - VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings._profiles.at(4)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(3).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(4).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileShouldNotLayer", settings._profiles.at(3).Name()); + VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings._profiles.at(4).Name()); } void SettingsTests::TestExplodingNameOnlyProfiles() @@ -1151,10 +1152,10 @@ namespace TerminalAppLocalTests settings._ParseJsonString(DefaultJson, true); settings.LayerJson(settings._defaultSettings); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1).Name()); Log::Comment(NoThrowString().Format( L"Parse the user settings")); @@ -1162,16 +1163,16 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(5u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(3)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(4)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"ThisProfileShouldNotDuplicate", settings._profiles.at(3)._name); - VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings._profiles.at(4)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(3).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(4).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileShouldNotDuplicate", settings._profiles.at(3).Name()); + VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings._profiles.at(4).Name()); Log::Comment(NoThrowString().Format( L"Pretend like we're checking to append dynamic profiles to the " @@ -1195,16 +1196,16 @@ namespace TerminalAppLocalTests settings2._ParseJsonString(firstSettingsString, false); settings2.LayerJson(settings2._userSettings); VERIFY_ARE_EQUAL(5u, settings2._profiles.size()); - VERIFY_IS_TRUE(settings2._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings2._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings2._profiles.at(2)._guid.has_value()); - VERIFY_IS_FALSE(settings2._profiles.at(3)._guid.has_value()); - VERIFY_IS_FALSE(settings2._profiles.at(4)._guid.has_value()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings2._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings2._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings2._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"ThisProfileShouldNotDuplicate", settings2._profiles.at(3)._name); - VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings2._profiles.at(4)._name); + VERIFY_IS_TRUE(settings2._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings2._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings2._profiles.at(2).HasGuid()); + VERIFY_IS_FALSE(settings2._profiles.at(3).HasGuid()); + VERIFY_IS_FALSE(settings2._profiles.at(4).HasGuid()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings2._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings2._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings2._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileShouldNotDuplicate", settings2._profiles.at(3).Name()); + VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings2._profiles.at(4).Name()); } Log::Comment(NoThrowString().Format( @@ -1212,16 +1213,16 @@ namespace TerminalAppLocalTests settings._ValidateSettings(); VERIFY_ARE_EQUAL(5u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(4)._guid.has_value()); - VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"ThisProfileShouldNotDuplicate", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3)._name); - VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(4)._name); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(3).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(4).HasGuid()); + VERIFY_ARE_EQUAL(L"ThisProfileIsGood", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"ThisProfileShouldNotDuplicate", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"NeitherShouldThisOne", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", settings._profiles.at(3).Name()); + VERIFY_ARE_EQUAL(L"Command Prompt", settings._profiles.at(4).Name()); } void SettingsTests::TestHideAllProfiles() @@ -1331,9 +1332,9 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings._profiles.size()); VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); - VERIFY_ARE_EQUAL(L"schemeOne", settings._profiles.at(0)._schemeName.value()); - VERIFY_ARE_EQUAL(L"InvalidSchemeName", settings._profiles.at(1)._schemeName.value()); - VERIFY_ARE_EQUAL(L"Campbell", settings._profiles.at(2)._schemeName.value()); + VERIFY_ARE_EQUAL(L"schemeOne", settings._profiles.at(0).ColorSchemeName()); + VERIFY_ARE_EQUAL(L"InvalidSchemeName", settings._profiles.at(1).ColorSchemeName()); + VERIFY_ARE_EQUAL(L"Campbell", settings._profiles.at(2).ColorSchemeName()); settings._ValidateAllSchemesExist(); @@ -1343,9 +1344,9 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings._profiles.size()); VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); - VERIFY_ARE_EQUAL(L"schemeOne", settings._profiles.at(0)._schemeName.value()); - VERIFY_ARE_EQUAL(L"Campbell", settings._profiles.at(1)._schemeName.value()); - VERIFY_ARE_EQUAL(L"Campbell", settings._profiles.at(2)._schemeName.value()); + VERIFY_ARE_EQUAL(L"schemeOne", settings._profiles.at(0).ColorSchemeName()); + VERIFY_ARE_EQUAL(L"Campbell", settings._profiles.at(1).ColorSchemeName()); + VERIFY_ARE_EQUAL(L"Campbell", settings._profiles.at(2).ColorSchemeName()); } void SettingsTests::TestHelperFunctions() @@ -1378,11 +1379,11 @@ namespace TerminalAppLocalTests auto name3{ L"ThisProfileShouldNotThrow" }; auto badName{ L"DoesNotExist" }; - auto guid0{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }; - auto guid1{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-6666-49a3-80bd-e8fdd045185c}") }; - auto guid2{ Microsoft::Console::Utils::GuidFromString(L"{2C4DE342-38B7-51CF-B940-2309A097F518}") }; - auto fakeGuid{ Microsoft::Console::Utils::GuidFromString(L"{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}") }; - std::optional badGuid{}; + winrt::guid guid0{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }; + winrt::guid guid1{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-6666-49a3-80bd-e8fdd045185c}") }; + winrt::guid guid2{ ::Microsoft::Console::Utils::GuidFromString(L"{2C4DE342-38B7-51CF-B940-2309A097F518}") }; + winrt::guid fakeGuid{ ::Microsoft::Console::Utils::GuidFromString(L"{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}") }; + std::optional badGuid{}; VerifyParseSucceeded(settings0String); @@ -1403,9 +1404,9 @@ namespace TerminalAppLocalTests auto badProf{ settings.FindProfile(fakeGuid) }; VERIFY_ARE_EQUAL(badProf, nullptr); - VERIFY_ARE_EQUAL(name0, prof0->GetName()); - VERIFY_ARE_EQUAL(name1, prof1->GetName()); - VERIFY_ARE_EQUAL(name2, prof2->GetName()); + VERIFY_ARE_EQUAL(name0, prof0.Name()); + VERIFY_ARE_EQUAL(name1, prof1.Name()); + VERIFY_ARE_EQUAL(name2, prof2.Name()); } void SettingsTests::TestProfileIconWithEnvVar() @@ -1450,7 +1451,8 @@ namespace TerminalAppLocalTests VERIFY_IS_FALSE(settings._profiles.empty()); GlobalAppSettings globalSettings{}; - auto terminalSettings = settings._profiles[0].CreateTerminalSettings(globalSettings.GetColorSchemes()); + const auto profileImpl = winrt::get_self(settings._profiles[0]); + auto terminalSettings = profileImpl->CreateTerminalSettings(globalSettings.GetColorSchemes()); VERIFY_ARE_EQUAL(expectedPath, terminalSettings.BackgroundImage()); } void SettingsTests::TestCloseOnExitParsing() @@ -1481,12 +1483,12 @@ namespace TerminalAppLocalTests CascadiaSettings settings{}; settings._ParseJsonString(settingsJson, false); settings.LayerJson(settings._userSettings); - VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings._profiles[0].GetCloseOnExitMode()); - VERIFY_ARE_EQUAL(CloseOnExitMode::Always, settings._profiles[1].GetCloseOnExitMode()); - VERIFY_ARE_EQUAL(CloseOnExitMode::Never, settings._profiles[2].GetCloseOnExitMode()); + VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings._profiles[0].CloseOnExit()); + VERIFY_ARE_EQUAL(CloseOnExitMode::Always, settings._profiles[1].CloseOnExit()); + VERIFY_ARE_EQUAL(CloseOnExitMode::Never, settings._profiles[2].CloseOnExit()); // Unknown modes parse as "Graceful" - VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings._profiles[3].GetCloseOnExitMode()); + VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings._profiles[3].CloseOnExit()); } void SettingsTests::TestCloseOnExitCompatibilityShim() { @@ -1508,8 +1510,8 @@ namespace TerminalAppLocalTests CascadiaSettings settings{}; settings._ParseJsonString(settingsJson, false); settings.LayerJson(settings._userSettings); - VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings._profiles[0].GetCloseOnExitMode()); - VERIFY_ARE_EQUAL(CloseOnExitMode::Never, settings._profiles[1].GetCloseOnExitMode()); + VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings._profiles[0].CloseOnExit()); + VERIFY_ARE_EQUAL(CloseOnExitMode::Never, settings._profiles[1].CloseOnExit()); } void SettingsTests::TestLayerUserDefaultsBeforeProfiles() @@ -1555,8 +1557,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(guid1String, settings._globals._unparsedDefaultProfile); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(2345, settings._profiles.at(0)._historySize); - VERIFY_ARE_EQUAL(1234, settings._profiles.at(1)._historySize); + VERIFY_ARE_EQUAL(2345, settings._profiles.at(0).HistorySize()); + VERIFY_ARE_EQUAL(1234, settings._profiles.at(1).HistorySize()); } } @@ -1589,8 +1591,8 @@ namespace TerminalAppLocalTests VerifyParseSucceeded(settings0String); const auto guid1String = L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"; - const auto guid1 = Microsoft::Console::Utils::GuidFromString(guid1String); - const auto guid2 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + const winrt::guid guid1{ ::Microsoft::Console::Utils::GuidFromString(guid1String) }; + const winrt::guid guid2{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}") }; { CascadiaSettings settings{ false }; @@ -1605,16 +1607,16 @@ namespace TerminalAppLocalTests Log::Comment(NoThrowString().Format( L"Ensure that cmd and powershell don't get their GUIDs overwritten")); - VERIFY_ARE_NOT_EQUAL(guid2, settings._profiles.at(0)._guid); - VERIFY_ARE_NOT_EQUAL(guid2, settings._profiles.at(1)._guid); + VERIFY_ARE_NOT_EQUAL(guid2, settings._profiles.at(0).Guid()); + VERIFY_ARE_NOT_EQUAL(guid2, settings._profiles.at(1).Guid()); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(guid1String, settings._globals._unparsedDefaultProfile); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_ARE_EQUAL(guid1, settings._profiles.at(2)._guid); - VERIFY_IS_FALSE(settings._profiles.at(3)._guid.has_value()); + VERIFY_ARE_EQUAL(guid1, settings._profiles.at(2).Guid()); + VERIFY_IS_FALSE(settings._profiles.at(3).HasGuid()); } } @@ -1627,9 +1629,9 @@ namespace TerminalAppLocalTests // settings in defaultSettings should apply _on top_ of settings from // dynamic profiles. - GUID guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - GUID guid2 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); - GUID guid3 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); + winrt::guid guid1{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}") }; + winrt::guid guid2{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}") }; + winrt::guid guid3{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}") }; const std::string userProfiles{ R"( { @@ -1662,21 +1664,22 @@ namespace TerminalAppLocalTests auto gen0 = std::make_unique(L"Terminal.App.UnitTest.0"); gen0->pfnGenerate = [guid1, guid2]() { std::vector profiles; - Profile p0{ guid1 }; - p0.SetName(L"profile0"); // this is _profiles.at(0) - p0._historySize = 1111; + Profile p0 = winrt::make(guid1); + p0.Name(L"profile0"); // this is _profiles.at(0) + p0.HistorySize(1111); profiles.push_back(p0); return profiles; }; auto gen1 = std::make_unique(L"Terminal.App.UnitTest.1"); gen1->pfnGenerate = [guid1, guid2]() { std::vector profiles; - Profile p0{ guid1 }, p1{ guid2 }; - p0.SetName(L"profile0"); // this is _profiles.at(1) - p1.SetName(L"profile1"); // this is _profiles.at(2) - p0._historySize = 2222; + Profile p0 = winrt::make(guid1); + Profile p1 = winrt::make(guid2); + p0.Name(L"profile0"); // this is _profiles.at(1) + p1.Name(L"profile1"); // this is _profiles.at(2) + p0.HistorySize(2222); profiles.push_back(p0); - p1._historySize = 3333; + p1.HistorySize(3333); profiles.push_back(p1); return profiles; }; @@ -1695,40 +1698,40 @@ namespace TerminalAppLocalTests settings._LoadDynamicProfiles(); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_ARE_EQUAL(1111, settings._profiles.at(0)._historySize); - VERIFY_ARE_EQUAL(2222, settings._profiles.at(1)._historySize); - VERIFY_ARE_EQUAL(3333, settings._profiles.at(2)._historySize); + VERIFY_ARE_EQUAL(1111, settings._profiles.at(0).HistorySize()); + VERIFY_ARE_EQUAL(2222, settings._profiles.at(1).HistorySize()); + VERIFY_ARE_EQUAL(3333, settings._profiles.at(2).HistorySize()); settings._ApplyDefaultsFromUserSettings(); - VERIFY_ARE_EQUAL(1234, settings._profiles.at(0)._historySize); - VERIFY_ARE_EQUAL(1234, settings._profiles.at(1)._historySize); - VERIFY_ARE_EQUAL(1234, settings._profiles.at(2)._historySize); + VERIFY_ARE_EQUAL(1234, settings._profiles.at(0).HistorySize()); + VERIFY_ARE_EQUAL(1234, settings._profiles.at(1).HistorySize()); + VERIFY_ARE_EQUAL(1234, settings._profiles.at(2).HistorySize()); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._source.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(3)._source.has_value()); + VERIFY_IS_FALSE(settings._profiles.at(0).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(1).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(2).Source().empty()); + VERIFY_IS_TRUE(settings._profiles.at(3).Source().empty()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.0", settings._profiles.at(0)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(2)._source.value()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.0", settings._profiles.at(0).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(2).Source()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); - VERIFY_ARE_EQUAL(guid1, settings._profiles.at(0)._guid.value()); - VERIFY_ARE_EQUAL(guid1, settings._profiles.at(1)._guid.value()); - VERIFY_ARE_EQUAL(guid2, settings._profiles.at(2)._guid.value()); + VERIFY_ARE_EQUAL(guid1, settings._profiles.at(0).Guid()); + VERIFY_ARE_EQUAL(guid1, settings._profiles.at(1).Guid()); + VERIFY_ARE_EQUAL(guid2, settings._profiles.at(2).Guid()); - VERIFY_ARE_EQUAL(L"profile0FromUserSettings", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile1FromUserSettings", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"profile2FromUserSettings", settings._profiles.at(3)._name); + VERIFY_ARE_EQUAL(L"profile0FromUserSettings", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile1FromUserSettings", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"profile2FromUserSettings", settings._profiles.at(3).Name()); Log::Comment(NoThrowString().Format( L"This is the real meat of the test: The two dynamic profiles that " @@ -1736,10 +1739,10 @@ namespace TerminalAppLocalTests L"1234 as their historySize(from the defaultSettings).The other two" L" profiles should have their custom historySize value.")); - VERIFY_ARE_EQUAL(1234, settings._profiles.at(0)._historySize); - VERIFY_ARE_EQUAL(1234, settings._profiles.at(1)._historySize); - VERIFY_ARE_EQUAL(4444, settings._profiles.at(2)._historySize); - VERIFY_ARE_EQUAL(5555, settings._profiles.at(3)._historySize); + VERIFY_ARE_EQUAL(1234, settings._profiles.at(0).HistorySize()); + VERIFY_ARE_EQUAL(1234, settings._profiles.at(1).HistorySize()); + VERIFY_ARE_EQUAL(4444, settings._profiles.at(2).HistorySize()); + VERIFY_ARE_EQUAL(5555, settings._profiles.at(3).HistorySize()); } void SettingsTests::TestTerminalArgsForBinding() @@ -1782,8 +1785,8 @@ namespace TerminalAppLocalTests ] })" }; - const auto guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); - const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + const winrt::guid guid0{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}") }; + const winrt::guid guid1{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}") }; VerifyParseSucceeded(settingsJson); CascadiaSettings settings{}; @@ -1794,8 +1797,8 @@ namespace TerminalAppLocalTests auto appKeyBindings = settings._globals._keybindings; VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - const auto profile2Guid = settings._profiles.at(2).GetGuid(); - VERIFY_ARE_NOT_EQUAL(GUID{ 0 }, profile2Guid); + const auto profile2Guid = settings._profiles.at(2).Guid(); + VERIFY_ARE_NOT_EQUAL(winrt::guid{}, profile2Guid); VERIFY_ARE_EQUAL(12u, appKeyBindings->_keyShortcuts.size()); @@ -2066,20 +2069,20 @@ namespace TerminalAppLocalTests const auto settingsJsonObj = VerifyParseSucceeded(settingsString); auto settings = CascadiaSettings::FromJson(settingsJsonObj); - const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - const auto guid2 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); - const auto guid3 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); + const auto guid1 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + const auto guid2 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + const auto guid3 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); - const Profile* const profile1 = settings->FindProfile(guid1); - const Profile* const profile2 = settings->FindProfile(guid2); - const Profile* const profile3 = settings->FindProfile(guid3); + const auto profile1 = settings->FindProfile(guid1); + const auto profile2 = settings->FindProfile(guid2); + const auto profile3 = settings->FindProfile(guid3); VERIFY_IS_NOT_NULL(profile1); VERIFY_IS_NOT_NULL(profile2); VERIFY_IS_NULL(profile3); - VERIFY_ARE_EQUAL(L"profile0", profile1->GetName()); - VERIFY_ARE_EQUAL(L"profile1", profile2->GetName()); + VERIFY_ARE_EQUAL(L"profile0", profile1.Name()); + VERIFY_ARE_EQUAL(L"profile1", profile2.Name()); } void SettingsTests::MakeSettingsForProfileThatDoesntExist() @@ -2105,9 +2108,9 @@ namespace TerminalAppLocalTests auto settings = CascadiaSettings::FromJson(settingsJsonObj); settings->_ResolveDefaultProfile(); - const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - const auto guid2 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); - const auto guid3 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); + const auto guid1 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + const auto guid2 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + const auto guid3 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); try { @@ -2173,7 +2176,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(2u, settings->_warnings.size()); VERIFY_ARE_EQUAL(2u, settings->_profiles.size()); - VERIFY_ARE_EQUAL(settings->_globals.DefaultProfile(), settings->_profiles.at(0).GetGuid()); + VERIFY_ARE_EQUAL(winrt::guid{ settings->_globals.DefaultProfile() }, settings->_profiles.at(0).Guid()); try { const auto [guid, termSettings] = settings->BuildSettings(nullptr); @@ -2240,12 +2243,12 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(6u, settings._profiles.size()); VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); - auto terminalSettings0 = settings._profiles[0].CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings1 = settings._profiles[1].CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings2 = settings._profiles[2].CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings3 = settings._profiles[3].CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings4 = settings._profiles[4].CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings5 = settings._profiles[5].CreateTerminalSettings(settings._globals._colorSchemes); + auto terminalSettings0 = winrt::get_self(settings._profiles[0])->CreateTerminalSettings(settings._globals._colorSchemes); + auto terminalSettings1 = winrt::get_self(settings._profiles[1])->CreateTerminalSettings(settings._globals._colorSchemes); + auto terminalSettings2 = winrt::get_self(settings._profiles[2])->CreateTerminalSettings(settings._globals._colorSchemes); + auto terminalSettings3 = winrt::get_self(settings._profiles[3])->CreateTerminalSettings(settings._globals._colorSchemes); + auto terminalSettings4 = winrt::get_self(settings._profiles[4])->CreateTerminalSettings(settings._globals._colorSchemes); + auto terminalSettings5 = winrt::get_self(settings._profiles[5])->CreateTerminalSettings(settings._globals._colorSchemes); VERIFY_ARE_EQUAL(ARGB(0, 0x12, 0x34, 0x56), terminalSettings0.CursorColor()); // from color scheme VERIFY_ARE_EQUAL(DEFAULT_CURSOR_COLOR, terminalSettings1.CursorColor()); // default @@ -2448,8 +2451,8 @@ namespace TerminalAppLocalTests ] })" }; - const auto guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); - const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + const auto guid0 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); + const auto guid1 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); VerifyParseSucceeded(settingsJson); CascadiaSettings settings{}; @@ -2459,8 +2462,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - const auto profile2Guid = settings._profiles.at(2).GetGuid(); - VERIFY_ARE_NOT_EQUAL(GUID{ 0 }, profile2Guid); + const auto profile2Guid = settings._profiles.at(2).Guid(); + VERIFY_ARE_NOT_EQUAL(winrt::guid{}, profile2Guid); auto appKeyBindings = settings._globals._keybindings; VERIFY_ARE_EQUAL(5u, appKeyBindings->_keyShortcuts.size()); @@ -2650,8 +2653,8 @@ namespace TerminalAppLocalTests "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. })" }; - const auto guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); - const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + const auto guid0 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); + const auto guid1 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); VerifyParseSucceeded(settingsJson); CascadiaSettings settings{}; @@ -2780,8 +2783,8 @@ namespace TerminalAppLocalTests "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. })" }; - const auto guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); - const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + const auto guid0 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); + const auto guid1 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); VerifyParseSucceeded(settingsJson); CascadiaSettings settings{}; @@ -2912,8 +2915,8 @@ namespace TerminalAppLocalTests "schemes": [ { "name": "Campbell" } ] // This is included here to prevent settings validation errors. })" }; - const auto guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); - const auto guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + const auto guid0 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); + const auto guid1 = ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); VerifyParseSucceeded(settingsJson); CascadiaSettings settings{}; diff --git a/src/cascadia/LocalTests_TerminalApp/pch.h b/src/cascadia/LocalTests_TerminalApp/pch.h index 6f134f00e4d..88e3ebcecca 100644 --- a/src/cascadia/LocalTests_TerminalApp/pch.h +++ b/src/cascadia/LocalTests_TerminalApp/pch.h @@ -15,6 +15,8 @@ Author(s): #pragma once +// Manually include til after we include Windows.Foundation to give it winrt superpowers +#define BLOCK_TIL // This includes support libraries from the CRT, STL, WIL, and GSL #include "LibraryIncludes.h" // This is inexplicable, but for whatever reason, cppwinrt conflicts with the @@ -33,12 +35,6 @@ Author(s): #include #include "consoletaeftemplates.hpp" -// Common includes for most tests: -#include "../../inc/argb.h" -#include "../../inc/conattrs.hpp" -#include "../../types/inc/utils.hpp" -#include "../../inc/DefaultSettings.h" - #include #include "winrt/Windows.UI.Xaml.Markup.h" #include @@ -63,3 +59,12 @@ Author(s): #include #include + +// Manually include til after we include Windows.Foundation to give it winrt superpowers +#include "til.h" + +// Common includes for most tests: +#include "../../inc/argb.h" +#include "../../inc/conattrs.hpp" +#include "../../types/inc/utils.hpp" +#include "../../inc/DefaultSettings.h" diff --git a/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp b/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp index b9e76dce7f0..5a5fc7ba150 100644 --- a/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp +++ b/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp @@ -14,6 +14,7 @@ #include "DefaultProfileUtils.h" using namespace ::TerminalApp; +using namespace winrt::TerminalApp; std::wstring_view AzureCloudShellGenerator::GetNamespace() { @@ -27,19 +28,19 @@ std::wstring_view AzureCloudShellGenerator::GetNamespace() // - // Return Value: // - a vector with the Azure Cloud Shell connection profile, if available. -std::vector AzureCloudShellGenerator::GenerateProfiles() +std::vector AzureCloudShellGenerator::GenerateProfiles() { - std::vector profiles; + std::vector profiles; if (winrt::Microsoft::Terminal::TerminalConnection::AzureConnection::IsAzureConnectionAvailable()) { auto azureCloudShellProfile{ CreateDefaultProfile(L"Azure Cloud Shell") }; - azureCloudShellProfile.SetCommandline(L"Azure"); - azureCloudShellProfile.SetStartingDirectory(DEFAULT_STARTING_DIRECTORY); - azureCloudShellProfile.SetColorScheme({ L"Vintage" }); - azureCloudShellProfile.SetAcrylicOpacity(0.6); - azureCloudShellProfile.SetUseAcrylic(true); - azureCloudShellProfile.SetConnectionType(AzureConnectionType); + azureCloudShellProfile.Commandline(L"Azure"); + azureCloudShellProfile.StartingDirectory(DEFAULT_STARTING_DIRECTORY); + azureCloudShellProfile.ColorSchemeName(L"Vintage"); + azureCloudShellProfile.AcrylicOpacity(0.6); + azureCloudShellProfile.UseAcrylic(true); + azureCloudShellProfile.ConnectionType(AzureConnectionType); profiles.emplace_back(azureCloudShellProfile); } diff --git a/src/cascadia/TerminalApp/AzureCloudShellGenerator.h b/src/cascadia/TerminalApp/AzureCloudShellGenerator.h index 3e752276d40..d624c856b47 100644 --- a/src/cascadia/TerminalApp/AzureCloudShellGenerator.h +++ b/src/cascadia/TerminalApp/AzureCloudShellGenerator.h @@ -18,7 +18,7 @@ Author(s): #pragma once #include "IDynamicProfileGenerator.h" -static constexpr GUID AzureConnectionType = { 0xd9fcfdfa, 0xa479, 0x412c, { 0x83, 0xb7, 0xc5, 0x64, 0xe, 0x61, 0xcd, 0x62 } }; +static constexpr winrt::guid AzureConnectionType = { 0xd9fcfdfa, 0xa479, 0x412c, { 0x83, 0xb7, 0xc5, 0x64, 0xe, 0x61, 0xcd, 0x62 } }; namespace TerminalApp { @@ -29,6 +29,6 @@ namespace TerminalApp ~AzureCloudShellGenerator() = default; std::wstring_view GetNamespace() override; - std::vector GenerateProfiles() override; + std::vector GenerateProfiles() override; }; }; diff --git a/src/cascadia/TerminalApp/CascadiaSettings.cpp b/src/cascadia/TerminalApp/CascadiaSettings.cpp index 2ecfa174543..4eda47ada1b 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettings.cpp @@ -70,15 +70,16 @@ CascadiaSettings::CascadiaSettings(const bool addDynamicProfiles) // Return Value: // - a non-ownership pointer to the profile matching the given guid, or nullptr // if there is no match. -const Profile* CascadiaSettings::FindProfile(GUID profileGuid) const noexcept +const Profile CascadiaSettings::FindProfile(winrt::guid profileGuid) const noexcept { + const winrt::guid guid{ profileGuid }; for (auto& profile : _profiles) { try { - if (profile.GetGuid() == profileGuid) + if (profile.Guid() == guid) { - return &profile; + return profile; } } CATCH_LOG(); @@ -215,7 +216,8 @@ void CascadiaSettings::_ValidateProfilesHaveGuid() { for (auto& profile : _profiles) { - profile.GenerateGuidIfNecessary(); + auto profileImpl = winrt::get_self(profile); + profileImpl->GenerateGuidIfNecessary(); } } @@ -228,7 +230,7 @@ void CascadiaSettings::_ResolveDefaultProfile() if (unparsedDefaultProfile) { auto maybeParsedDefaultProfile{ _GetProfileGuidByName(*unparsedDefaultProfile) }; - auto defaultProfileGuid{ til::coalesce_value(maybeParsedDefaultProfile, GUID{}) }; + auto defaultProfileGuid{ til::coalesce_value(maybeParsedDefaultProfile, winrt::guid{}) }; GlobalSettings().DefaultProfile(defaultProfileGuid); } } @@ -242,12 +244,12 @@ void CascadiaSettings::_ResolveDefaultProfile() // warnings if we failed to find the default. void CascadiaSettings::_ValidateDefaultProfileExists() { - const auto defaultProfileGuid = GlobalSettings().DefaultProfile(); - const bool nullDefaultProfile = defaultProfileGuid == GUID{}; + const winrt::guid defaultProfileGuid{ GlobalSettings().DefaultProfile() }; + const bool nullDefaultProfile = defaultProfileGuid == winrt::guid{}; bool defaultProfileNotInProfiles = true; for (const auto& profile : _profiles) { - if (profile.GetGuid() == defaultProfileGuid) + if (profile.Guid() == defaultProfileGuid) { defaultProfileNotInProfiles = false; break; @@ -261,7 +263,7 @@ void CascadiaSettings::_ValidateDefaultProfileExists() // _temporarily_ set the default profile to the first profile. Because // we're adding a warning, this settings change won't be re-serialized. - GlobalSettings().DefaultProfile(_profiles[0].GetGuid()); + GlobalSettings().DefaultProfile(_profiles[0].Guid()); } } @@ -277,13 +279,13 @@ void CascadiaSettings::_ValidateNoDuplicateProfiles() std::vector indicesToDelete; - std::set uniqueGuids; + std::set uniqueGuids; // Try collecting all the unique guids. If we ever encounter a guid that's // already in the set, then we need to delete that profile. for (size_t i = 0; i < _profiles.size(); i++) { - if (!uniqueGuids.insert(_profiles.at(i).GetGuid()).second) + if (!uniqueGuids.insert(_profiles.at(i).Guid()).second) { foundDupe = true; indicesToDelete.push_back(i); @@ -314,15 +316,15 @@ void CascadiaSettings::_ValidateNoDuplicateProfiles() // - void CascadiaSettings::_ReorderProfilesToMatchUserSettingsOrder() { - std::set uniqueGuids; - std::deque guidOrder; + std::set uniqueGuids; + std::deque guidOrder; auto collectGuids = [&](const auto& json) { for (auto profileJson : _GetProfilesJsonObject(json)) { if (profileJson.isObject()) { - auto guid = Profile::GetGuidOrGenerateForJson(profileJson); + auto guid = implementation::Profile::GetGuidOrGenerateForJson(profileJson); if (uniqueGuids.insert(guid).second) { guidOrder.push_back(guid); @@ -336,7 +338,7 @@ void CascadiaSettings::_ReorderProfilesToMatchUserSettingsOrder() // Push all the defaultSettings profiles' GUIDS into the set collectGuids(_defaultSettings); - std::equal_to equals; + std::equal_to equals; // Re-order the list of _profiles to match that ordering // for (gIndex=0 -> uniqueGuids.size) // pIndex = the pIndex of the profile with guid==guids[gIndex] @@ -347,7 +349,7 @@ void CascadiaSettings::_ReorderProfilesToMatchUserSettingsOrder() const auto guid = guidOrder.at(gIndex); for (size_t pIndex = gIndex; pIndex < _profiles.size(); pIndex++) { - auto profileGuid = _profiles.at(pIndex).GetGuid(); + auto profileGuid = _profiles.at(pIndex).Guid(); if (equals(profileGuid, guid)) { std::iter_swap(_profiles.begin() + pIndex, _profiles.begin() + gIndex); @@ -373,7 +375,7 @@ void CascadiaSettings::_RemoveHiddenProfiles() // idiom](https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom) _profiles.erase(std::remove_if(_profiles.begin(), _profiles.end(), - [](auto&& profile) { return profile.IsHidden(); }), + [](auto&& profile) { return profile.Hidden(); }), _profiles.end()); // Ensure that we still have some profiles here. If we don't, then throw an @@ -402,13 +404,13 @@ void CascadiaSettings::_ValidateAllSchemesExist() bool foundInvalidScheme = false; for (auto& profile : _profiles) { - auto schemeName = profile.GetSchemeName(); - if (schemeName.has_value()) + auto schemeName = profile.ColorSchemeName(); + if (!schemeName.empty()) { - const auto found = _globals.GetColorSchemes().find(schemeName.value()); + const auto found = _globals.GetColorSchemes().find(schemeName.c_str()); if (found == _globals.GetColorSchemes().end()) { - profile.SetColorScheme({ L"Campbell" }); + profile.ColorSchemeName({ L"Campbell" }); foundInvalidScheme = true; } } @@ -438,7 +440,7 @@ void CascadiaSettings::_ValidateMediaResources() for (auto& profile : _profiles) { - if (profile.HasBackgroundImage()) + if (!profile.BackgroundImagePath().empty()) { // Attempt to convert the path to a URI, the ctor will throw if it's invalid/unparseable. // This covers file paths on the machine, app data, URLs, and other resource paths. @@ -448,12 +450,13 @@ void CascadiaSettings::_ValidateMediaResources() } catch (...) { - profile.ResetBackgroundImagePath(); + // reset background image path + profile.BackgroundImagePath(L""); invalidBackground = true; } } - if (profile.HasIcon()) + if (!profile.IconPath().empty()) { try { @@ -461,7 +464,8 @@ void CascadiaSettings::_ValidateMediaResources() } catch (...) { - profile.ResetIconPath(); + // reset icon path + profile.IconPath(L""); invalidIcon = true; } } @@ -493,9 +497,9 @@ void CascadiaSettings::_ValidateMediaResources() // the profile. // Return Value: // - the GUID of the created profile, and a fully initialized TerminalSettings object -std::tuple CascadiaSettings::BuildSettings(const NewTerminalArgs& newTerminalArgs) const +std::tuple CascadiaSettings::BuildSettings(const NewTerminalArgs& newTerminalArgs) const { - const GUID profileGuid = _GetProfileForArgs(newTerminalArgs); + const winrt::guid profileGuid = _GetProfileForArgs(newTerminalArgs); auto settings = BuildSettings(profileGuid); if (newTerminalArgs) @@ -525,13 +529,14 @@ std::tuple CascadiaSettings::BuildSettings(const NewTerm // Arguments: // - profileGuid: The GUID of a profile to use to create a settings object for. // Return Value: -// - the GUID of the created profile, and a fully initialized TerminalSettings object -TerminalSettings CascadiaSettings::BuildSettings(GUID profileGuid) const +// - a fully initialized TerminalSettings object +TerminalSettings CascadiaSettings::BuildSettings(winrt::guid profileGuid) const { - const Profile* const profile = FindProfile(profileGuid); + const auto profile = FindProfile(profileGuid); THROW_HR_IF_NULL(E_INVALIDARG, profile); - TerminalSettings result = profile->CreateTerminalSettings(_globals.GetColorSchemes()); + const auto profileImpl = winrt::get_self(profile); + TerminalSettings result = profileImpl->CreateTerminalSettings(_globals.GetColorSchemes()); // Place our appropriate global settings into the Terminal Settings _globals.ApplyToSettings(result); @@ -555,9 +560,9 @@ TerminalSettings CascadiaSettings::BuildSettings(GUID profileGuid) const // and attempt to look the profile up by name instead. // Return Value: // - the GUID of the profile corresponding to this combination of index and NewTerminalArgs -GUID CascadiaSettings::_GetProfileForArgs(const NewTerminalArgs& newTerminalArgs) const +winrt::guid CascadiaSettings::_GetProfileForArgs(const NewTerminalArgs& newTerminalArgs) const { - std::optional profileByIndex, profileByName; + std::optional profileByIndex, profileByName; if (newTerminalArgs) { if (newTerminalArgs.ProfileIndex() != nullptr) @@ -577,7 +582,7 @@ GUID CascadiaSettings::_GetProfileForArgs(const NewTerminalArgs& newTerminalArgs // - name: a guid string _or_ the name of a profile // Return Value: // - the GUID of the profile corresponding to this name -std::optional CascadiaSettings::_GetProfileGuidByName(const std::wstring_view name) const +std::optional CascadiaSettings::_GetProfileGuidByName(const std::wstring_view name) const try { // First, try and parse the "name" as a GUID. If it's a @@ -602,12 +607,12 @@ try // lookup a profile. Instead, try using the string to look the // Profile up by name. const auto profileIterator{ std::find_if(_profiles.cbegin(), _profiles.cend(), [&](auto&& profile) { - return profile.GetName().compare(name) == 0; + return profile.Name() == name; }) }; if (profileIterator != _profiles.cend()) { - return profileIterator->GetGuid(); + return profileIterator->Guid(); } } @@ -629,7 +634,7 @@ catch (...) // If omitted, instead return the default profile's GUID // Return Value: // - the Nth profile's GUID, or the default profile's GUID -std::optional CascadiaSettings::_GetProfileGuidByIndex(std::optional index) const +std::optional CascadiaSettings::_GetProfileGuidByIndex(std::optional index) const { if (index) { @@ -639,7 +644,7 @@ std::optional CascadiaSettings::_GetProfileGuidByIndex(std::optional realIndex < gsl::narrow_cast(_profiles.size())) { const auto& selectedProfile = _profiles.at(realIndex); - return selectedProfile.GetGuid(); + return selectedProfile.Guid(); } } return std::nullopt; @@ -734,14 +739,14 @@ std::string CascadiaSettings::_ApplyFirstRunChangesToSettingsTemplate(std::strin // - 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 +const ColorScheme CascadiaSettings::GetColorSchemeForProfile(const winrt::guid profileGuid) const { - auto* profile = FindProfile(profileGuid); + auto profile = FindProfile(profileGuid); if (!profile) { return nullptr; } - auto schemeName = profile->GetSchemeName().has_value() ? profile->GetSchemeName().value() : L"\0"; + const std::wstring schemeName{ profile.ColorSchemeName() }; auto scheme = _globals.GetColorSchemes().find(schemeName); if (scheme != _globals.GetColorSchemes().end()) { diff --git a/src/cascadia/TerminalApp/CascadiaSettings.h b/src/cascadia/TerminalApp/CascadiaSettings.h index def568424f5..a64be8c364a 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.h +++ b/src/cascadia/TerminalApp/CascadiaSettings.h @@ -19,9 +19,9 @@ Author(s): #include #include "GlobalAppSettings.h" #include "TerminalWarnings.h" -#include "Profile.h" #include "IDynamicProfileGenerator.h" +#include "Profile.h" #include "ColorScheme.h" // fwdecl unittest classes @@ -64,12 +64,12 @@ class TerminalApp::CascadiaSettings final static const CascadiaSettings& GetCurrentAppSettings(); - std::tuple BuildSettings(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) const; - winrt::TerminalApp::TerminalSettings BuildSettings(GUID profileGuid) const; + std::tuple BuildSettings(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) const; + winrt::TerminalApp::TerminalSettings BuildSettings(winrt::guid profileGuid) const; GlobalAppSettings& GlobalSettings(); - gsl::span GetProfiles() const noexcept; + gsl::span GetProfiles() const noexcept; winrt::TerminalApp::AppKeyBindings GetKeybindings() const noexcept; @@ -79,8 +79,8 @@ class TerminalApp::CascadiaSettings final static std::filesystem::path GetSettingsPath(); static std::filesystem::path GetDefaultSettingsPath(); - const Profile* FindProfile(GUID profileGuid) const noexcept; - const winrt::TerminalApp::ColorScheme GetColorSchemeForProfile(const GUID profileGuid) const; + const winrt::TerminalApp::Profile FindProfile(winrt::guid profileGuid) const noexcept; + const winrt::TerminalApp::ColorScheme GetColorSchemeForProfile(const winrt::guid profileGuid) const; std::vector& GetWarnings(); @@ -88,7 +88,7 @@ class TerminalApp::CascadiaSettings final private: GlobalAppSettings _globals; - std::vector _profiles; + std::vector _profiles; std::vector _warnings; std::vector> _profileGenerators; @@ -99,7 +99,7 @@ class TerminalApp::CascadiaSettings final Json::Value _userDefaultProfileSettings{ Json::Value::null }; void _LayerOrCreateProfile(const Json::Value& profileJson); - Profile* _FindMatchingProfile(const Json::Value& profileJson); + winrt::com_ptr _FindMatchingProfile(const Json::Value& profileJson); void _LayerOrCreateColorScheme(const Json::Value& schemeJson); winrt::com_ptr _FindMatchingColorScheme(const Json::Value& schemeJson); void _ParseJsonString(std::string_view fileData, const bool isDefaultSettings); @@ -118,9 +118,9 @@ class TerminalApp::CascadiaSettings final static std::optional _ReadUserSettings(); static std::optional _ReadFile(HANDLE hFile); - std::optional _GetProfileGuidByName(const std::wstring_view) const; - std::optional _GetProfileGuidByIndex(std::optional index) const; - GUID _GetProfileForArgs(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) const; + std::optional _GetProfileGuidByName(const std::wstring_view) const; + std::optional _GetProfileGuidByIndex(std::optional index) const; + winrt::guid _GetProfileForArgs(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) const; void _ValidateSettings(); void _ValidateProfilesExist(); diff --git a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp index 33433a3b9eb..fe68f476602 100644 --- a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp @@ -327,7 +327,7 @@ void CascadiaSettings::_LoadDynamicProfiles() { // If the profile did not have a GUID when it was generated, // we'll synthesize a GUID for it in _ValidateProfilesHaveGuid - profile.SetSource(generatorNamespace); + profile.Source(generatorNamespace); _profiles.emplace_back(profile); } @@ -452,7 +452,8 @@ bool CascadiaSettings::_AppendDynamicProfilesToUserSettings() { if (profileJson.isObject()) { - if (profile.ShouldBeLayered(profileJson)) + const auto profileImpl = winrt::get_self(profile); + if (profileImpl->ShouldBeLayered(profileJson)) { return true; } @@ -502,7 +503,8 @@ bool CascadiaSettings::_AppendDynamicProfilesToUserSettings() // Generate a diff for the profile, that contains the minimal set of // changes to re-create this profile. - const auto diff = profile.GenerateStub(); + const auto profileImpl = winrt::get_self(profile); + const auto diff = profileImpl->GenerateStub(); auto profileSerialization = Json::writeString(wbuilder, diff); // Add the user's indent to the start of each line @@ -605,19 +607,19 @@ void CascadiaSettings::_LayerOrCreateProfile(const Json::Value& profileJson) // If this JSON represents a dynamic profile, we _shouldn't_ create the // profile here. We only want to create profiles for profiles without a // `source`. Dynamic profiles _must_ be layered on an existing profile. - if (!Profile::IsDynamicProfileObject(profileJson)) + if (!implementation::Profile::IsDynamicProfileObject(profileJson)) { - Profile profile{}; + auto profile = winrt::make_self(); // GH#2325: If we have a set of default profile settings, apply them here. // We _won't_ have these settings yet for defaults, dynamic profiles. if (_userDefaultProfileSettings) { - profile.LayerJson(_userDefaultProfileSettings); + profile->LayerJson(_userDefaultProfileSettings); } - profile.LayerJson(profileJson); - _profiles.emplace_back(profile); + profile->LayerJson(profileJson); + _profiles.emplace_back(*profile); } } } @@ -633,17 +635,14 @@ void CascadiaSettings::_LayerOrCreateProfile(const Json::Value& profileJson) // Return Value: // - a Profile that can be layered with the given json object, iff such a // profile exists. -Profile* CascadiaSettings::_FindMatchingProfile(const Json::Value& profileJson) +winrt::com_ptr CascadiaSettings::_FindMatchingProfile(const Json::Value& profileJson) { for (auto& profile : _profiles) { - if (profile.ShouldBeLayered(profileJson)) + auto profileImpl = winrt::get_self(profile); + if (profileImpl->ShouldBeLayered(profileJson)) { - // HERE BE DRAGONS: Returning a pointer to a type in the vector is - // maybe not the _safest_ thing, but we have a mind to make Profile - // and ColorScheme winrt types in the future, so this will be safer - // then. - return &profile; + return profileImpl->get_strong(); } } return nullptr; @@ -685,7 +684,8 @@ void CascadiaSettings::_ApplyDefaultsFromUserSettings() for (auto& profile : _profiles) { - profile.LayerJson(_userDefaultProfileSettings); + auto profileImpl = winrt::get_self(profile); + profileImpl->LayerJson(_userDefaultProfileSettings); } } } diff --git a/src/cascadia/TerminalApp/Command.cpp b/src/cascadia/TerminalApp/Command.cpp index 1eeadc21494..2c66cdf7dd4 100644 --- a/src/cascadia/TerminalApp/Command.cpp +++ b/src/cascadia/TerminalApp/Command.cpp @@ -353,7 +353,7 @@ namespace winrt::TerminalApp::implementation // Return Value: // - void Command::ExpandCommands(Windows::Foundation::Collections::IMap& commands, - gsl::span profiles, + gsl::span profiles, gsl::span schemes, std::vector<::TerminalApp::SettingsLoadWarnings>& warnings) { @@ -409,7 +409,7 @@ namespace winrt::TerminalApp::implementation // - and empty vector if the command wasn't expandable, otherwise a list of // the newly-created commands. std::vector Command::_expandCommand(Command* const expandable, - gsl::span profiles, + gsl::span profiles, gsl::span schemes, std::vector<::TerminalApp::SettingsLoadWarnings>& warnings) { @@ -466,7 +466,7 @@ namespace winrt::TerminalApp::implementation // Replace all the keywords in the original json, and try and parse that // - Escape the profile name for JSON appropriately - auto escapedProfileName = _escapeForJson(til::u16u8(p.GetName())); + auto escapedProfileName = _escapeForJson(til::u16u8(p.Name())); auto escapedProfileIcon = _escapeForJson(til::u16u8(p.GetExpandedIconPath())); auto newJsonString = til::replace_needle_in_haystack(oldJsonString, ProfileNameToken, diff --git a/src/cascadia/TerminalApp/Command.h b/src/cascadia/TerminalApp/Command.h index e7aa339a41c..c98f968c6b0 100644 --- a/src/cascadia/TerminalApp/Command.h +++ b/src/cascadia/TerminalApp/Command.h @@ -41,7 +41,7 @@ namespace winrt::TerminalApp::implementation std::vector<::TerminalApp::SettingsLoadWarnings>& warnings); static void ExpandCommands(Windows::Foundation::Collections::IMap& commands, - gsl::span profiles, + gsl::span profiles, gsl::span schemes, std::vector<::TerminalApp::SettingsLoadWarnings>& warnings); @@ -69,7 +69,7 @@ namespace winrt::TerminalApp::implementation winrt::hstring _lastIconPath{}; static std::vector _expandCommand(Command* const expandable, - gsl::span profiles, + gsl::span profiles, gsl::span schemes, std::vector<::TerminalApp::SettingsLoadWarnings>& warnings); friend class TerminalAppLocalTests::SettingsTests; diff --git a/src/cascadia/TerminalApp/DefaultProfileUtils.cpp b/src/cascadia/TerminalApp/DefaultProfileUtils.cpp index 02222fdcb61..18c59ef6e88 100644 --- a/src/cascadia/TerminalApp/DefaultProfileUtils.cpp +++ b/src/cascadia/TerminalApp/DefaultProfileUtils.cpp @@ -15,19 +15,18 @@ static constexpr std::wstring_view PACKAGED_PROFILE_ICON_EXTENSION{ L".png" }; // - name: the name of the new profile. // Return Value: // - A Profile, ready to be filled in -TerminalApp::Profile CreateDefaultProfile(const std::wstring_view name) +winrt::TerminalApp::Profile CreateDefaultProfile(const std::wstring_view name) { - const auto profileGuid{ Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, - gsl::as_bytes(gsl::make_span(name))) }; - TerminalApp::Profile newProfile{ profileGuid }; - - newProfile.SetName(name); + const winrt::guid profileGuid{ Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, + gsl::as_bytes(gsl::make_span(name))) }; + auto newProfile = winrt::make(profileGuid); + newProfile.Name(name); std::wstring iconPath{ PACKAGED_PROFILE_ICON_PATH }; iconPath.append(Microsoft::Console::Utils::GuidToString(profileGuid)); iconPath.append(PACKAGED_PROFILE_ICON_EXTENSION); - newProfile.SetIconPath(iconPath); + newProfile.IconPath(iconPath); return newProfile; } diff --git a/src/cascadia/TerminalApp/DefaultProfileUtils.h b/src/cascadia/TerminalApp/DefaultProfileUtils.h index 16d0f99deb1..c12b7169cf0 100644 --- a/src/cascadia/TerminalApp/DefaultProfileUtils.h +++ b/src/cascadia/TerminalApp/DefaultProfileUtils.h @@ -20,4 +20,4 @@ Author(s): // uuidv5 properties: name format is UTF-16LE bytes static constexpr GUID TERMINAL_PROFILE_NAMESPACE_GUID = { 0x2bde4a90, 0xd05f, 0x401c, { 0x94, 0x92, 0xe4, 0x8, 0x84, 0xea, 0xd1, 0xd8 } }; -TerminalApp::Profile CreateDefaultProfile(const std::wstring_view name); +winrt::TerminalApp::Profile CreateDefaultProfile(const std::wstring_view name); diff --git a/src/cascadia/TerminalApp/IDynamicProfileGenerator.h b/src/cascadia/TerminalApp/IDynamicProfileGenerator.h index 740ed483c1b..22940364a26 100644 --- a/src/cascadia/TerminalApp/IDynamicProfileGenerator.h +++ b/src/cascadia/TerminalApp/IDynamicProfileGenerator.h @@ -32,6 +32,6 @@ class TerminalApp::IDynamicProfileGenerator public: virtual ~IDynamicProfileGenerator() = 0; virtual std::wstring_view GetNamespace() = 0; - virtual std::vector GenerateProfiles() = 0; + virtual std::vector GenerateProfiles() = 0; }; inline TerminalApp::IDynamicProfileGenerator::~IDynamicProfileGenerator() {} diff --git a/src/cascadia/TerminalApp/JsonUtils.h b/src/cascadia/TerminalApp/JsonUtils.h index b75c58200e1..5e639ecc73a 100644 --- a/src/cascadia/TerminalApp/JsonUtils.h +++ b/src/cascadia/TerminalApp/JsonUtils.h @@ -67,6 +67,13 @@ namespace TerminalApp::JsonUtils using Type = typename std::decay::type; static constexpr bool IsOptional = true; }; + + template<> + struct DeduceOptional<::winrt::hstring> + { + using Type = typename ::winrt::hstring; + static constexpr bool IsOptional = true; + }; } class DeserializationError : public std::runtime_error @@ -269,10 +276,25 @@ namespace TerminalApp::JsonUtils } }; - // (GUID and winrt::guid are mutually convertible!) + // GUID and winrt::guid are mutually convertible, + // but IReference throws some of this off template<> - struct ConversionTrait : public ConversionTrait + struct ConversionTrait { + winrt::guid FromJson(const Json::Value& json) const + { + return static_cast(ConversionTrait{}.FromJson(json)); + } + + bool CanConvert(const Json::Value& json) const + { + return ConversionTrait{}.CanConvert(json); + } + + std::string TypeDescription() const + { + return ConversionTrait{}.TypeDescription(); + } }; template<> @@ -300,6 +322,27 @@ namespace TerminalApp::JsonUtils } }; +#ifdef WINRT_Windows_UI_H + template<> + struct ConversionTrait + { + winrt::Windows::UI::Color FromJson(const Json::Value& json) const + { + return static_cast(ConversionTrait{}.FromJson(json)); + } + + bool CanConvert(const Json::Value& json) const + { + return ConversionTrait{}.CanConvert(json); + } + + std::string TypeDescription() const + { + return ConversionTrait{}.TypeDescription(); + } + }; +#endif + template struct EnumMapper { diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 180100f4a97..754c7e56c52 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -323,9 +323,9 @@ void Pane::_ControlConnectionStateChangedHandler(const TermControl& /*sender*/, auto paneProfile = settings.FindProfile(_profile.value()); if (paneProfile) { - auto mode = paneProfile->GetCloseOnExitMode(); - if ((mode == CloseOnExitMode::Always) || - (mode == CloseOnExitMode::Graceful && newConnectionState == ConnectionState::Closed)) + auto mode = paneProfile.CloseOnExit(); + if ((mode == winrt::TerminalApp::CloseOnExitMode::Always) || + (mode == winrt::TerminalApp::CloseOnExitMode::Graceful && newConnectionState == ConnectionState::Closed)) { _ClosedHandlers(nullptr, nullptr); } diff --git a/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.cpp b/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.cpp index 2c2ba87d48a..364a42e0c19 100644 --- a/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.cpp +++ b/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.cpp @@ -136,6 +136,7 @@ namespace } using namespace ::TerminalApp; +using namespace winrt::TerminalApp; // Function Description: // - Finds all powershell instances with the traditional layout under a directory. @@ -286,7 +287,7 @@ static std::vector _collectPowerShellInstances() // Legacy GUIDs: // - PowerShell Core 574e775e-4f2a-5b96-ac1e-a2962a402336 -static constexpr GUID PowershellCoreGuid{ 0x574e775e, 0x4f2a, 0x5b96, { 0xac, 0x1e, 0xa2, 0x96, 0x2a, 0x40, 0x23, 0x36 } }; +static constexpr winrt::guid PowershellCoreGuid{ 0x574e775e, 0x4f2a, 0x5b96, { 0xac, 0x1e, 0xa2, 0x96, 0x2a, 0x40, 0x23, 0x36 } }; std::wstring_view PowershellCoreProfileGenerator::GetNamespace() { @@ -299,20 +300,20 @@ std::wstring_view PowershellCoreProfileGenerator::GetNamespace() // - // Return Value: // - a vector with the PowerShell Core profile, if available. -std::vector PowershellCoreProfileGenerator::GenerateProfiles() +std::vector PowershellCoreProfileGenerator::GenerateProfiles() { - std::vector profiles; + std::vector profiles; auto psInstances = _collectPowerShellInstances(); for (const auto& psI : psInstances) { const auto name = psI.Name(); auto profile{ CreateDefaultProfile(name) }; - profile.SetCommandline(psI.executablePath.wstring()); - profile.SetStartingDirectory(DEFAULT_STARTING_DIRECTORY); - profile.SetColorScheme({ L"Campbell" }); + profile.Commandline(psI.executablePath.wstring()); + profile.StartingDirectory(DEFAULT_STARTING_DIRECTORY); + profile.ColorSchemeName(L"Campbell"); - profile.SetIconPath(WI_IsFlagSet(psI.flags, PowerShellFlags::Preview) ? POWERSHELL_PREVIEW_ICON : POWERSHELL_ICON); + profile.IconPath(WI_IsFlagSet(psI.flags, PowerShellFlags::Preview) ? POWERSHELL_PREVIEW_ICON : POWERSHELL_ICON); profiles.emplace_back(std::move(profile)); } @@ -322,8 +323,8 @@ std::vector PowershellCoreProfileGenerator::GenerateProfil // This will turn the anchored default profile into "PowerShell Core Latest for Native Architecture through Store" // (or the closest approximation thereof). It may choose a preview instance as the "best" if it is a higher version. auto firstProfile = profiles.begin(); - firstProfile->SetGuid(PowershellCoreGuid); - firstProfile->SetName(POWERSHELL_PREFERRED_PROFILE_NAME); + firstProfile->Guid(PowershellCoreGuid); + firstProfile->Name(POWERSHELL_PREFERRED_PROFILE_NAME); } return profiles; diff --git a/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.h b/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.h index eb529358843..c32c9410c92 100644 --- a/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.h +++ b/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.h @@ -29,6 +29,6 @@ namespace TerminalApp ~PowershellCoreProfileGenerator() = default; std::wstring_view GetNamespace() override; - std::vector GenerateProfiles() override; + std::vector GenerateProfiles() override; }; }; diff --git a/src/cascadia/TerminalApp/Profile.cpp b/src/cascadia/TerminalApp/Profile.cpp index b1ad96ae3f2..5a594171e68 100644 --- a/src/cascadia/TerminalApp/Profile.cpp +++ b/src/cascadia/TerminalApp/Profile.cpp @@ -11,10 +11,14 @@ #include "LegacyProfileGeneratorNamespaces.h" #include "TerminalSettingsSerializationHelpers.h" +#include "Profile.g.cpp" + using namespace TerminalApp; -using namespace winrt::TerminalApp; +using namespace winrt::TerminalApp::implementation; using namespace winrt::Microsoft::Terminal::TerminalControl; +using namespace winrt::Windows::UI; using namespace winrt::Windows::UI::Xaml; +using namespace winrt::Windows::Foundation; using namespace ::Microsoft::Console; static constexpr std::string_view NameKey{ "name" }; @@ -55,77 +59,13 @@ static constexpr std::string_view RetroTerminalEffectKey{ "experimental.retroTer static constexpr std::string_view AntialiasingModeKey{ "antialiasingMode" }; static constexpr std::string_view TabColorKey{ "tabColor" }; -Profile::Profile() : - Profile(std::nullopt) -{ -} - -Profile::Profile(const std::optional& guid) : - _guid(guid), - _name{ L"Default" }, - _schemeName{ L"Campbell" }, - _hidden{ false }, - - _defaultForeground{}, - _defaultBackground{}, - _selectionBackground{}, - _cursorColor{}, - _tabTitle{}, - _suppressApplicationTitle{}, - _historySize{ DEFAULT_HISTORY_SIZE }, - _snapOnInput{ true }, - _altGrAliasing{ true }, - _cursorShape{ CursorStyle::Bar }, - _cursorHeight{ DEFAULT_CURSOR_HEIGHT }, - - _connectionType{}, - _commandline{ L"cmd.exe" }, - _startingDirectory{}, - _fontFace{ DEFAULT_FONT_FACE }, - _fontSize{ DEFAULT_FONT_SIZE }, - /* _fontWeight is initialized below because the structure won't accept a uint16_t directly */ - _acrylicTransparency{ 0.5 }, - _useAcrylic{ false }, - _scrollbarState{}, - _closeOnExitMode{ CloseOnExitMode::Graceful }, - _padding{ DEFAULT_PADDING }, - _icon{}, - _backgroundImage{}, - _backgroundImageOpacity{}, - _backgroundImageStretchMode{}, - _backgroundImageAlignment{}, - _retroTerminalEffect{}, - _antialiasingMode{ TextAntialiasingMode::Grayscale } -{ - winrt::Windows::UI::Text::FontWeight weight; - weight.Weight = DEFAULT_FONT_WEIGHT; - _fontWeight = weight; -} - -Profile::~Profile() -{ -} - -bool Profile::HasGuid() const noexcept -{ - return _guid.has_value(); -} - -bool Profile::HasSource() const noexcept -{ - return _source.has_value(); -} - -GUID Profile::GetGuid() const +Profile::Profile() { - // This can throw if we never had our guid set to a legitimate value. - THROW_HR_IF_MSG(E_FAIL, !_guid.has_value(), "Profile._guid always expected to have a value"); - return _guid.value(); } -void Profile::SetSource(std::wstring_view sourceNamespace) noexcept +Profile::Profile(guid guid) : + _Guid(guid) { - _source = sourceNamespace; } // Method Description: @@ -135,108 +75,97 @@ void Profile::SetSource(std::wstring_view sourceNamespace) noexcept // - schemes: a list of schemes to look for our color scheme in, if we have one. // Return Value: // - a new TerminalSettings object with our settings in it. -TerminalSettings Profile::CreateTerminalSettings(const std::unordered_map& schemes) const +winrt::TerminalApp::TerminalSettings Profile::CreateTerminalSettings(const std::unordered_map& schemes) const { - TerminalSettings terminalSettings{}; + winrt::TerminalApp::TerminalSettings terminalSettings{}; // Fill in the Terminal Setting's CoreSettings from the profile - terminalSettings.HistorySize(_historySize); - terminalSettings.SnapOnInput(_snapOnInput); - terminalSettings.AltGrAliasing(_altGrAliasing); - terminalSettings.CursorHeight(_cursorHeight); - terminalSettings.CursorShape(_cursorShape); + terminalSettings.HistorySize(_HistorySize); + terminalSettings.SnapOnInput(_SnapOnInput); + terminalSettings.AltGrAliasing(_AltGrAliasing); + terminalSettings.CursorHeight(_CursorHeight); + terminalSettings.CursorShape(_CursorShape); // Fill in the remaining properties from the profile - terminalSettings.ProfileName(_name); - terminalSettings.UseAcrylic(_useAcrylic); - terminalSettings.TintOpacity(_acrylicTransparency); + terminalSettings.ProfileName(_Name); + terminalSettings.UseAcrylic(_UseAcrylic); + terminalSettings.TintOpacity(_AcrylicOpacity); - terminalSettings.FontFace(_fontFace); - terminalSettings.FontSize(_fontSize); - terminalSettings.FontWeight(_fontWeight); - terminalSettings.Padding(_padding); + terminalSettings.FontFace(_FontFace); + terminalSettings.FontSize(_FontSize); + terminalSettings.FontWeight(_FontWeight); + terminalSettings.Padding(_Padding); - terminalSettings.Commandline(_commandline); + terminalSettings.Commandline(_Commandline); - if (_startingDirectory) + if (!_StartingDirectory.empty()) { - const auto evaluatedDirectory = Profile::EvaluateStartingDirectory(_startingDirectory.value()); + const auto evaluatedDirectory = Profile::EvaluateStartingDirectory(_StartingDirectory.c_str()); terminalSettings.StartingDirectory(evaluatedDirectory); } // GH#2373: Use the tabTitle as the starting title if it exists, otherwise // use the profile name - terminalSettings.StartingTitle(_tabTitle ? _tabTitle.value() : _name); + terminalSettings.StartingTitle(!_TabTitle.empty() ? _TabTitle : _Name); - if (_suppressApplicationTitle) + if (_SuppressApplicationTitle) { - terminalSettings.SuppressApplicationTitle(_suppressApplicationTitle); + terminalSettings.SuppressApplicationTitle(_SuppressApplicationTitle); } - if (_schemeName) + if (!_ColorSchemeName.empty()) { - const auto found = schemes.find(_schemeName.value()); + const auto found = schemes.find(_ColorSchemeName.c_str()); if (found != schemes.end()) { found->second.ApplyScheme(terminalSettings); } } - if (_defaultForeground) + if (_Foreground) { - terminalSettings.DefaultForeground(_defaultForeground.value()); + const til::color colorRef{ _Foreground.Value() }; + terminalSettings.DefaultForeground(static_cast(colorRef)); } - if (_defaultBackground) + if (_Background) { - terminalSettings.DefaultBackground(_defaultBackground.value()); + const til::color colorRef{ _Background.Value() }; + terminalSettings.DefaultBackground(static_cast(colorRef)); } - if (_selectionBackground) + if (_SelectionBackground) { - terminalSettings.SelectionBackground(_selectionBackground.value()); + const til::color colorRef{ _SelectionBackground.Value() }; + terminalSettings.SelectionBackground(static_cast(colorRef)); } - if (_cursorColor) + if (_CursorColor) { - terminalSettings.CursorColor(_cursorColor.value()); + const til::color colorRef{ _CursorColor.Value() }; + terminalSettings.CursorColor(static_cast(colorRef)); } - if (_scrollbarState) - { - terminalSettings.ScrollState(_scrollbarState.value()); - } + terminalSettings.ScrollState(_ScrollState); - if (HasBackgroundImage()) + if (!_BackgroundImagePath.empty()) { terminalSettings.BackgroundImage(GetExpandedBackgroundImagePath()); } - if (_backgroundImageOpacity) - { - terminalSettings.BackgroundImageOpacity(_backgroundImageOpacity.value()); - } + terminalSettings.BackgroundImageOpacity(_BackgroundImageOpacity); + terminalSettings.BackgroundImageStretchMode(_BackgroundImageStretchMode); - if (_backgroundImageStretchMode) - { - terminalSettings.BackgroundImageStretchMode(_backgroundImageStretchMode.value()); - } + const auto imageHorizontalAlignment = std::get(_BackgroundImageAlignment); + terminalSettings.BackgroundImageHorizontalAlignment(imageHorizontalAlignment); - if (_backgroundImageAlignment) - { - const auto imageHorizontalAlignment = std::get(_backgroundImageAlignment.value()); - const auto imageVerticalAlignment = std::get(_backgroundImageAlignment.value()); - terminalSettings.BackgroundImageHorizontalAlignment(imageHorizontalAlignment); - terminalSettings.BackgroundImageVerticalAlignment(imageVerticalAlignment); - } + const auto imageVerticalAlignment = std::get(_BackgroundImageAlignment); + terminalSettings.BackgroundImageVerticalAlignment(imageVerticalAlignment); - if (_retroTerminalEffect) - { - terminalSettings.RetroTerminalEffect(_retroTerminalEffect.value()); - } + terminalSettings.RetroTerminalEffect(_RetroTerminalEffect); - terminalSettings.AntialiasingMode(_antialiasingMode); + terminalSettings.AntialiasingMode(_AntialiasingMode); - if (_tabColor) + if (_TabColor) { - winrt::Windows::Foundation::IReference colorRef{ _tabColor.value() }; - terminalSettings.TabColor(colorRef); + const til::color colorRef{ _TabColor.Value() }; + terminalSettings.TabColor(static_cast(colorRef)); } return terminalSettings; @@ -258,19 +187,19 @@ Json::Value Profile::GenerateStub() const Json::Value stub; ///// Profile-specific settings ///// - if (_guid.has_value()) + if (_Guid.has_value()) { - stub[JsonKey(GuidKey)] = winrt::to_string(Utils::GuidToString(_guid.value())); + stub[JsonKey(GuidKey)] = winrt::to_string(Utils::GuidToString(*_Guid)); } - stub[JsonKey(NameKey)] = winrt::to_string(_name); + stub[JsonKey(NameKey)] = winrt::to_string(_Name); - if (_source.has_value()) + if (!_Source.empty()) { - stub[JsonKey(SourceKey)] = winrt::to_string(_source.value()); + stub[JsonKey(SourceKey)] = winrt::to_string(_Source); } - stub[JsonKey(HiddenKey)] = _hidden; + stub[JsonKey(HiddenKey)] = _Hidden; return stub; } @@ -281,12 +210,10 @@ Json::Value Profile::GenerateStub() const // - json: an object which should be a serialization of a Profile object. // Return Value: // - a new Profile instance created from the values in `json` -Profile Profile::FromJson(const Json::Value& json) +winrt::com_ptr Profile::FromJson(const Json::Value& json) { - Profile result; - - result.LayerJson(json); - + auto result = winrt::make_self(); + result->LayerJson(json); return result; } @@ -300,16 +227,16 @@ Profile Profile::FromJson(const Json::Value& json) // - true iff the json object has the same `GUID` as we do. bool Profile::ShouldBeLayered(const Json::Value& json) const { - if (!_guid.has_value()) + if (!_Guid.has_value()) { return false; } // First, check that GUIDs match. This is easy. If they don't match, they // should _definitely_ not layer. - if (const auto otherGuid{ JsonUtils::GetValueForKey>(json, GuidKey) }) + if (const auto otherGuid{ JsonUtils::GetValueForKey>(json, GuidKey) }) { - if (otherGuid != _guid) // optional compare takes care of this + if (otherGuid.value() != *_Guid) { return false; } @@ -328,12 +255,12 @@ bool Profile::ShouldBeLayered(const Json::Value& json) const // For profiles with a `source`, also check the `source` property. bool sourceMatches = false; - if (_source.has_value()) + if (!_Source.empty()) { if (otherHadSource) { // If we have a source and the other has a source, compare them! - sourceMatches = otherSource == _source; + sourceMatches = *otherSource == _Source; } else { @@ -341,9 +268,9 @@ bool Profile::ShouldBeLayered(const Json::Value& json) const // `this` is a dynamic profile with a source, and our _source is one // of the legacy DPG namespaces. We're looking to see if the other // json object has the same guid, but _no_ "source" - if (_source.value() == WslGeneratorNamespace || - _source.value() == AzureGeneratorNamespace || - _source.value() == PowershellCoreGeneratorNamespace) + if (_Source == WslGeneratorNamespace || + _Source == AzureGeneratorNamespace || + _Source == PowershellCoreGeneratorNamespace) { sourceMatches = true; } @@ -373,162 +300,51 @@ bool Profile::ShouldBeLayered(const Json::Value& json) const void Profile::LayerJson(const Json::Value& json) { // Profile-specific Settings - JsonUtils::GetValueForKey(json, NameKey, _name); - JsonUtils::GetValueForKey(json, GuidKey, _guid); - JsonUtils::GetValueForKey(json, HiddenKey, _hidden); + JsonUtils::GetValueForKey(json, NameKey, _Name); + JsonUtils::GetValueForKey(json, GuidKey, _Guid); + JsonUtils::GetValueForKey(json, HiddenKey, _Hidden); // Core Settings - JsonUtils::GetValueForKey(json, ForegroundKey, _defaultForeground); - JsonUtils::GetValueForKey(json, BackgroundKey, _defaultBackground); - JsonUtils::GetValueForKey(json, SelectionBackgroundKey, _selectionBackground); - JsonUtils::GetValueForKey(json, CursorColorKey, _cursorColor); - JsonUtils::GetValueForKey(json, ColorSchemeKey, _schemeName); + JsonUtils::GetValueForKey(json, ForegroundKey, _Foreground); + JsonUtils::GetValueForKey(json, BackgroundKey, _Background); + JsonUtils::GetValueForKey(json, SelectionBackgroundKey, _SelectionBackground); + JsonUtils::GetValueForKey(json, CursorColorKey, _CursorColor); + JsonUtils::GetValueForKey(json, ColorSchemeKey, _ColorSchemeName); // TODO:MSFT:20642297 - Use a sentinel value (-1) for "Infinite scrollback" - JsonUtils::GetValueForKey(json, HistorySizeKey, _historySize); - JsonUtils::GetValueForKey(json, SnapOnInputKey, _snapOnInput); - JsonUtils::GetValueForKey(json, AltGrAliasingKey, _altGrAliasing); - JsonUtils::GetValueForKey(json, CursorHeightKey, _cursorHeight); - JsonUtils::GetValueForKey(json, CursorShapeKey, _cursorShape); - JsonUtils::GetValueForKey(json, TabTitleKey, _tabTitle); + JsonUtils::GetValueForKey(json, HistorySizeKey, _HistorySize); + JsonUtils::GetValueForKey(json, SnapOnInputKey, _SnapOnInput); + JsonUtils::GetValueForKey(json, AltGrAliasingKey, _AltGrAliasing); + JsonUtils::GetValueForKey(json, CursorHeightKey, _CursorHeight); + JsonUtils::GetValueForKey(json, CursorShapeKey, _CursorShape); + JsonUtils::GetValueForKey(json, TabTitleKey, _TabTitle); // Control Settings - JsonUtils::GetValueForKey(json, FontWeightKey, _fontWeight); - JsonUtils::GetValueForKey(json, ConnectionTypeKey, _connectionType); - JsonUtils::GetValueForKey(json, CommandlineKey, _commandline); - JsonUtils::GetValueForKey(json, FontFaceKey, _fontFace); - JsonUtils::GetValueForKey(json, FontSizeKey, _fontSize); - JsonUtils::GetValueForKey(json, AcrylicTransparencyKey, _acrylicTransparency); - JsonUtils::GetValueForKey(json, UseAcrylicKey, _useAcrylic); - JsonUtils::GetValueForKey(json, SuppressApplicationTitleKey, _suppressApplicationTitle); - JsonUtils::GetValueForKey(json, CloseOnExitKey, _closeOnExitMode); + JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight); + JsonUtils::GetValueForKey(json, ConnectionTypeKey, _ConnectionType); + JsonUtils::GetValueForKey(json, CommandlineKey, _Commandline); + JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace); + JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize); + JsonUtils::GetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity); + JsonUtils::GetValueForKey(json, UseAcrylicKey, _UseAcrylic); + JsonUtils::GetValueForKey(json, SuppressApplicationTitleKey, _SuppressApplicationTitle); + JsonUtils::GetValueForKey(json, CloseOnExitKey, _CloseOnExit); // Padding was never specified as an integer, but it was a common working mistake. // Allow it to be permissive. - JsonUtils::GetValueForKey(json, PaddingKey, _padding, JsonUtils::PermissiveStringConverter{}); - - JsonUtils::GetValueForKey(json, ScrollbarStateKey, _scrollbarState); - JsonUtils::GetValueForKey(json, StartingDirectoryKey, _startingDirectory); - JsonUtils::GetValueForKey(json, IconKey, _icon); - JsonUtils::GetValueForKey(json, BackgroundImageKey, _backgroundImage); - JsonUtils::GetValueForKey(json, BackgroundImageOpacityKey, _backgroundImageOpacity); - JsonUtils::GetValueForKey(json, BackgroundImageStretchModeKey, _backgroundImageStretchMode); - JsonUtils::GetValueForKey(json, BackgroundImageAlignmentKey, _backgroundImageAlignment); - JsonUtils::GetValueForKey(json, RetroTerminalEffectKey, _retroTerminalEffect); - JsonUtils::GetValueForKey(json, AntialiasingModeKey, _antialiasingMode); - - JsonUtils::GetValueForKey(json, TabColorKey, _tabColor); -} - -void Profile::SetFontFace(std::wstring fontFace) noexcept -{ - _fontFace = std::move(fontFace); -} - -void Profile::SetColorScheme(std::optional schemeName) noexcept -{ - _schemeName = std::move(schemeName); -} - -const std::optional& Profile::GetSchemeName() const noexcept -{ - return _schemeName; -} - -void Profile::SetAcrylicOpacity(double opacity) noexcept -{ - _acrylicTransparency = opacity; -} - -void Profile::SetCommandline(std::wstring cmdline) noexcept -{ - _commandline = std::move(cmdline); -} - -void Profile::SetStartingDirectory(std::wstring startingDirectory) noexcept -{ - _startingDirectory = std::move(startingDirectory); -} - -void Profile::SetName(const std::wstring_view name) noexcept -{ - _name = static_cast(name); -} - -void Profile::SetUseAcrylic(bool useAcrylic) noexcept -{ - _useAcrylic = useAcrylic; -} - -void Profile::SetDefaultForeground(til::color defaultForeground) noexcept -{ - _defaultForeground = defaultForeground; -} - -void Profile::SetDefaultBackground(til::color defaultBackground) noexcept -{ - _defaultBackground = defaultBackground; -} - -void Profile::SetSelectionBackground(til::color selectionBackground) noexcept -{ - _selectionBackground = selectionBackground; -} - -void Profile::SetCloseOnExitMode(CloseOnExitMode mode) noexcept -{ - _closeOnExitMode = mode; -} - -void Profile::SetConnectionType(GUID connectionType) noexcept -{ - _connectionType = connectionType; -} - -bool Profile::HasIcon() const noexcept -{ - return _icon.has_value() && !_icon.value().empty(); -} - -bool Profile::HasBackgroundImage() const noexcept -{ - return _backgroundImage.has_value() && !_backgroundImage.value().empty(); -} - -// Method Description -// - Sets this profile's tab title. -// Arguments: -// - tabTitle: the tab title -void Profile::SetTabTitle(std::wstring tabTitle) noexcept -{ - _tabTitle = std::move(tabTitle); -} - -// Method Description -// - Sets if the application title will be suppressed in this profile. -// Arguments: -// - suppressApplicationTitle: boolean -void Profile::SetSuppressApplicationTitle(bool suppressApplicationTitle) noexcept -{ - _suppressApplicationTitle = suppressApplicationTitle; -} + JsonUtils::GetValueForKey(json, PaddingKey, _Padding, JsonUtils::PermissiveStringConverter{}); -// Method Description: -// - Sets this profile's icon path. -// Arguments: -// - path: the path -void Profile::SetIconPath(std::wstring_view path) -{ - static_assert(!noexcept(_icon.emplace(path))); - _icon.emplace(path); -} + JsonUtils::GetValueForKey(json, ScrollbarStateKey, _ScrollState); + JsonUtils::GetValueForKey(json, StartingDirectoryKey, _StartingDirectory); + JsonUtils::GetValueForKey(json, IconKey, _IconPath); + JsonUtils::GetValueForKey(json, BackgroundImageKey, _BackgroundImagePath); + JsonUtils::GetValueForKey(json, BackgroundImageOpacityKey, _BackgroundImageOpacity); + JsonUtils::GetValueForKey(json, BackgroundImageStretchModeKey, _BackgroundImageStretchMode); + JsonUtils::GetValueForKey(json, BackgroundImageAlignmentKey, _BackgroundImageAlignment); + JsonUtils::GetValueForKey(json, RetroTerminalEffectKey, _RetroTerminalEffect); + JsonUtils::GetValueForKey(json, AntialiasingModeKey, _AntialiasingMode); -// Method Description: -// - Resets the std::optional holding the icon file path string. -// HasIcon() will return false after the execution of this function. -void Profile::ResetIconPath() -{ - _icon.reset(); + JsonUtils::GetValueForKey(json, TabColorKey, _TabColor); } // Method Description: @@ -539,11 +355,11 @@ void Profile::ResetIconPath() // - this profile's icon path, if one is set. Otherwise returns the empty string. winrt::hstring Profile::GetExpandedIconPath() const { - if (!HasIcon()) + if (_IconPath.empty()) { - return { L"" }; + return _IconPath; } - winrt::hstring envExpandedPath{ wil::ExpandEnvironmentStringsW(_icon.value().data()) }; + winrt::hstring envExpandedPath{ wil::ExpandEnvironmentStringsW(_IconPath.c_str()) }; return envExpandedPath; } @@ -554,68 +370,11 @@ winrt::hstring Profile::GetExpandedIconPath() const // - This profile's expanded background image path / the empty string. winrt::hstring Profile::GetExpandedBackgroundImagePath() const { - winrt::hstring result{}; - - if (HasBackgroundImage()) + if (_BackgroundImagePath.empty()) { - result = wil::ExpandEnvironmentStringsW(_backgroundImage.value().data()); + return _BackgroundImagePath; } - - return result; -} - -// Method Description: -// - Resets the std::optional holding the background image file path string. -// HasBackgroundImage() will return false after the execution of this function. -void Profile::ResetBackgroundImagePath() -{ - _backgroundImage.reset(); -} - -// Method Description: -// - Returns the name of this profile. -// Arguments: -// - -// Return Value: -// - the name of this profile -std::wstring_view Profile::GetName() const noexcept -{ - return _name; -} - -bool Profile::GetSuppressApplicationTitle() const noexcept -{ - return _suppressApplicationTitle; -} - -bool Profile::HasConnectionType() const noexcept -{ - return _connectionType.has_value(); -} - -GUID Profile::GetConnectionType() const noexcept -{ - return HasConnectionType() ? - _connectionType.value() : - _GUID{}; -} - -CloseOnExitMode Profile::GetCloseOnExitMode() const noexcept -{ - return _closeOnExitMode; -} - -// Method Description: -// - If a profile is marked hidden, it should not appear in the dropdown list of -// profiles. This setting is used to "remove" default and dynamic profiles -// from the list of profiles. -// Arguments: -// - -// Return Value: -// - true iff the profile should be hidden from the list of profiles. -bool Profile::IsHidden() const noexcept -{ - return _hidden; + return winrt::hstring{ wil::ExpandEnvironmentStringsW(_BackgroundImagePath.c_str()) }; } // Method Description: @@ -655,11 +414,11 @@ std::wstring Profile::EvaluateStartingDirectory(const std::wstring& directory) // will _not_ change the profile's GUID. void Profile::GenerateGuidIfNecessary() noexcept { - if (!_guid.has_value()) + if (!_Guid.has_value()) { // Always use the name to generate the temporary GUID. That way, across // reloads, we'll generate the same static GUID. - _guid = Profile::_GenerateGuidForProfile(_name, _source); + _Guid = Profile::_GenerateGuidForProfile(_Name, _Source); TraceLoggingWrite( g_hTerminalAppProvider, @@ -690,18 +449,18 @@ bool Profile::IsDynamicProfileObject(const Json::Value& json) // - name: The name to generate a unique GUID from // Return Value: // - a uuidv5 GUID generated from the given name. -GUID Profile::_GenerateGuidForProfile(const std::wstring& name, const std::optional& source) noexcept +winrt::guid Profile::_GenerateGuidForProfile(const hstring& name, const hstring& source) noexcept { // If we have a _source, then we can from a dynamic profile generator. Use // our source to build the namespace guid, instead of using the default GUID. - const GUID namespaceGuid = source.has_value() ? - Utils::CreateV5Uuid(RUNTIME_GENERATED_PROFILE_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(source.value()))) : + const GUID namespaceGuid = !source.empty() ? + Utils::CreateV5Uuid(RUNTIME_GENERATED_PROFILE_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(source))) : RUNTIME_GENERATED_PROFILE_NAMESPACE_GUID; // Always use the name to generate the temporary GUID. That way, across // reloads, we'll generate the same static GUID. - return Utils::CreateV5Uuid(namespaceGuid, gsl::as_bytes(gsl::make_span(name))); + return { Utils::CreateV5Uuid(namespaceGuid, gsl::as_bytes(gsl::make_span(name))) }; } // Function Description: @@ -712,20 +471,67 @@ GUID Profile::_GenerateGuidForProfile(const std::wstring& name, const std::optio // (given the `name`) // Return Value: // - The json's `guid`, or a guid synthesized for it. -GUID Profile::GetGuidOrGenerateForJson(const Json::Value& json) noexcept +winrt::guid Profile::GetGuidOrGenerateForJson(const Json::Value& json) noexcept { if (const auto guid{ JsonUtils::GetValueForKey>(json, GuidKey) }) { - return guid.value(); + return { guid.value() }; } - const auto name{ JsonUtils::GetValueForKey(json, NameKey) }; - const auto source{ JsonUtils::GetValueForKey>(json, SourceKey) }; + const auto name{ JsonUtils::GetValueForKey(json, NameKey) }; + const auto source{ JsonUtils::GetValueForKey(json, SourceKey) }; return Profile::_GenerateGuidForProfile(name, source); } -void Profile::SetRetroTerminalEffect(bool value) noexcept +const HorizontalAlignment Profile::BackgroundImageHorizontalAlignment() const noexcept +{ + return std::get(_BackgroundImageAlignment); +} + +void Profile::BackgroundImageHorizontalAlignment(const HorizontalAlignment& value) noexcept +{ + std::get(_BackgroundImageAlignment) = value; +} + +const VerticalAlignment Profile::BackgroundImageVerticalAlignment() const noexcept +{ + return std::get(_BackgroundImageAlignment); +} + +void Profile::BackgroundImageVerticalAlignment(const VerticalAlignment& value) noexcept +{ + std::get(_BackgroundImageAlignment) = value; +} + +bool Profile::HasGuid() const noexcept +{ + return _Guid.has_value(); +} + +winrt::guid Profile::Guid() const +{ + // This can throw if we never had our guid set to a legitimate value. + THROW_HR_IF_MSG(E_FAIL, !_Guid.has_value(), "Profile._guid always expected to have a value"); + return *_Guid; +} + +void Profile::Guid(winrt::guid guid) noexcept +{ + _Guid = guid; +} + +bool Profile::HasConnectionType() const noexcept +{ + return _ConnectionType.has_value(); +} + +winrt::guid Profile::ConnectionType() const noexcept +{ + return *_ConnectionType; +} + +void Profile::ConnectionType(winrt::guid conType) noexcept { - _retroTerminalEffect = value; + _ConnectionType = conType; } diff --git a/src/cascadia/TerminalApp/Profile.h b/src/cascadia/TerminalApp/Profile.h index 2ab88f0c884..823eaae42fa 100644 --- a/src/cascadia/TerminalApp/Profile.h +++ b/src/cascadia/TerminalApp/Profile.h @@ -14,8 +14,13 @@ Author(s): --*/ #pragma once + +#include "Profile.g.h" #include "ColorScheme.g.h" -#include "SettingsTypes.h" + +#include "../inc/cppwinrt_utils.h" +#include "JsonUtils.h" +#include // fwdecl unittest classes namespace TerminalAppLocalTests @@ -33,123 +38,106 @@ namespace TerminalAppUnitTests // GUID specified manually. constexpr GUID RUNTIME_GENERATED_PROFILE_NAMESPACE_GUID = { 0xf65ddb7e, 0x706b, 0x4499, { 0x8a, 0x50, 0x40, 0x31, 0x3c, 0xaf, 0x51, 0x0a } }; -namespace TerminalApp +namespace winrt::TerminalApp::implementation { - class Profile; + struct Profile : ProfileT + { + public: + Profile(); + Profile(guid guid); + + TerminalApp::TerminalSettings CreateTerminalSettings(const std::unordered_map& schemes) const; + + Json::Value GenerateStub() const; + static com_ptr FromJson(const Json::Value& json); + bool ShouldBeLayered(const Json::Value& json) const; + void LayerJson(const Json::Value& json); + static bool IsDynamicProfileObject(const Json::Value& json); + + hstring GetExpandedIconPath() const; + hstring GetExpandedBackgroundImagePath() const; + void GenerateGuidIfNecessary() noexcept; + static guid GetGuidOrGenerateForJson(const Json::Value& json) noexcept; + + bool HasGuid() const noexcept; + winrt::guid Guid() const; + void Guid(winrt::guid guid) noexcept; + + bool HasConnectionType() const noexcept; + winrt::guid ConnectionType() const noexcept; + void ConnectionType(winrt::guid conType) noexcept; + + // BackgroundImageAlignment is 1 setting saved as 2 separate values + const Windows::UI::Xaml::HorizontalAlignment BackgroundImageHorizontalAlignment() const noexcept; + void BackgroundImageHorizontalAlignment(const Windows::UI::Xaml::HorizontalAlignment& value) noexcept; + const Windows::UI::Xaml::VerticalAlignment BackgroundImageVerticalAlignment() const noexcept; + void BackgroundImageVerticalAlignment(const Windows::UI::Xaml::VerticalAlignment& value) noexcept; + + GETSET_PROPERTY(hstring, Name, L"Default"); + GETSET_PROPERTY(hstring, Source); + GETSET_PROPERTY(bool, Hidden, false); + + GETSET_PROPERTY(hstring, IconPath); + + GETSET_PROPERTY(CloseOnExitMode, CloseOnExit, CloseOnExitMode::Graceful); + GETSET_PROPERTY(hstring, TabTitle); + GETSET_PROPERTY(Windows::Foundation::IReference, TabColor); + GETSET_PROPERTY(bool, SuppressApplicationTitle, false); + + GETSET_PROPERTY(bool, UseAcrylic, false); + GETSET_PROPERTY(double, AcrylicOpacity, 0.5); + GETSET_PROPERTY(Microsoft::Terminal::TerminalControl::ScrollbarState, ScrollState, Microsoft::Terminal::TerminalControl::ScrollbarState::Visible); + + GETSET_PROPERTY(hstring, FontFace, DEFAULT_FONT_FACE); + GETSET_PROPERTY(int32_t, FontSize, DEFAULT_FONT_SIZE); + GETSET_PROPERTY(Windows::UI::Text::FontWeight, FontWeight, DEFAULT_FONT_WEIGHT); + GETSET_PROPERTY(hstring, Padding, DEFAULT_PADDING); + + GETSET_PROPERTY(hstring, Commandline, L"cmd.exe"); + GETSET_PROPERTY(hstring, StartingDirectory); + + GETSET_PROPERTY(hstring, BackgroundImagePath); + GETSET_PROPERTY(double, BackgroundImageOpacity, 1.0); + GETSET_PROPERTY(Windows::UI::Xaml::Media::Stretch, BackgroundImageStretchMode, Windows::UI::Xaml::Media::Stretch::Fill); + + GETSET_PROPERTY(Microsoft::Terminal::TerminalControl::TextAntialiasingMode, AntialiasingMode, Microsoft::Terminal::TerminalControl::TextAntialiasingMode::Grayscale); + GETSET_PROPERTY(bool, RetroTerminalEffect, false); + GETSET_PROPERTY(bool, ForceFullRepaintRendering, false); + GETSET_PROPERTY(bool, SoftwareRendering, false); + + GETSET_PROPERTY(hstring, ColorSchemeName, L"Campbell"); + GETSET_PROPERTY(Windows::Foundation::IReference, Foreground); + GETSET_PROPERTY(Windows::Foundation::IReference, Background); + GETSET_PROPERTY(Windows::Foundation::IReference, SelectionBackground); + GETSET_PROPERTY(Windows::Foundation::IReference, CursorColor); + + GETSET_PROPERTY(int32_t, HistorySize, DEFAULT_HISTORY_SIZE); + GETSET_PROPERTY(bool, SnapOnInput, true); + GETSET_PROPERTY(bool, AltGrAliasing, true); + + GETSET_PROPERTY(Microsoft::Terminal::TerminalControl::CursorStyle, CursorShape, Microsoft::Terminal::TerminalControl::CursorStyle::Bar); + GETSET_PROPERTY(uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT); + + private: + std::optional _Guid{ std::nullopt }; + std::optional _ConnectionType{ std::nullopt }; + std::tuple _BackgroundImageAlignment{ + Windows::UI::Xaml::HorizontalAlignment::Center, + Windows::UI::Xaml::VerticalAlignment::Center + }; + + static std::wstring EvaluateStartingDirectory(const std::wstring& directory); + + static guid _GenerateGuidForProfile(const hstring& name, const hstring& source) noexcept; + + friend class TerminalAppLocalTests::SettingsTests; + friend class TerminalAppLocalTests::ProfileTests; + friend class TerminalAppUnitTests::JsonTests; + friend class TerminalAppUnitTests::DynamicProfileTests; + }; } -class TerminalApp::Profile final +namespace winrt::TerminalApp::factory_implementation { -public: - Profile(); - explicit Profile(const std::optional& guid); - - ~Profile(); - - winrt::TerminalApp::TerminalSettings CreateTerminalSettings(const std::unordered_map& schemes) const; - - Json::Value GenerateStub() const; - static Profile FromJson(const Json::Value& json); - bool ShouldBeLayered(const Json::Value& json) const; - void LayerJson(const Json::Value& json); - static bool IsDynamicProfileObject(const Json::Value& json); - - bool HasGuid() const noexcept; - bool HasSource() const noexcept; - GUID GetGuid() const; - void SetSource(std::wstring_view sourceNamespace) noexcept; - std::wstring_view GetName() const noexcept; - bool HasConnectionType() const noexcept; - GUID GetConnectionType() const noexcept; - - void SetGuid(GUID guid) noexcept { _guid = guid; } - void SetFontFace(std::wstring fontFace) noexcept; - void SetColorScheme(std::optional schemeName) noexcept; - const std::optional& GetSchemeName() const noexcept; - void SetTabTitle(std::wstring tabTitle) noexcept; - void SetSuppressApplicationTitle(bool suppressApplicationTitle) noexcept; - void SetAcrylicOpacity(double opacity) noexcept; - void SetCommandline(std::wstring cmdline) noexcept; - void SetStartingDirectory(std::wstring startingDirectory) noexcept; - void SetName(const std::wstring_view name) noexcept; - void SetUseAcrylic(bool useAcrylic) noexcept; - void SetDefaultForeground(til::color defaultForeground) noexcept; - void SetDefaultBackground(til::color defaultBackground) noexcept; - void SetSelectionBackground(til::color selectionBackground) noexcept; - void SetCloseOnExitMode(CloseOnExitMode mode) noexcept; - void SetConnectionType(GUID connectionType) noexcept; - - bool HasIcon() const noexcept; - winrt::hstring GetExpandedIconPath() const; - void SetIconPath(std::wstring_view path); - void ResetIconPath(); - - bool HasBackgroundImage() const noexcept; - winrt::hstring GetExpandedBackgroundImagePath() const; - void ResetBackgroundImagePath(); - - CloseOnExitMode GetCloseOnExitMode() const noexcept; - bool GetSuppressApplicationTitle() const noexcept; - bool IsHidden() const noexcept; - - void GenerateGuidIfNecessary() noexcept; - - static GUID GetGuidOrGenerateForJson(const Json::Value& json) noexcept; - - void SetRetroTerminalEffect(bool value) noexcept; - -private: - static std::wstring EvaluateStartingDirectory(const std::wstring& directory); - - static GUID _GenerateGuidForProfile(const std::wstring& name, const std::optional& source) noexcept; - - std::optional _guid{ std::nullopt }; - std::optional _source{ std::nullopt }; - std::wstring _name; - std::optional _connectionType; - bool _hidden; - - // If this is set, then our colors should come from the associated color scheme - std::optional _schemeName; - - std::optional _defaultForeground; - std::optional _defaultBackground; - std::optional _selectionBackground; - std::optional _cursorColor; - std::optional _tabTitle; - std::optional _tabColor; - bool _suppressApplicationTitle; - int32_t _historySize; - bool _snapOnInput; - bool _altGrAliasing; - uint32_t _cursorHeight; - winrt::Microsoft::Terminal::TerminalControl::CursorStyle _cursorShape; - - std::wstring _commandline; - std::wstring _fontFace; - std::optional _startingDirectory; - int32_t _fontSize; - winrt::Windows::UI::Text::FontWeight _fontWeight; - double _acrylicTransparency; - bool _useAcrylic; - - std::optional _backgroundImage; - std::optional _backgroundImageOpacity; - std::optional _backgroundImageStretchMode; - std::optional> _backgroundImageAlignment; - - std::optional<::winrt::Microsoft::Terminal::TerminalControl::ScrollbarState> _scrollbarState; - CloseOnExitMode _closeOnExitMode; - std::wstring _padding; - - std::optional _icon; - - winrt::Microsoft::Terminal::TerminalControl::TextAntialiasingMode _antialiasingMode; - - friend class TerminalAppLocalTests::SettingsTests; - friend class TerminalAppLocalTests::ProfileTests; - friend class TerminalAppUnitTests::JsonTests; - friend class TerminalAppUnitTests::DynamicProfileTests; - - std::optional _retroTerminalEffect; -}; + BASIC_FACTORY(Profile); +} diff --git a/src/cascadia/TerminalApp/Profile.idl b/src/cascadia/TerminalApp/Profile.idl new file mode 100644 index 00000000000..d8de2ec7d67 --- /dev/null +++ b/src/cascadia/TerminalApp/Profile.idl @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +namespace TerminalApp +{ + enum CloseOnExitMode + { + Never = 0, + Graceful, + Always + }; + + [default_interface] runtimeclass Profile { + Profile(); + Profile(Guid guid); + + String Name; + Boolean HasGuid(); + Guid Guid; + String Source; + Boolean HasConnectionType(); + Guid ConnectionType; + Boolean Hidden; + + String IconPath; + String GetExpandedIconPath(); + + CloseOnExitMode CloseOnExit; + String TabTitle; + Windows.Foundation.IReference TabColor; + Boolean SuppressApplicationTitle; + + Boolean UseAcrylic; + Double AcrylicOpacity; + Microsoft.Terminal.TerminalControl.ScrollbarState ScrollState; + + String FontFace; + Int32 FontSize; + Windows.UI.Text.FontWeight FontWeight; + String Padding; + + String Commandline; + String StartingDirectory; + + String BackgroundImagePath; + String GetExpandedBackgroundImagePath(); + Double BackgroundImageOpacity; + Windows.UI.Xaml.Media.Stretch BackgroundImageStretchMode; + Windows.UI.Xaml.HorizontalAlignment BackgroundImageHorizontalAlignment; + Windows.UI.Xaml.VerticalAlignment BackgroundImageVerticalAlignment; + + Microsoft.Terminal.TerminalControl.TextAntialiasingMode AntialiasingMode; + Boolean RetroTerminalEffect; + Boolean ForceFullRepaintRendering; + Boolean SoftwareRendering; + + String ColorSchemeName; + Windows.Foundation.IReference Foreground; + Windows.Foundation.IReference Background; + Windows.Foundation.IReference SelectionBackground; + Windows.Foundation.IReference CursorColor; + + Int32 HistorySize; + Boolean SnapOnInput; + Boolean AltGrAliasing; + + Microsoft.Terminal.TerminalControl.CursorStyle CursorShape; + UInt32 CursorHeight; + } +} diff --git a/src/cascadia/TerminalApp/SettingsTypes.h b/src/cascadia/TerminalApp/SettingsTypes.h index 5a3cc3da00c..946b1951cba 100644 --- a/src/cascadia/TerminalApp/SettingsTypes.h +++ b/src/cascadia/TerminalApp/SettingsTypes.h @@ -13,13 +13,6 @@ Module Name: namespace TerminalApp { - enum class CloseOnExitMode - { - Never = 0, - Graceful, - Always - }; - struct LaunchPosition { std::optional x; diff --git a/src/cascadia/TerminalApp/TelnetGenerator.h b/src/cascadia/TerminalApp/TelnetGenerator.h index 85282b7c4d9..c7356b65fd9 100644 --- a/src/cascadia/TerminalApp/TelnetGenerator.h +++ b/src/cascadia/TerminalApp/TelnetGenerator.h @@ -16,4 +16,4 @@ Author(s): #pragma once // {311153fb-d3f0-4ac6-b920-038de7cf5289} -static constexpr GUID TelnetConnectionType = { 0x311153fb, 0xd3f0, 0x4ac6, { 0xb9, 0x20, 0x03, 0x8d, 0xe7, 0xcf, 0x52, 0x89 } }; +static constexpr winrt::guid TelnetConnectionType = { 0x311153fb, 0xd3f0, 0x4ac6, { 0xb9, 0x20, 0x03, 0x8d, 0xe7, 0xcf, 0x52, 0x89 } }; diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index 807f9464445..a562ed31e30 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -108,7 +108,9 @@ ColorScheme.idl - + + Profile.idl + @@ -187,7 +189,9 @@ ColorScheme.idl - + + Profile.idl + @@ -276,6 +280,7 @@ + diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters index 3056b71130d..3a2e600fd71 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters @@ -151,6 +151,9 @@ settings + + settings + diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 318fe967f9d..5c62c5ade3e 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -477,13 +477,12 @@ namespace winrt::TerminalApp::implementation _SetAcceleratorForMenuItem(profileMenuItem, profileKeyChord); } - auto profileName = profile.GetName(); - winrt::hstring hName{ profileName }; - profileMenuItem.Text(hName); + auto profileName = profile.Name(); + profileMenuItem.Text(profileName); // If there's an icon set for this profile, set it as the icon for // this flyout item. - if (profile.HasIcon()) + if (!profile.IconPath().empty()) { auto iconSource = GetColoredIcon(profile.GetExpandedIconPath()); @@ -493,7 +492,7 @@ namespace winrt::TerminalApp::implementation Automation::AutomationProperties::SetAccessibilityView(iconElement, Automation::Peers::AccessibilityView::Raw); } - if (profile.GetGuid() == defaultProfileGuid) + if (profile.Guid() == winrt::guid{ defaultProfileGuid }) { // Contrast the default profile with others in font weight. profileMenuItem.FontWeight(FontWeights::Bold()); @@ -726,10 +725,10 @@ namespace winrt::TerminalApp::implementation } // Set this tab's icon to the icon from the user's profile - const auto* const profile = _settings->FindProfile(profileGuid); - if (profile != nullptr && profile->HasIcon()) + const auto profile = _settings->FindProfile(profileGuid); + if (profile != nullptr && !profile.IconPath().empty()) { - newTabImpl->UpdateIcon(profile->GetExpandedIconPath()); + newTabImpl->UpdateIcon(profile.GetExpandedIconPath()); } tabViewItem.PointerPressed({ this, &TerminalPage::_OnTabClick }); @@ -765,20 +764,21 @@ namespace winrt::TerminalApp::implementation TerminalConnection::ITerminalConnection TerminalPage::_CreateConnectionFromSettings(GUID profileGuid, TerminalApp::TerminalSettings settings) { - const auto* const profile = _settings->FindProfile(profileGuid); + const auto profile = _settings->FindProfile(profileGuid); TerminalConnection::ITerminalConnection connection{ nullptr }; - GUID connectionType{ 0 }; - GUID sessionGuid{ 0 }; + winrt::guid connectionType{}; + winrt::guid sessionGuid{}; - if (profile->HasConnectionType()) + const auto hasConnectionType = profile.HasConnectionType(); + if (hasConnectionType) { - connectionType = profile->GetConnectionType(); + connectionType = profile.ConnectionType(); } - if (profile->HasConnectionType() && - profile->GetConnectionType() == AzureConnectionType && + if (hasConnectionType && + connectionType == AzureConnectionType && TerminalConnection::AzureConnection::IsAzureConnectionAvailable()) { // TODO GH#4661: Replace this with directly using the AzCon when our VT is better @@ -793,8 +793,8 @@ namespace winrt::TerminalApp::implementation winrt::guid()); } - else if (profile->HasConnectionType() && - profile->GetConnectionType() == TelnetConnectionType) + else if (hasConnectionType && + connectionType == TelnetConnectionType) { connection = TerminalConnection::TelnetConnection(settings.Commandline()); } @@ -966,10 +966,10 @@ namespace winrt::TerminalApp::implementation if (lastFocusedProfileOpt.has_value()) { const auto lastFocusedProfile = lastFocusedProfileOpt.value(); - const auto* const matchingProfile = _settings->FindProfile(lastFocusedProfile); + const auto matchingProfile = _settings->FindProfile(lastFocusedProfile); if (matchingProfile) { - tab.UpdateIcon(matchingProfile->GetExpandedIconPath()); + tab.UpdateIcon(matchingProfile.GetExpandedIconPath()); } else { @@ -2004,7 +2004,7 @@ namespace winrt::TerminalApp::implementation auto profiles = _settings->GetProfiles(); for (auto& profile : profiles) { - const GUID profileGuid = profile.GetGuid(); + const auto profileGuid = profile.Guid(); try { @@ -2069,7 +2069,7 @@ namespace winrt::TerminalApp::implementation // Return Value: // - IMap TerminalPage::_ExpandCommands(IMapView commandsToExpand, - gsl::span profiles, + gsl::span profiles, const std::unordered_map& schemes) { std::vector<::TerminalApp::SettingsLoadWarnings> warnings; diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 02d0af0b53d..b30682ada54 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -137,7 +137,7 @@ namespace winrt::TerminalApp::implementation void _UpdateTabWidthMode(); void _UpdateCommandsForPalette(); static winrt::Windows::Foundation::Collections::IMap _ExpandCommands(Windows::Foundation::Collections::IMapView commandsToExpand, - gsl::span profiles, + gsl::span profiles, const std::unordered_map& schemes); void _DuplicateTabViewItem(); diff --git a/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h index 06054eab69a..deb7856063a 100644 --- a/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h @@ -79,7 +79,7 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::TerminalControl::TextAntialiasing // Type Description: // - Helper for converting a user-specified closeOnExit value to its corresponding enum -JSON_ENUM_MAPPER(::TerminalApp::CloseOnExitMode) +JSON_ENUM_MAPPER(::winrt::TerminalApp::CloseOnExitMode) { JSON_MAPPINGS(3) = { pair_type{ "always", ValueType::Always }, @@ -88,7 +88,7 @@ JSON_ENUM_MAPPER(::TerminalApp::CloseOnExitMode) }; // Override mapping parser to add boolean parsing - CloseOnExitMode FromJson(const Json::Value& json) + ::winrt::TerminalApp::CloseOnExitMode FromJson(const Json::Value& json) { if (json.isBool()) { diff --git a/src/cascadia/TerminalApp/WslDistroGenerator.cpp b/src/cascadia/TerminalApp/WslDistroGenerator.cpp index ab63dcf92c7..3f2c655fecb 100644 --- a/src/cascadia/TerminalApp/WslDistroGenerator.cpp +++ b/src/cascadia/TerminalApp/WslDistroGenerator.cpp @@ -16,6 +16,7 @@ static constexpr std::wstring_view DockerDistributionPrefix{ L"docker-desktop" }; using namespace ::TerminalApp; +using namespace winrt::TerminalApp; // Legacy GUIDs: // - Debian 58ad8b0c-3ef8-5f4d-bc6f-13e4c00f2530 @@ -34,9 +35,9 @@ std::wstring_view WslDistroGenerator::GetNamespace() // - // Return Value: // - a vector with all distros for all the installed WSL distros -std::vector WslDistroGenerator::GenerateProfiles() +std::vector WslDistroGenerator::GenerateProfiles() { - std::vector profiles; + std::vector profiles; wil::unique_handle readPipe; wil::unique_handle writePipe; @@ -125,10 +126,10 @@ std::vector WslDistroGenerator::GenerateProfiles() } auto WSLDistro{ CreateDefaultProfile(distName) }; - WSLDistro.SetCommandline(L"wsl.exe -d " + distName); - WSLDistro.SetColorScheme({ L"Campbell" }); - WSLDistro.SetStartingDirectory(DEFAULT_STARTING_DIRECTORY); - WSLDistro.SetIconPath(L"ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png"); + WSLDistro.Commandline(L"wsl.exe -d " + distName); + WSLDistro.ColorSchemeName(L"Campbell"); + WSLDistro.StartingDirectory(DEFAULT_STARTING_DIRECTORY); + WSLDistro.IconPath(L"ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png"); profiles.emplace_back(WSLDistro); } } diff --git a/src/cascadia/TerminalApp/WslDistroGenerator.h b/src/cascadia/TerminalApp/WslDistroGenerator.h index 8f4aedea57b..323ecaaadad 100644 --- a/src/cascadia/TerminalApp/WslDistroGenerator.h +++ b/src/cascadia/TerminalApp/WslDistroGenerator.h @@ -25,6 +25,6 @@ namespace TerminalApp WslDistroGenerator() = default; ~WslDistroGenerator() = default; std::wstring_view GetNamespace() override; - std::vector GenerateProfiles() override; + std::vector GenerateProfiles() override; }; }; diff --git a/src/cascadia/ut_app/DynamicProfileTests.cpp b/src/cascadia/ut_app/DynamicProfileTests.cpp index 312bc0f1d0e..668cf7ba5ce 100644 --- a/src/cascadia/ut_app/DynamicProfileTests.cpp +++ b/src/cascadia/ut_app/DynamicProfileTests.cpp @@ -14,6 +14,7 @@ using namespace Microsoft::Console; using namespace TerminalApp; +using namespace winrt::TerminalApp; using namespace WEX::Logging; using namespace WEX::TestExecution; using namespace WEX::Common; @@ -63,7 +64,7 @@ namespace TerminalAppUnitTests gen.pfnGenerate = []() { std::vector profiles; Profile p0; - p0.SetName(L"profile0"); + p0.Name(L"profile0"); profiles.push_back(p0); return profiles; }; @@ -71,8 +72,8 @@ namespace TerminalAppUnitTests VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest", gen.GetNamespace()); std::vector profiles = gen.GenerateProfiles(); VERIFY_ARE_EQUAL(1u, profiles.size()); - VERIFY_ARE_EQUAL(L"profile0", profiles.at(0).GetName()); - VERIFY_IS_FALSE(profiles.at(0)._guid.has_value()); + VERIFY_ARE_EQUAL(L"profile0", profiles.at(0).Name()); + VERIFY_IS_FALSE(profiles.at(0).HasGuid()); } void DynamicProfileTests::TestSimpleGenerateMultipleGenerators() @@ -81,7 +82,7 @@ namespace TerminalAppUnitTests gen0->pfnGenerate = []() { std::vector profiles; Profile p0; - p0.SetName(L"profile0"); + p0.Name(L"profile0"); profiles.push_back(p0); return profiles; }; @@ -89,7 +90,7 @@ namespace TerminalAppUnitTests gen1->pfnGenerate = []() { std::vector profiles; Profile p0; - p0.SetName(L"profile1"); + p0.Name(L"profile1"); profiles.push_back(p0); return profiles; }; @@ -101,11 +102,11 @@ namespace TerminalAppUnitTests settings._LoadDynamicProfiles(); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).GetName()); - VERIFY_IS_FALSE(settings._profiles.at(0)._guid.has_value()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).Name()); + VERIFY_IS_FALSE(settings._profiles.at(0).HasGuid()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).GetName()); - VERIFY_IS_FALSE(settings._profiles.at(1)._guid.has_value()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).Name()); + VERIFY_IS_FALSE(settings._profiles.at(1).HasGuid()); } void DynamicProfileTests::TestGenGuidsForProfiles() @@ -119,7 +120,7 @@ namespace TerminalAppUnitTests gen0->pfnGenerate = []() { std::vector profiles; Profile p0; - p0.SetName(L"profile0"); // this is _profiles.at(2) + p0.Name(L"profile0"); // this is _profiles.at(2) profiles.push_back(p0); return profiles; }; @@ -127,8 +128,8 @@ namespace TerminalAppUnitTests gen1->pfnGenerate = []() { std::vector profiles; Profile p0, p1; - p0.SetName(L"profile0"); // this is _profiles.at(3) - p1.SetName(L"profile1"); // this is _profiles.at(4) + p0.Name(L"profile0"); // this is _profiles.at(3) + p1.Name(L"profile1"); // this is _profiles.at(4) profiles.push_back(p0); profiles.push_back(p1); return profiles; @@ -139,60 +140,60 @@ namespace TerminalAppUnitTests settings._profileGenerators.emplace_back(std::move(gen1)); Profile p0, p1; - p0.SetName(L"profile0"); // this is _profiles.at(0) - p1.SetName(L"profile1"); // this is _profiles.at(1) + p0.Name(L"profile0"); // this is _profiles.at(0) + p1.Name(L"profile1"); // this is _profiles.at(1) settings._profiles.push_back(p0); settings._profiles.push_back(p1); settings._LoadDynamicProfiles(); VERIFY_ARE_EQUAL(5u, settings._profiles.size()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).GetName()); - VERIFY_IS_FALSE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(0)._source.has_value()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).Name()); + VERIFY_IS_FALSE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(0).Source().empty()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).GetName()); - VERIFY_IS_FALSE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(1)._source.has_value()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).Name()); + VERIFY_IS_FALSE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).Source().empty()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(2).GetName()); - VERIFY_IS_FALSE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._source.has_value()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(2).Name()); + VERIFY_IS_FALSE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(2).Source().empty()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(3).GetName()); - VERIFY_IS_FALSE(settings._profiles.at(3)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._source.has_value()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(3).Name()); + VERIFY_IS_FALSE(settings._profiles.at(3).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(3).Source().empty()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(4).GetName()); - VERIFY_IS_FALSE(settings._profiles.at(4)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(4)._source.has_value()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(4).Name()); + VERIFY_IS_FALSE(settings._profiles.at(4).HasGuid()); + VERIFY_IS_FALSE(settings._profiles.at(4).Source().empty()); settings._ValidateProfilesHaveGuid(); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(4)._guid.has_value()); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(3).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(4).HasGuid()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0)._guid.value(), - settings._profiles.at(1)._guid.value()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0)._guid.value(), - settings._profiles.at(2)._guid.value()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0)._guid.value(), - settings._profiles.at(3)._guid.value()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).Guid(), + settings._profiles.at(1).Guid()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).Guid(), + settings._profiles.at(2).Guid()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(0).Guid(), + settings._profiles.at(3).Guid()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1)._guid.value(), - settings._profiles.at(4)._guid.value()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(1).Guid(), + settings._profiles.at(4).Guid()); - VERIFY_ARE_NOT_EQUAL(settings._profiles.at(3)._guid.value(), - settings._profiles.at(4)._guid.value()); + VERIFY_ARE_NOT_EQUAL(settings._profiles.at(3).Guid(), + settings._profiles.at(4).Guid()); } void DynamicProfileTests::DontLayerUserProfilesOnDynamicProfiles() { - GUID guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - GUID guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + winrt::guid guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + winrt::guid guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); const std::string userProfiles{ R"( { @@ -211,17 +212,18 @@ namespace TerminalAppUnitTests auto gen0 = std::make_unique(L"Terminal.App.UnitTest.0"); gen0->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }; - p0.SetName(L"profile0"); // this is _profiles.at(0) + Profile p0 = winrt::make(guid0); + p0.Name(L"profile0"); // this is _profiles.at(0) profiles.push_back(p0); return profiles; }; auto gen1 = std::make_unique(L"Terminal.App.UnitTest.1"); gen1->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }, p1{ guid1 }; - p0.SetName(L"profile0"); // this is _profiles.at(1) - p1.SetName(L"profile1"); // this is _profiles.at(2) + Profile p0 = winrt::make(guid0); + Profile p1 = winrt::make(guid1); + p0.Name(L"profile0"); // this is _profiles.at(1) + p1.Name(L"profile1"); // this is _profiles.at(2) profiles.push_back(p0); profiles.push_back(p1); return profiles; @@ -243,33 +245,33 @@ namespace TerminalAppUnitTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(5u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._source.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(3)._source.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(4)._source.has_value()); - - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.0", settings._profiles.at(0)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(2)._source.value()); - - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(4)._guid.has_value()); - - VERIFY_ARE_EQUAL(guid0, settings._profiles.at(0)._guid.value()); - VERIFY_ARE_EQUAL(guid0, settings._profiles.at(1)._guid.value()); - VERIFY_ARE_EQUAL(guid1, settings._profiles.at(2)._guid.value()); - VERIFY_ARE_EQUAL(guid0, settings._profiles.at(3)._guid.value()); - VERIFY_ARE_EQUAL(guid1, settings._profiles.at(4)._guid.value()); + VERIFY_IS_FALSE(settings._profiles.at(0).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(1).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(2).Source().empty()); + VERIFY_IS_TRUE(settings._profiles.at(3).Source().empty()); + VERIFY_IS_TRUE(settings._profiles.at(4).Source().empty()); + + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.0", settings._profiles.at(0).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(2).Source()); + + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(3).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(4).HasGuid()); + + VERIFY_ARE_EQUAL(guid0, settings._profiles.at(0).Guid()); + VERIFY_ARE_EQUAL(guid0, settings._profiles.at(1).Guid()); + VERIFY_ARE_EQUAL(guid1, settings._profiles.at(2).Guid()); + VERIFY_ARE_EQUAL(guid0, settings._profiles.at(3).Guid()); + VERIFY_ARE_EQUAL(guid1, settings._profiles.at(4).Guid()); } void DynamicProfileTests::DoLayerUserProfilesOnDynamicsWhenSourceMatches() { - GUID guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - GUID guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + winrt::guid guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + winrt::guid guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); const std::string userProfiles{ R"( { @@ -290,17 +292,18 @@ namespace TerminalAppUnitTests auto gen0 = std::make_unique(L"Terminal.App.UnitTest.0"); gen0->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }; - p0.SetName(L"profile0"); // this is _profiles.at(0) + Profile p0 = winrt::make(guid0); + p0.Name(L"profile0"); // this is _profiles.at(0) profiles.push_back(p0); return profiles; }; auto gen1 = std::make_unique(L"Terminal.App.UnitTest.1"); gen1->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }, p1{ guid1 }; - p0.SetName(L"profile0"); // this is _profiles.at(1) - p1.SetName(L"profile1"); // this is _profiles.at(2) + Profile p0 = winrt::make(guid0); + Profile p1 = winrt::make(guid1); + p0.Name(L"profile0"); // this is _profiles.at(1) + p1.Name(L"profile1"); // this is _profiles.at(2) profiles.push_back(p0); profiles.push_back(p1); return profiles; @@ -322,25 +325,25 @@ namespace TerminalAppUnitTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._source.has_value()); + VERIFY_IS_FALSE(settings._profiles.at(0).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(1).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(2).Source().empty()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.0", settings._profiles.at(0)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(2)._source.value()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.0", settings._profiles.at(0).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(2).Source()); - VERIFY_IS_TRUE(settings._profiles.at(0)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._guid.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._guid.has_value()); + VERIFY_IS_TRUE(settings._profiles.at(0).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(1).HasGuid()); + VERIFY_IS_TRUE(settings._profiles.at(2).HasGuid()); - VERIFY_ARE_EQUAL(guid0, settings._profiles.at(0)._guid.value()); - VERIFY_ARE_EQUAL(guid0, settings._profiles.at(1)._guid.value()); - VERIFY_ARE_EQUAL(guid1, settings._profiles.at(2)._guid.value()); + VERIFY_ARE_EQUAL(guid0, settings._profiles.at(0).Guid()); + VERIFY_ARE_EQUAL(guid0, settings._profiles.at(1).Guid()); + VERIFY_ARE_EQUAL(guid1, settings._profiles.at(2).Guid()); - VERIFY_ARE_EQUAL(L"profile0FromUserSettings", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile1FromUserSettings", settings._profiles.at(2)._name); + VERIFY_ARE_EQUAL(L"profile0FromUserSettings", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile1FromUserSettings", settings._profiles.at(2).Name()); } void DynamicProfileTests::TestDontRunDisabledGenerators() @@ -359,7 +362,7 @@ namespace TerminalAppUnitTests auto gen0GenerateFn = []() { std::vector profiles; Profile p0; - p0.SetName(L"profile0"); + p0.Name(L"profile0"); profiles.push_back(p0); return profiles; }; @@ -367,8 +370,8 @@ namespace TerminalAppUnitTests auto gen1GenerateFn = []() { std::vector profiles; Profile p0, p1; - p0.SetName(L"profile1"); - p1.SetName(L"profile2"); + p0.Name(L"profile1"); + p1.Name(L"profile2"); profiles.push_back(p0); profiles.push_back(p1); return profiles; @@ -377,8 +380,8 @@ namespace TerminalAppUnitTests auto gen2GenerateFn = []() { std::vector profiles; Profile p0, p1; - p0.SetName(L"profile3"); - p1.SetName(L"profile4"); + p0.Name(L"profile3"); + p1.Name(L"profile4"); profiles.push_back(p0); profiles.push_back(p1); return profiles; @@ -404,18 +407,18 @@ namespace TerminalAppUnitTests settings._LoadDynamicProfiles(); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._source.has_value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(0)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(2)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(3)._source.value()); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(3)._name); + VERIFY_IS_FALSE(settings._profiles.at(0).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(1).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(2).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(3).Source().empty()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(0).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.1", settings._profiles.at(1).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(2).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(3).Source()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(3).Name()); } { @@ -437,22 +440,22 @@ namespace TerminalAppUnitTests settings._LoadDynamicProfiles(); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._source.has_value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(0)._source.value()); - VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(1)._source.value()); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(1)._name); + VERIFY_IS_FALSE(settings._profiles.at(0).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(1).Source().empty()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(0).Source()); + VERIFY_ARE_EQUAL(L"Terminal.App.UnitTest.2", settings._profiles.at(1).Source()); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile4", settings._profiles.at(1).Name()); } } void DynamicProfileTests::TestLegacyProfilesMigrate() { - GUID guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); - GUID guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - GUID guid2 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); - GUID guid3 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); - GUID guid4 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}"); + winrt::guid guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-0000-49a3-80bd-e8fdd045185c}"); + winrt::guid guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + winrt::guid guid2 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + winrt::guid guid3 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-3333-49a3-80bd-e8fdd045185c}"); + winrt::guid guid4 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}"); const std::string settings0String{ R"( { @@ -489,17 +492,18 @@ namespace TerminalAppUnitTests auto gen0 = std::make_unique(L"Windows.Terminal.PowershellCore"); gen0->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }; - p0.SetName(L"profile0"); + Profile p0 = winrt::make(guid0); + p0.Name(L"profile0"); profiles.push_back(p0); return profiles; }; auto gen1 = std::make_unique(L"Windows.Terminal.Wsl"); gen1->pfnGenerate = [guid2, guid1]() { std::vector profiles; - Profile p0{ guid1 }, p1{ guid2 }; - p0.SetName(L"profile1"); - p1.SetName(L"profile2"); + Profile p0 = winrt::make(guid1); + Profile p1 = winrt::make(guid2); + p0.Name(L"profile1"); + p1.Name(L"profile2"); profiles.push_back(p0); profiles.push_back(p1); return profiles; @@ -507,8 +511,8 @@ namespace TerminalAppUnitTests auto gen2 = std::make_unique(L"Windows.Terminal.Azure"); gen2->pfnGenerate = [guid3]() { std::vector profiles; - Profile p0{ guid3 }; - p0.SetName(L"profile3"); + Profile p0 = winrt::make(guid3); + p0.Name(L"profile3"); profiles.push_back(p0); return profiles; }; @@ -524,43 +528,43 @@ namespace TerminalAppUnitTests settings._LoadDynamicProfiles(); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._source.has_value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.PowershellCore", settings._profiles.at(0)._source.value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(1)._source.value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(2)._source.value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.Azure", settings._profiles.at(3)._source.value()); - VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(3)._name); + VERIFY_IS_FALSE(settings._profiles.at(0).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(1).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(2).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(3).Source().empty()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.PowershellCore", settings._profiles.at(0).Source()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(1).Source()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(2).Source()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.Azure", settings._profiles.at(3).Source()); + VERIFY_ARE_EQUAL(L"profile0", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile1", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile2", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"profile3", settings._profiles.at(3).Name()); settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(5u, settings._profiles.size()); - VERIFY_IS_TRUE(settings._profiles.at(0)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(1)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(2)._source.has_value()); - VERIFY_IS_TRUE(settings._profiles.at(3)._source.has_value()); - VERIFY_IS_FALSE(settings._profiles.at(4)._source.has_value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.PowershellCore", settings._profiles.at(0)._source.value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(1)._source.value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(2)._source.value()); - VERIFY_ARE_EQUAL(L"Windows.Terminal.Azure", settings._profiles.at(3)._source.value()); + VERIFY_IS_FALSE(settings._profiles.at(0).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(1).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(2).Source().empty()); + VERIFY_IS_FALSE(settings._profiles.at(3).Source().empty()); + VERIFY_IS_TRUE(settings._profiles.at(4).Source().empty()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.PowershellCore", settings._profiles.at(0).Source()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(1).Source()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.Wsl", settings._profiles.at(2).Source()); + VERIFY_ARE_EQUAL(L"Windows.Terminal.Azure", settings._profiles.at(3).Source()); // settings._profiles.at(4) does not have a source - VERIFY_ARE_EQUAL(L"profile0FromUserSettings", settings._profiles.at(0)._name); - VERIFY_ARE_EQUAL(L"profile1FromUserSettings", settings._profiles.at(1)._name); - VERIFY_ARE_EQUAL(L"profile2FromUserSettings", settings._profiles.at(2)._name); - VERIFY_ARE_EQUAL(L"profile3FromUserSettings", settings._profiles.at(3)._name); - VERIFY_ARE_EQUAL(L"profile4FromUserSettings", settings._profiles.at(4)._name); + VERIFY_ARE_EQUAL(L"profile0FromUserSettings", settings._profiles.at(0).Name()); + VERIFY_ARE_EQUAL(L"profile1FromUserSettings", settings._profiles.at(1).Name()); + VERIFY_ARE_EQUAL(L"profile2FromUserSettings", settings._profiles.at(2).Name()); + VERIFY_ARE_EQUAL(L"profile3FromUserSettings", settings._profiles.at(3).Name()); + VERIFY_ARE_EQUAL(L"profile4FromUserSettings", settings._profiles.at(4).Name()); } void DynamicProfileTests::UserProfilesWithInvalidSourcesAreIgnored() { - GUID guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - GUID guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + winrt::guid guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + winrt::guid guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); const std::string settings0String{ R"( { @@ -585,17 +589,18 @@ namespace TerminalAppUnitTests auto gen0 = std::make_unique(L"Terminal.App.UnitTest.0"); gen0->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }; - p0.SetName(L"profile0"); // this is _profiles.at(0) + Profile p0 = winrt::make(guid0); + p0.Name(L"profile0"); // this is _profiles.at(0) profiles.push_back(p0); return profiles; }; auto gen1 = std::make_unique(L"Terminal.App.UnitTest.1"); gen1->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }, p1{ guid1 }; - p0.SetName(L"profile0"); // this is _profiles.at(1) - p1.SetName(L"profile1"); // this is _profiles.at(2) + Profile p0 = winrt::make(guid0); + Profile p1 = winrt::make(guid1); + p0.Name(L"profile0"); // this is _profiles.at(1) + p1.Name(L"profile1"); // this is _profiles.at(2) profiles.push_back(p0); profiles.push_back(p1); return profiles; @@ -617,8 +622,8 @@ namespace TerminalAppUnitTests void DynamicProfileTests::UserProfilesFromDisabledSourcesDontAppear() { - GUID guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); - GUID guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); + winrt::guid guid0 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}"); + winrt::guid guid1 = Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}"); const std::string settings0String{ R"( { @@ -644,17 +649,18 @@ namespace TerminalAppUnitTests auto gen0 = std::make_unique(L"Terminal.App.UnitTest.0"); gen0->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }; - p0.SetName(L"profile0"); // this is _profiles.at(0) + Profile p0 = winrt::make(guid0); + p0.Name(L"profile0"); // this is _profiles.at(0) profiles.push_back(p0); return profiles; }; auto gen1 = std::make_unique(L"Terminal.App.UnitTest.1"); gen1->pfnGenerate = [guid0, guid1]() { std::vector profiles; - Profile p0{ guid0 }, p1{ guid1 }; - p0.SetName(L"profile0"); // this shouldn't be in the profiles at all - p1.SetName(L"profile1"); // this shouldn't be in the profiles at all + Profile p0 = winrt::make(guid0); + Profile p1 = winrt::make(guid1); + p0.Name(L"profile0"); // this shouldn't be in the profiles at all + p1.Name(L"profile1"); // this shouldn't be in the profiles at all profiles.push_back(p0); profiles.push_back(p1); return profiles; diff --git a/src/cascadia/ut_app/JsonTests.cpp b/src/cascadia/ut_app/JsonTests.cpp index c145c48c1dc..d36f97123d6 100644 --- a/src/cascadia/ut_app/JsonTests.cpp +++ b/src/cascadia/ut_app/JsonTests.cpp @@ -94,10 +94,10 @@ namespace TerminalAppUnitTests const auto schemeObject = VerifyParseSucceeded(campbellScheme); auto scheme = implementation::ColorScheme::FromJson(schemeObject); VERIFY_ARE_EQUAL(L"Campbell", scheme->Name()); - VERIFY_ARE_EQUAL(til::color(0xf2, 0xf2, 0xf2, 255), scheme->Foreground()); - VERIFY_ARE_EQUAL(til::color(0x0c, 0x0c, 0x0c, 255), scheme->Background()); - VERIFY_ARE_EQUAL(til::color(0x13, 0x13, 0x13, 255), scheme->SelectionBackground()); - VERIFY_ARE_EQUAL(til::color(0xFF, 0xFF, 0xFF, 255), scheme->CursorColor()); + VERIFY_ARE_EQUAL(til::color(0xf2, 0xf2, 0xf2, 255), til::color{ scheme->Foreground() }); + VERIFY_ARE_EQUAL(til::color(0x0c, 0x0c, 0x0c, 255), til::color{ scheme->Background() }); + VERIFY_ARE_EQUAL(til::color(0x13, 0x13, 0x13, 255), til::color{ scheme->SelectionBackground() }); + VERIFY_ARE_EQUAL(til::color(0xFF, 0xFF, 0xFF, 255), til::color{ scheme->CursorColor() }); std::array expectedCampbellTable; auto campbellSpan = gsl::span(&expectedCampbellTable[0], COLOR_TABLE_SIZE); @@ -150,21 +150,21 @@ namespace TerminalAppUnitTests const auto profile3Json = VerifyParseSucceeded(profileWithNullGuid); const auto profile4Json = VerifyParseSucceeded(profileWithGuid); - const auto profile0 = Profile::FromJson(profile0Json); - const auto profile1 = Profile::FromJson(profile1Json); - const auto profile2 = Profile::FromJson(profile2Json); - const auto profile3 = Profile::FromJson(profile3Json); - const auto profile4 = Profile::FromJson(profile4Json); - const GUID cmdGuid = Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}"); - const GUID nullGuid{ 0 }; - - VERIFY_IS_FALSE(profile0._guid.has_value()); - VERIFY_IS_FALSE(profile1._guid.has_value()); - VERIFY_IS_FALSE(profile2._guid.has_value()); - VERIFY_IS_TRUE(profile3._guid.has_value()); - VERIFY_IS_TRUE(profile4._guid.has_value()); - - VERIFY_ARE_EQUAL(profile3.GetGuid(), nullGuid); - VERIFY_ARE_EQUAL(profile4.GetGuid(), cmdGuid); + const auto profile0 = implementation::Profile::FromJson(profile0Json); + const auto profile1 = implementation::Profile::FromJson(profile1Json); + const auto profile2 = implementation::Profile::FromJson(profile2Json); + const auto profile3 = implementation::Profile::FromJson(profile3Json); + const auto profile4 = implementation::Profile::FromJson(profile4Json); + const winrt::guid cmdGuid = Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}"); + const winrt::guid nullGuid{}; + + VERIFY_IS_FALSE(profile0->HasGuid()); + VERIFY_IS_FALSE(profile1->HasGuid()); + VERIFY_IS_FALSE(profile2->HasGuid()); + VERIFY_IS_TRUE(profile3->HasGuid()); + VERIFY_IS_TRUE(profile4->HasGuid()); + + VERIFY_ARE_EQUAL(profile3->Guid(), nullGuid); + VERIFY_ARE_EQUAL(profile4->Guid(), cmdGuid); } } diff --git a/src/cascadia/ut_app/TestDynamicProfileGenerator.h b/src/cascadia/ut_app/TestDynamicProfileGenerator.h index bda1608e5cb..698af689edd 100644 --- a/src/cascadia/ut_app/TestDynamicProfileGenerator.h +++ b/src/cascadia/ut_app/TestDynamicProfileGenerator.h @@ -29,16 +29,16 @@ class TerminalAppUnitTests::TestDynamicProfileGenerator final : std::wstring_view GetNamespace() override { return _namespace; }; - std::vector GenerateProfiles() override + std::vector GenerateProfiles() override { if (pfnGenerate) { return pfnGenerate(); } - return std::vector{}; + return std::vector{}; } std::wstring _namespace; - std::function()> pfnGenerate{ nullptr }; + std::function()> pfnGenerate{ nullptr }; }; diff --git a/src/cascadia/ut_app/precomp.h b/src/cascadia/ut_app/precomp.h index 3ab75f96a8b..51ff1f4474e 100644 --- a/src/cascadia/ut_app/precomp.h +++ b/src/cascadia/ut_app/precomp.h @@ -15,6 +15,8 @@ Author(s): #pragma once +// Manually include til after we include Windows.Foundation to give it winrt superpowers +#define BLOCK_TIL // This includes support libraries from the CRT, STL, WIL, and GSL #include "LibraryIncludes.h" // This is inexplicable, but for whatever reason, cppwinrt conflicts with the @@ -29,12 +31,6 @@ Author(s): #include #include "consoletaeftemplates.hpp" -// Common includes for most tests: -#include "../../inc/argb.h" -#include "../../inc/conattrs.hpp" -#include "../../types/inc/utils.hpp" -#include "../../inc/DefaultSettings.h" - // Are you thinking about adding WinRT things here? If so, you probably want to // add your test to TerminalApp.LocalTests, not TerminalApp.UnitTests. The // UnitTests run in CI, while the LocalTests do not. However, since the CI can't @@ -48,3 +44,12 @@ Author(s): #include #include #include + +// Manually include til after we include Windows.Foundation to give it winrt superpowers +#include "til.h" + +// Common includes for most tests: +#include "../../inc/argb.h" +#include "../../inc/conattrs.hpp" +#include "../../types/inc/utils.hpp" +#include "../../inc/DefaultSettings.h"