diff --git a/build/pipelines/ci.yml b/build/pipelines/ci.yml index 365e0f3abb1..0220419e550 100644 --- a/build/pipelines/ci.yml +++ b/build/pipelines/ci.yml @@ -3,6 +3,7 @@ trigger: branches: include: - master + - feature/* paths: exclude: - doc/* @@ -13,6 +14,7 @@ pr: branches: include: - master + - feature/* paths: exclude: - doc/* diff --git a/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp b/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp index ab56263cad0..e59d022f526 100644 --- a/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp @@ -195,7 +195,7 @@ namespace TerminalAppLocalTests CascadiaSettings settings; - VERIFY_ARE_EQUAL(0u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(0u, settings._globals->GetColorSchemes().Size()); VERIFY_IS_NULL(settings._FindMatchingColorScheme(scheme0Json)); VERIFY_IS_NULL(settings._FindMatchingColorScheme(scheme1Json)); VERIFY_IS_NULL(settings._FindMatchingColorScheme(scheme2Json)); @@ -203,15 +203,15 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme0Json); { - for (auto& kv : settings._globals._colorSchemes) + for (auto kv : settings._globals->GetColorSchemes()) { Log::Comment(NoThrowString().Format( - L"kv:%s->%s", kv.first.data(), kv.second.Name().data())); + L"kv:%s->%s", kv.Key().data(), kv.Value().Name().data())); } - VERIFY_ARE_EQUAL(1u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(1u, settings._globals->GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals->GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); @@ -225,13 +225,13 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme1Json); { - VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(2u, settings._globals->GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals->GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme1") != settings._globals._colorSchemes.end()); - auto scheme1Proj = settings._globals._colorSchemes.find(L"scheme1")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"scheme1")); + auto scheme1Proj = settings._globals->GetColorSchemes().Lookup(L"scheme1"); auto scheme1 = winrt::get_self(scheme1Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); @@ -246,13 +246,13 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme2Json); { - VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(2u, settings._globals->GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals->GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme1") != settings._globals._colorSchemes.end()); - auto scheme1Proj = settings._globals._colorSchemes.find(L"scheme1")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"scheme1")); + auto scheme1Proj = settings._globals->GetColorSchemes().Lookup(L"scheme1"); auto scheme1 = winrt::get_self(scheme1Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); @@ -267,16 +267,16 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme3Json); { - VERIFY_ARE_EQUAL(3u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(3u, settings._globals->GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals->GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme1") != settings._globals._colorSchemes.end()); - auto scheme1Proj = settings._globals._colorSchemes.find(L"scheme1")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"scheme1")); + auto scheme1Proj = settings._globals->GetColorSchemes().Lookup(L"scheme1"); auto scheme1 = winrt::get_self(scheme1Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"") != settings._globals._colorSchemes.end()); - auto scheme2Proj = settings._globals._colorSchemes.find(L"")->second; + VERIFY_IS_TRUE(settings._globals->GetColorSchemes().HasKey(L"")); + auto scheme2Proj = settings._globals->GetColorSchemes().Lookup(L""); auto scheme2 = winrt::get_self(scheme2Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); 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..91c45987ce7 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -106,7 +106,7 @@ namespace TerminalAppLocalTests } private: - void _logCommandNames(winrt::Windows::Foundation::Collections::IMap& commands, const int indentation = 1) + void _logCommandNames(winrt::Windows::Foundation::Collections::IMapView commands, const int indentation = 1) { if (indentation == 1) { @@ -125,7 +125,7 @@ namespace TerminalAppLocalTests cmdImpl.copy_from(winrt::get_self(nameAndCommand.Value())); if (cmdImpl->HasNestedCommands()) { - _logCommandNames(cmdImpl->_subcommands, indentation + 2); + _logCommandNames(cmdImpl->_subcommands.GetView(), indentation + 2); } } } @@ -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(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(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(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(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(::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}")); + profile0.Name(L"profile0"); + Profile profile1 = winrt::make(::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}")); + profile1.Name(L"profile1"); + Profile profile2 = winrt::make(::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}")); + profile2.Name(L"profile2"); + Profile profile3 = winrt::make(::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}")); + profile3.Name(L"profile3"); + Profile profile4 = winrt::make(::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-6666-49a3-80bd-e8fdd045185c}")); + profile4.Name(L"profile4"); + Profile profile5 = winrt::make(::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}")); + profile5.Name(L"profile5"); + Profile profile6 = winrt::make(::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(::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-4444-49a3-80bd-e8fdd045185c}")); + profile4.Name(L"profile4"); + Profile profile5 = winrt::make(::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(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() @@ -522,16 +522,16 @@ namespace TerminalAppLocalTests CascadiaSettings settings; settings.LayerJson(settings0Json); - VERIFY_ARE_EQUAL(true, settings._globals._AlwaysShowTabs); - VERIFY_ARE_EQUAL(120, settings._globals._InitialCols); - VERIFY_ARE_EQUAL(30, settings._globals._InitialRows); - VERIFY_ARE_EQUAL(true, settings._globals._ShowTabsInTitlebar); + VERIFY_ARE_EQUAL(true, settings._globals->AlwaysShowTabs()); + VERIFY_ARE_EQUAL(120, settings._globals->InitialCols()); + VERIFY_ARE_EQUAL(30, settings._globals->InitialRows()); + VERIFY_ARE_EQUAL(true, settings._globals->ShowTabsInTitlebar()); settings.LayerJson(settings1Json); - VERIFY_ARE_EQUAL(true, settings._globals._AlwaysShowTabs); - VERIFY_ARE_EQUAL(240, settings._globals._InitialCols); - VERIFY_ARE_EQUAL(60, settings._globals._InitialRows); - VERIFY_ARE_EQUAL(false, settings._globals._ShowTabsInTitlebar); + VERIFY_ARE_EQUAL(true, settings._globals->AlwaysShowTabs()); + VERIFY_ARE_EQUAL(240, settings._globals->InitialCols()); + VERIFY_ARE_EQUAL(60, settings._globals->InitialRows()); + VERIFY_ARE_EQUAL(false, settings._globals->ShowTabsInTitlebar()); } void SettingsTests::ValidateProfileOrdering() @@ -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() @@ -1329,11 +1330,11 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); + VERIFY_ARE_EQUAL(2u, settings._globals->GetColorSchemes().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(); @@ -1341,11 +1342,11 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::UnknownColorScheme, settings._warnings.at(0)); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); + VERIFY_ARE_EQUAL(2u, settings._globals->GetColorSchemes().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{}; + const winrt::guid guid0{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }; + const winrt::guid guid1{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-6666-49a3-80bd-e8fdd045185c}") }; + const winrt::guid guid2{ ::Microsoft::Console::Utils::GuidFromString(L"{2C4DE342-38B7-51CF-B940-2309A097F518}") }; + const winrt::guid fakeGuid{ ::Microsoft::Console::Utils::GuidFromString(L"{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}") }; + const 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() @@ -1449,8 +1450,9 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_IS_FALSE(settings._profiles.empty()); - GlobalAppSettings globalSettings{}; - auto terminalSettings = settings._profiles[0].CreateTerminalSettings(globalSettings.GetColorSchemes()); + auto globalSettings{ winrt::make() }; + 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() @@ -1552,11 +1554,11 @@ namespace TerminalAppLocalTests VERIFY_IS_FALSE(settings._userDefaultProfileSettings == Json::Value::null); settings.LayerJson(settings._userSettings); - VERIFY_ARE_EQUAL(guid1String, settings._globals._unparsedDefaultProfile); + 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(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}"); + const winrt::guid guid1{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}") }; + const winrt::guid guid2{ ::Microsoft::Console::Utils::GuidFromString(L"{6239a42c-2222-49a3-80bd-e8fdd045185c}") }; + const 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{}; @@ -1791,12 +1794,13 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); settings._ValidateSettings(); - auto appKeyBindings = settings._globals._keybindings; + auto appKeyBindingsProj = settings._globals->GetKeybindings(); 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); + const auto appKeyBindings = winrt::get_self(appKeyBindingsProj); VERIFY_ARE_EQUAL(12u, appKeyBindings->_keyShortcuts.size()); { @@ -2066,20 +2070,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 +2109,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 +2177,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(settings->_globals->DefaultProfile(), settings->_profiles.at(0).Guid()); try { const auto [guid, termSettings] = settings->BuildSettings(nullptr); @@ -2238,14 +2242,14 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(6u, settings._profiles.size()); - VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); + VERIFY_ARE_EQUAL(2u, settings._globals->GetColorSchemes().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->GetColorSchemes()); + auto terminalSettings1 = winrt::get_self(settings._profiles[1])->CreateTerminalSettings(settings._globals->GetColorSchemes()); + auto terminalSettings2 = winrt::get_self(settings._profiles[2])->CreateTerminalSettings(settings._globals->GetColorSchemes()); + auto terminalSettings3 = winrt::get_self(settings._profiles[3])->CreateTerminalSettings(settings._globals->GetColorSchemes()); + auto terminalSettings4 = winrt::get_self(settings._profiles[4])->CreateTerminalSettings(settings._globals->GetColorSchemes()); + auto terminalSettings5 = winrt::get_self(settings._profiles[5])->CreateTerminalSettings(settings._globals->GetColorSchemes()); VERIFY_ARE_EQUAL(ARGB(0, 0x12, 0x34, 0x56), terminalSettings0.CursorColor()); // from color scheme VERIFY_ARE_EQUAL(DEFAULT_CURSOR_COLOR, terminalSettings1.CursorColor()); // default @@ -2280,12 +2284,12 @@ namespace TerminalAppLocalTests const auto settingsObject = VerifyParseSucceeded(badSettings); auto settings = CascadiaSettings::FromJson(settingsObject); - VERIFY_ARE_EQUAL(0u, settings->_globals._keybindings->_keyShortcuts.size()); + VERIFY_ARE_EQUAL(0u, settings->_globals->_keybindings->_keyShortcuts.size()); - VERIFY_ARE_EQUAL(3u, settings->_globals._keybindingsWarnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, settings->_globals._keybindingsWarnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(2)); + VERIFY_ARE_EQUAL(3u, settings->_globals->_keybindingsWarnings.size()); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, settings->_globals->_keybindingsWarnings.at(0)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(1)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(2)); settings->_ValidateKeybindings(); @@ -2322,17 +2326,17 @@ namespace TerminalAppLocalTests auto settings = CascadiaSettings::FromJson(settingsObject); - VERIFY_ARE_EQUAL(0u, settings->_globals._keybindings->_keyShortcuts.size()); + VERIFY_ARE_EQUAL(0u, settings->_globals->_keybindings->_keyShortcuts.size()); - for (const auto& warning : settings->_globals._keybindingsWarnings) + for (const auto& warning : settings->_globals->_keybindingsWarnings) { Log::Comment(NoThrowString().Format( L"warning:%d", warning)); } - VERIFY_ARE_EQUAL(3u, settings->_globals._keybindingsWarnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(2)); + VERIFY_ARE_EQUAL(3u, settings->_globals->_keybindingsWarnings.size()); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(0)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(1)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals->_keybindingsWarnings.at(2)); settings->_ValidateKeybindings(); @@ -2448,8 +2452,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,16 +2463,16 @@ 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; + auto appKeyBindings = winrt::get_self(settings._globals->GetKeybindings()); VERIFY_ARE_EQUAL(5u, appKeyBindings->_keyShortcuts.size()); // A/D, B, C, E will be in the list of commands, for 4 total. // * A and D share the same name, so they'll only generate a single action. // * F's name is set manually to `null` - auto commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); VERIFY_ARE_EQUAL(4u, commands.Size()); { @@ -2650,8 +2654,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{}; @@ -2662,7 +2666,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -2683,8 +2687,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile()); } - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); @@ -2780,8 +2784,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{}; @@ -2792,7 +2796,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -2813,8 +2817,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile()); } - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); @@ -2912,8 +2916,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{}; @@ -2924,7 +2928,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -2946,8 +2950,8 @@ namespace TerminalAppLocalTests } settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); @@ -3065,10 +3069,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3173,10 +3177,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3312,10 +3316,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); @@ -3334,7 +3338,7 @@ namespace TerminalAppLocalTests VERIFY_IS_TRUE(commandImpl->HasNestedCommands()); VERIFY_ARE_EQUAL(3u, commandImpl->_subcommands.Size()); - _logCommandNames(commandImpl->_subcommands); + _logCommandNames(commandImpl->_subcommands.GetView()); { winrt::hstring childCommandName{ fmt::format(L"Split pane, profile: {}", name) }; auto childCommandProj = commandImpl->_subcommands.Lookup(childCommandName); @@ -3465,10 +3469,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3578,10 +3582,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3610,7 +3614,7 @@ namespace TerminalAppLocalTests VERIFY_IS_TRUE(commandImpl->HasNestedCommands()); VERIFY_ARE_EQUAL(3u, commandImpl->_subcommands.Size()); - _logCommandNames(commandImpl->_subcommands); + _logCommandNames(commandImpl->_subcommands.GetView()); { winrt::hstring childCommandName{ fmt::format(L"Split pane, profile: {}", name) }; auto childCommandProj = commandImpl->_subcommands.Lookup(childCommandName); @@ -3739,7 +3743,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); _logCommandNames(commands); @@ -3816,7 +3820,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); _logCommandNames(commands); @@ -3899,7 +3903,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); settings._ValidateSettings(); _logCommandNames(commands); @@ -3995,7 +3999,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals->GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -4016,8 +4020,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"${scheme.name}", realArgs.TerminalArgs().Profile()); } - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals->GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); 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/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 3f75052d8c1..964b212d4a6 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -562,7 +562,7 @@ namespace winrt::TerminalApp::implementation // - defaultInitialY: the system default y coordinate value // Return Value: // - a point containing the requested initial position in pixels. - winrt::Windows::Foundation::Point AppLogic::GetLaunchInitialPositions(int32_t defaultInitialX, int32_t defaultInitialY) + TerminalApp::InitialPosition AppLogic::GetInitialPosition(int64_t defaultInitialX, int64_t defaultInitialY) { if (!_loadedInitialSettings) { @@ -571,12 +571,10 @@ namespace winrt::TerminalApp::implementation } const auto initialPosition{ _settings->GlobalSettings().InitialPosition() }; - winrt::Windows::Foundation::Point point{ - /* X */ gsl::narrow_cast(initialPosition.x.value_or(defaultInitialX)), - /* Y */ gsl::narrow_cast(initialPosition.y.value_or(defaultInitialY)) + return { + initialPosition.X ? initialPosition.X.Value() : defaultInitialX, + initialPosition.Y ? initialPosition.Y.Value() : defaultInitialY }; - - return point; } winrt::Windows::UI::Xaml::ElementTheme AppLogic::GetRequestedTheme() diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index c0c75952b1a..a5e811a886b 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -38,7 +38,7 @@ namespace winrt::TerminalApp::implementation bool AlwaysOnTop() const; Windows::Foundation::Size GetLaunchDimensions(uint32_t dpi); - winrt::Windows::Foundation::Point GetLaunchInitialPositions(int32_t defaultInitialX, int32_t defaultInitialY); + TerminalApp::InitialPosition GetInitialPosition(int64_t defaultInitialX, int64_t defaultInitialY); winrt::Windows::UI::Xaml::ElementTheme GetRequestedTheme(); LaunchMode GetLaunchMode(); bool GetShowTabsInTitlebar(); diff --git a/src/cascadia/TerminalApp/AppLogic.idl b/src/cascadia/TerminalApp/AppLogic.idl index 73b77b54413..838b40e1a67 100644 --- a/src/cascadia/TerminalApp/AppLogic.idl +++ b/src/cascadia/TerminalApp/AppLogic.idl @@ -7,6 +7,12 @@ import "IDirectKeyListener.idl"; namespace TerminalApp { + struct InitialPosition + { + Int64 X; + Int64 Y; + }; + enum LaunchMode { DefaultMode, @@ -47,7 +53,7 @@ namespace TerminalApp Windows.Foundation.Size GetLaunchDimensions(UInt32 dpi); - Windows.Foundation.Point GetLaunchInitialPositions(Int32 defaultInitialX, Int32 defaultInitialY); + InitialPosition GetInitialPosition(Int64 defaultInitialX, Int64 defaultInitialY); Windows.UI.Xaml.ElementTheme GetRequestedTheme(); LaunchMode GetLaunchMode(); Boolean GetShowTabsInTitlebar(); diff --git a/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp b/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp index 0c9ff1f4c19..0463adf160f 100644 --- a/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp +++ b/src/cascadia/TerminalApp/AzureCloudShellGenerator.cpp @@ -15,6 +15,7 @@ #include "DefaultProfileUtils.h" using namespace ::TerminalApp; +using namespace winrt::TerminalApp; std::wstring_view AzureCloudShellGenerator::GetNamespace() { @@ -28,19 +29,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 443fd0c5576..80f9769885f 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettings.cpp @@ -53,7 +53,8 @@ CascadiaSettings::CascadiaSettings() : // generators. Set this to `false` for unit testing. // Arguments: // - addDynamicProfiles: if true, we'll add the built-in DPGs. -CascadiaSettings::CascadiaSettings(const bool addDynamicProfiles) +CascadiaSettings::CascadiaSettings(const bool addDynamicProfiles) : + _globals{ winrt::make_self() } { if (addDynamicProfiles) { @@ -71,15 +72,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(); @@ -106,7 +108,7 @@ gsl::span CascadiaSettings::GetProfiles() const noexcept // - the globally configured keybindings AppKeyBindings CascadiaSettings::GetKeybindings() const noexcept { - return _globals.GetKeybindings(); + return _globals->GetKeybindings(); } // Method Description: @@ -115,9 +117,9 @@ AppKeyBindings CascadiaSettings::GetKeybindings() const noexcept // - // Return Value: // - a reference to our global settings -GlobalAppSettings& CascadiaSettings::GlobalSettings() +winrt::TerminalApp::GlobalAppSettings CascadiaSettings::GlobalSettings() { - return _globals; + return *_globals; } // Method Description: @@ -216,7 +218,8 @@ void CascadiaSettings::_ValidateProfilesHaveGuid() { for (auto& profile : _profiles) { - profile.GenerateGuidIfNecessary(); + auto profileImpl = winrt::get_self(profile); + profileImpl->GenerateGuidIfNecessary(); } } @@ -226,10 +229,10 @@ void CascadiaSettings::_ValidateProfilesHaveGuid() void CascadiaSettings::_ResolveDefaultProfile() { const auto unparsedDefaultProfile{ GlobalSettings().UnparsedDefaultProfile() }; - if (unparsedDefaultProfile) + if (!unparsedDefaultProfile.empty()) { - auto maybeParsedDefaultProfile{ _GetProfileGuidByName(*unparsedDefaultProfile) }; - auto defaultProfileGuid{ til::coalesce_value(maybeParsedDefaultProfile, GUID{}) }; + auto maybeParsedDefaultProfile{ _GetProfileGuidByName(unparsedDefaultProfile) }; + auto defaultProfileGuid{ til::coalesce_value(maybeParsedDefaultProfile, winrt::guid{}) }; GlobalSettings().DefaultProfile(defaultProfileGuid); } } @@ -243,12 +246,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; @@ -262,7 +265,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()); } } @@ -278,13 +281,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); @@ -315,15 +318,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); @@ -337,7 +340,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] @@ -348,7 +351,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); @@ -374,7 +377,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 @@ -403,15 +406,11 @@ void CascadiaSettings::_ValidateAllSchemesExist() bool foundInvalidScheme = false; for (auto& profile : _profiles) { - auto schemeName = profile.GetSchemeName(); - if (schemeName.has_value()) + const auto schemeName = profile.ColorSchemeName(); + if (!_globals->GetColorSchemes().HasKey(schemeName)) { - const auto found = _globals.GetColorSchemes().find(schemeName.value()); - if (found == _globals.GetColorSchemes().end()) - { - profile.SetColorScheme({ L"Campbell" }); - foundInvalidScheme = true; - } + profile.ColorSchemeName({ L"Campbell" }); + foundInvalidScheme = true; } } @@ -439,7 +438,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. @@ -449,12 +448,13 @@ void CascadiaSettings::_ValidateMediaResources() } catch (...) { - profile.ResetBackgroundImagePath(); + // reset background image path + profile.BackgroundImagePath(L""); invalidBackground = true; } } - if (profile.HasIcon()) + if (!profile.IconPath().empty()) { try { @@ -462,7 +462,8 @@ void CascadiaSettings::_ValidateMediaResources() } catch (...) { - profile.ResetIconPath(); + // reset icon path + profile.IconPath(L""); invalidIcon = true; } } @@ -494,9 +495,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) @@ -526,16 +527,17 @@ 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); + _globals->ApplyToSettings(result); return result; } @@ -556,9 +558,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) @@ -569,7 +571,7 @@ GUID CascadiaSettings::_GetProfileForArgs(const NewTerminalArgs& newTerminalArgs profileByName = _GetProfileGuidByName(newTerminalArgs.Profile()); } - return til::coalesce_value(profileByName, profileByIndex, _globals.DefaultProfile()); + return til::coalesce_value(profileByName, profileByIndex, _globals->DefaultProfile()); } // Method Description: @@ -578,7 +580,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 @@ -603,12 +605,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(); } } @@ -630,7 +632,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) { @@ -640,7 +642,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; @@ -657,7 +659,7 @@ std::optional CascadiaSettings::_GetProfileGuidByIndex(std::optional // - void CascadiaSettings::_ValidateKeybindings() { - auto keybindingWarnings = _globals.GetKeybindingsWarnings(); + auto keybindingWarnings = _globals->GetKeybindingsWarnings(); if (!keybindingWarnings.empty()) { @@ -735,23 +737,15 @@ 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"; - auto scheme = _globals.GetColorSchemes().find(schemeName); - if (scheme != _globals.GetColorSchemes().end()) - { - return scheme->second; - } - else - { - return nullptr; - } + const auto schemeName = profile.ColorSchemeName(); + return _globals->GetColorSchemes().TryLookup(schemeName); } // Method Description: @@ -764,13 +758,10 @@ const ColorScheme CascadiaSettings::GetColorSchemeForProfile(const GUID profileG // Return Value: // - true iff we found a matching scheme for the name schemeName bool CascadiaSettings::ApplyColorScheme(winrt::Microsoft::Terminal::TerminalControl::IControlSettings& settings, - std::wstring_view schemeName) + winrt::hstring schemeName) { - std::wstring name{ schemeName }; - auto schemeAndName = _globals.GetColorSchemes().find(name); - if (schemeAndName != _globals.GetColorSchemes().end()) + if (auto scheme{ _globals->GetColorSchemes().TryLookup(schemeName) }) { - const auto& scheme = schemeAndName->second; scheme.ApplyScheme(settings); return true; } diff --git a/src/cascadia/TerminalApp/CascadiaSettings.h b/src/cascadia/TerminalApp/CascadiaSettings.h index def568424f5..b2c0d3d87c6 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(); + winrt::TerminalApp::GlobalAppSettings GlobalSettings(); - gsl::span GetProfiles() const noexcept; + gsl::span GetProfiles() const noexcept; winrt::TerminalApp::AppKeyBindings GetKeybindings() const noexcept; @@ -79,16 +79,16 @@ 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(); - bool ApplyColorScheme(winrt::Microsoft::Terminal::TerminalControl::IControlSettings& settings, std::wstring_view schemeName); + bool ApplyColorScheme(winrt::Microsoft::Terminal::TerminalControl::IControlSettings& settings, winrt::hstring schemeName); private: - GlobalAppSettings _globals; - std::vector _profiles; + winrt::com_ptr _globals; + 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 c747f216ba4..88f93647849 100644 --- a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp @@ -328,7 +328,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); } @@ -453,7 +453,8 @@ bool CascadiaSettings::_AppendDynamicProfilesToUserSettings() { if (profileJson.isObject()) { - if (profile.ShouldBeLayered(profileJson)) + const auto profileImpl = winrt::get_self(profile); + if (profileImpl->ShouldBeLayered(profileJson)) { return true; } @@ -503,7 +504,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 @@ -559,7 +561,7 @@ std::unique_ptr CascadiaSettings::FromJson(const Json::Value& // void CascadiaSettings::LayerJson(const Json::Value& json) { - _globals.LayerJson(json); + _globals->LayerJson(json); if (auto schemes{ json[SchemesKey.data()] }) { @@ -606,19 +608,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); } } } @@ -634,17 +636,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; @@ -686,7 +685,8 @@ void CascadiaSettings::_ApplyDefaultsFromUserSettings() for (auto& profile : _profiles) { - profile.LayerJson(_userDefaultProfileSettings); + auto profileImpl = winrt::get_self(profile); + profileImpl->LayerJson(_userDefaultProfileSettings); } } } @@ -710,7 +710,7 @@ void CascadiaSettings::_LayerOrCreateColorScheme(const Json::Value& schemeJson) else { const auto scheme = implementation::ColorScheme::FromJson(schemeJson); - _globals.AddColorScheme(*scheme); + _globals->AddColorScheme(*scheme); } } @@ -729,11 +729,9 @@ winrt::com_ptr CascadiaSettings::_FindMatchingColor { if (auto schemeName = implementation::ColorScheme::GetNameFromJson(schemeJson)) { - auto& schemes = _globals.GetColorSchemes(); - auto iterator = schemes.find(*schemeName); - if (iterator != schemes.end()) + if (auto scheme{ _globals->GetColorSchemes().TryLookup(*schemeName) }) { - return winrt::get_self(iterator->second)->get_strong(); + return winrt::get_self(scheme)->get_strong(); } } return nullptr; diff --git a/src/cascadia/TerminalApp/Command.cpp b/src/cascadia/TerminalApp/Command.cpp index 94b4a52eb0a..ad82aefb9a3 100644 --- a/src/cascadia/TerminalApp/Command.cpp +++ b/src/cascadia/TerminalApp/Command.cpp @@ -354,7 +354,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) { @@ -410,7 +410,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) { @@ -467,7 +467,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..6f3d374c1d1 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); @@ -60,7 +60,7 @@ namespace winrt::TerminalApp::implementation OBSERVABLE_GETSET_PROPERTY(winrt::hstring, KeyChordText, _PropertyChangedHandlers); OBSERVABLE_GETSET_PROPERTY(winrt::Windows::UI::Xaml::Controls::IconSource, IconSource, _PropertyChangedHandlers, nullptr); - GETSET_PROPERTY(::TerminalApp::ExpandCommandType, IterateOn, ::TerminalApp::ExpandCommandType::None); + GETSET_PROPERTY(ExpandCommandType, IterateOn, ExpandCommandType::None); private: Json::Value _originalJson; @@ -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 9c99a7c6a65..5888f5782ec 100644 --- a/src/cascadia/TerminalApp/DefaultProfileUtils.cpp +++ b/src/cascadia/TerminalApp/DefaultProfileUtils.cpp @@ -16,19 +16,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/GlobalAppSettings.cpp b/src/cascadia/TerminalApp/GlobalAppSettings.cpp index 0bc52b55e78..72c6bb64816 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalApp/GlobalAppSettings.cpp @@ -10,8 +10,10 @@ #include "JsonUtils.h" #include "TerminalSettingsSerializationHelpers.h" +#include "GlobalAppSettings.g.cpp" + using namespace TerminalApp; -using namespace winrt::TerminalApp; +using namespace winrt::TerminalApp::implementation; using namespace winrt::Windows::UI::Xaml; using namespace ::Microsoft::Console; using namespace winrt::Microsoft::UI::Xaml::Controls; @@ -52,52 +54,40 @@ static constexpr bool debugFeaturesDefault{ false }; #endif GlobalAppSettings::GlobalAppSettings() : - _keybindings{ winrt::make_self() }, + _keybindings{ winrt::make_self() }, _keybindingsWarnings{}, - _colorSchemes{}, - _unparsedDefaultProfile{ std::nullopt }, + _unparsedDefaultProfile{}, _defaultProfile{}, - _InitialRows{ DEFAULT_ROWS }, - _InitialCols{ DEFAULT_COLS }, - _WordDelimiters{ DEFAULT_WORD_DELIMITERS }, _DebugFeaturesEnabled{ debugFeaturesDefault } { _commands = winrt::single_threaded_map(); + _colorSchemes = winrt::single_threaded_map(); } -GlobalAppSettings::~GlobalAppSettings() -{ -} - -std::unordered_map& GlobalAppSettings::GetColorSchemes() noexcept -{ - return _colorSchemes; -} - -const std::unordered_map& GlobalAppSettings::GetColorSchemes() const noexcept +winrt::Windows::Foundation::Collections::IMapView GlobalAppSettings::GetColorSchemes() noexcept { - return _colorSchemes; + return _colorSchemes.GetView(); } -void GlobalAppSettings::DefaultProfile(const GUID defaultProfile) noexcept +void GlobalAppSettings::DefaultProfile(const winrt::guid& defaultProfile) noexcept { - _unparsedDefaultProfile.reset(); + _unparsedDefaultProfile.clear(); _defaultProfile = defaultProfile; } -GUID GlobalAppSettings::DefaultProfile() const +winrt::guid GlobalAppSettings::DefaultProfile() const { // If we have an unresolved default profile, we should likely explode. - THROW_HR_IF(E_INVALIDARG, _unparsedDefaultProfile.has_value()); + THROW_HR_IF(E_INVALIDARG, !_unparsedDefaultProfile.empty()); return _defaultProfile; } -std::optional GlobalAppSettings::UnparsedDefaultProfile() const +winrt::hstring GlobalAppSettings::UnparsedDefaultProfile() const { return _unparsedDefaultProfile; } -AppKeyBindings GlobalAppSettings::GetKeybindings() const noexcept +winrt::TerminalApp::AppKeyBindings GlobalAppSettings::GetKeybindings() const noexcept { return *_keybindings; } @@ -108,7 +98,7 @@ AppKeyBindings GlobalAppSettings::GetKeybindings() const noexcept // - settings: a TerminalSettings object to add global property values to. // Return Value: // - -void GlobalAppSettings::ApplyToSettings(TerminalSettings& settings) const noexcept +void GlobalAppSettings::ApplyToSettings(const TerminalApp::TerminalSettings& settings) const noexcept { settings.KeyBindings(GetKeybindings()); settings.InitialRows(_InitialRows); @@ -127,10 +117,10 @@ void GlobalAppSettings::ApplyToSettings(TerminalSettings& settings) const noexce // - json: an object which should be a serialization of a GlobalAppSettings object. // Return Value: // - a new GlobalAppSettings instance created from the values in `json` -GlobalAppSettings GlobalAppSettings::FromJson(const Json::Value& json) +winrt::com_ptr GlobalAppSettings::FromJson(const Json::Value& json) { - GlobalAppSettings result; - result.LayerJson(json); + auto result = winrt::make_self(); + result->LayerJson(json); return result; } @@ -215,10 +205,9 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) // - scheme: the color scheme to add // Return Value: // - -void GlobalAppSettings::AddColorScheme(ColorScheme scheme) +void GlobalAppSettings::AddColorScheme(const winrt::TerminalApp::ColorScheme& scheme) { - std::wstring name{ scheme.Name() }; - _colorSchemes[name] = std::move(scheme); + _colorSchemes.Insert(scheme.Name(), scheme); } // Method Description: @@ -235,12 +224,7 @@ std::vector GlobalAppSettings::GetKeybindings return _keybindingsWarnings; } -const winrt::Windows::Foundation::Collections::IMap& GlobalAppSettings::GetCommands() const noexcept -{ - return _commands; -} - -winrt::Windows::Foundation::Collections::IMap& GlobalAppSettings::GetCommands() noexcept +winrt::Windows::Foundation::Collections::IMapView GlobalAppSettings::GetCommands() noexcept { - return _commands; + return _commands.GetView(); } diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.h b/src/cascadia/TerminalApp/GlobalAppSettings.h index d78d15a8e34..82d385a9434 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.h +++ b/src/cascadia/TerminalApp/GlobalAppSettings.h @@ -14,11 +14,12 @@ Author(s): --*/ #pragma once + +#include "GlobalAppSettings.g.h" + #include "AppKeyBindings.h" #include "Command.h" -#include "SettingsTypes.h" - -#include "ColorScheme.g.h" +#include "ColorScheme.h" // fwdecl unittest classes namespace TerminalAppLocalTests @@ -27,73 +28,68 @@ namespace TerminalAppLocalTests class ColorSchemeTests; }; -namespace TerminalApp +namespace winrt::TerminalApp::implementation { - class GlobalAppSettings; -}; - -class TerminalApp::GlobalAppSettings final -{ -public: - GlobalAppSettings(); - ~GlobalAppSettings(); - - std::unordered_map& GetColorSchemes() noexcept; - const std::unordered_map& GetColorSchemes() const noexcept; - void AddColorScheme(winrt::TerminalApp::ColorScheme scheme); - - winrt::TerminalApp::AppKeyBindings GetKeybindings() const noexcept; - - static GlobalAppSettings FromJson(const Json::Value& json); - void LayerJson(const Json::Value& json); - - void ApplyToSettings(winrt::TerminalApp::TerminalSettings& settings) const noexcept; - - std::vector GetKeybindingsWarnings() const; - - const winrt::Windows::Foundation::Collections::IMap& GetCommands() const noexcept; - winrt::Windows::Foundation::Collections::IMap& GetCommands() noexcept; - - // These are implemented manually to handle the string/GUID exchange - // by higher layers in the app. - void DefaultProfile(const GUID defaultProfile) noexcept; - GUID DefaultProfile() const; - std::optional UnparsedDefaultProfile() const; - - GETSET_PROPERTY(int32_t, InitialRows); // default value set in constructor - GETSET_PROPERTY(int32_t, InitialCols); // default value set in constructor - GETSET_PROPERTY(bool, AlwaysShowTabs, true); - GETSET_PROPERTY(bool, ShowTitleInTitlebar, true); - GETSET_PROPERTY(bool, ConfirmCloseAllTabs, true); - GETSET_PROPERTY(winrt::Windows::UI::Xaml::ElementTheme, Theme, winrt::Windows::UI::Xaml::ElementTheme::Default); - GETSET_PROPERTY(winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::Equal); - GETSET_PROPERTY(bool, ShowTabsInTitlebar, true); - GETSET_PROPERTY(std::wstring, WordDelimiters); // default value set in constructor - GETSET_PROPERTY(bool, CopyOnSelect, false); - GETSET_PROPERTY(winrt::Microsoft::Terminal::TerminalControl::CopyFormat, CopyFormatting, 0); - GETSET_PROPERTY(bool, WarnAboutLargePaste, true); - GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true); - GETSET_PROPERTY(LaunchPosition, InitialPosition); - GETSET_PROPERTY(winrt::TerminalApp::LaunchMode, LaunchMode, winrt::TerminalApp::LaunchMode::DefaultMode); - GETSET_PROPERTY(bool, SnapToGridOnResize, true); - GETSET_PROPERTY(bool, ForceFullRepaintRendering, false); - GETSET_PROPERTY(bool, SoftwareRendering, false); - GETSET_PROPERTY(bool, ForceVTInput, false); - GETSET_PROPERTY(bool, DebugFeaturesEnabled); // default value set in constructor - GETSET_PROPERTY(bool, StartOnUserLogin, false); - GETSET_PROPERTY(bool, AlwaysOnTop, false); - GETSET_PROPERTY(bool, UseTabSwitcher, true); - -private: - std::optional _unparsedDefaultProfile; - GUID _defaultProfile; - - winrt::com_ptr _keybindings; - std::vector<::TerminalApp::SettingsLoadWarnings> _keybindingsWarnings; - - std::unordered_map _colorSchemes; - winrt::Windows::Foundation::Collections::IMap _commands; - - friend class TerminalAppLocalTests::SettingsTests; - friend class TerminalAppLocalTests::ColorSchemeTests; -}; + struct GlobalAppSettings : GlobalAppSettingsT + { + public: + GlobalAppSettings(); + + Windows::Foundation::Collections::IMapView GetColorSchemes() noexcept; + void AddColorScheme(const TerminalApp::ColorScheme& scheme); + + TerminalApp::AppKeyBindings GetKeybindings() const noexcept; + + static com_ptr FromJson(const Json::Value& json); + void LayerJson(const Json::Value& json); + + void ApplyToSettings(const TerminalApp::TerminalSettings& settings) const noexcept; + + std::vector<::TerminalApp::SettingsLoadWarnings> GetKeybindingsWarnings() const; + + Windows::Foundation::Collections::IMapView GetCommands() noexcept; + + // These are implemented manually to handle the string/GUID exchange + // by higher layers in the app. + void DefaultProfile(const guid& defaultProfile) noexcept; + guid DefaultProfile() const; + hstring UnparsedDefaultProfile() const; + + GETSET_PROPERTY(int32_t, InitialRows, DEFAULT_ROWS); + GETSET_PROPERTY(int32_t, InitialCols, DEFAULT_COLS); + GETSET_PROPERTY(bool, AlwaysShowTabs, true); + GETSET_PROPERTY(bool, ShowTitleInTitlebar, true); + GETSET_PROPERTY(bool, ConfirmCloseAllTabs, true); + GETSET_PROPERTY(winrt::Windows::UI::Xaml::ElementTheme, Theme, winrt::Windows::UI::Xaml::ElementTheme::Default); + GETSET_PROPERTY(winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::Equal); + GETSET_PROPERTY(bool, ShowTabsInTitlebar, true); + GETSET_PROPERTY(hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS); + GETSET_PROPERTY(bool, CopyOnSelect, false); + GETSET_PROPERTY(winrt::Microsoft::Terminal::TerminalControl::CopyFormat, CopyFormatting, 0); + GETSET_PROPERTY(bool, WarnAboutLargePaste, true); + GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true); + GETSET_PROPERTY(winrt::TerminalApp::LaunchPosition, InitialPosition, nullptr, nullptr); + GETSET_PROPERTY(winrt::TerminalApp::LaunchMode, LaunchMode, winrt::TerminalApp::LaunchMode::DefaultMode); + GETSET_PROPERTY(bool, SnapToGridOnResize, true); + GETSET_PROPERTY(bool, ForceFullRepaintRendering, false); + GETSET_PROPERTY(bool, SoftwareRendering, false); + GETSET_PROPERTY(bool, ForceVTInput, false); + GETSET_PROPERTY(bool, DebugFeaturesEnabled); // default value set in constructor + GETSET_PROPERTY(bool, StartOnUserLogin, false); + GETSET_PROPERTY(bool, AlwaysOnTop, false); + GETSET_PROPERTY(bool, UseTabSwitcher, true); + + private: + hstring _unparsedDefaultProfile; + guid _defaultProfile; + + com_ptr _keybindings; + std::vector<::TerminalApp::SettingsLoadWarnings> _keybindingsWarnings; + + Windows::Foundation::Collections::IMap _colorSchemes; + Windows::Foundation::Collections::IMap _commands; + + friend class TerminalAppLocalTests::SettingsTests; + friend class TerminalAppLocalTests::ColorSchemeTests; + }; +} diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.idl b/src/cascadia/TerminalApp/GlobalAppSettings.idl new file mode 100644 index 00000000000..6b0de0440ab --- /dev/null +++ b/src/cascadia/TerminalApp/GlobalAppSettings.idl @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "AppLogic.idl"; +import "ColorScheme.idl"; +import "AppKeybindings.idl"; +import "Command.idl"; +import "TerminalSettings.idl"; + +namespace TerminalApp +{ + // MIDL 3 allows for structs to hold nullable types + // Though IReference is a WinRT object, MIDL 3 + // handles all of the ownership logic for us. + // Docs: https://docs.microsoft.com/en-us/uwp/midl-3/intro#types + struct LaunchPosition + { + Windows.Foundation.IReference X; + Windows.Foundation.IReference Y; + }; + + [default_interface] runtimeclass GlobalAppSettings { + Guid DefaultProfile; + String UnparsedDefaultProfile(); + + Int32 InitialRows; + Int32 InitialCols; + Boolean AlwaysShowTabs; + Boolean ShowTitleInTitlebar; + Boolean ConfirmCloseAllTabs; + Windows.UI.Xaml.ElementTheme Theme; + Microsoft.UI.Xaml.Controls.TabViewWidthMode TabWidthMode; + Boolean ShowTabsInTitlebar; + String WordDelimiters; + Boolean CopyOnSelect; + Microsoft.Terminal.TerminalControl.CopyFormat CopyFormatting; + Boolean WarnAboutLargePaste; + Boolean WarnAboutMultiLinePaste; + LaunchPosition InitialPosition; + LaunchMode LaunchMode; + Boolean SnapToGridOnResize; + Boolean ForceFullRepaintRendering; + Boolean SoftwareRendering; + Boolean ForceVTInput; + Boolean DebugFeaturesEnabled; + Boolean StartOnUserLogin; + Boolean AlwaysOnTop; + Boolean UseTabSwitcher; + + Windows.Foundation.Collections.IMapView GetColorSchemes(); + void AddColorScheme(ColorScheme scheme); + + AppKeyBindings GetKeybindings(); + + Windows.Foundation.Collections.IMapView GetCommands(); + + void ApplyToSettings(TerminalSettings settings); + } +} 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 a49ae624af3..c2788591894 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -324,9 +324,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 681a3d28364..39d4d761d83 100644 --- a/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.cpp +++ b/src/cascadia/TerminalApp/PowershellCoreProfileGenerator.cpp @@ -137,6 +137,7 @@ namespace } using namespace ::TerminalApp; +using namespace winrt::TerminalApp; // Function Description: // - Finds all powershell instances with the traditional layout under a directory. @@ -287,7 +288,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() { @@ -300,20 +301,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)); } @@ -323,8 +324,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 220afd2067a..935513338ae 100644 --- a/src/cascadia/TerminalApp/Profile.cpp +++ b/src/cascadia/TerminalApp/Profile.cpp @@ -12,10 +12,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" }; @@ -56,77 +60,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: @@ -136,108 +76,96 @@ 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 Collections::IMapView& schemes) const { - TerminalSettings terminalSettings{}; + auto terminalSettings = winrt::make(); // 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()); - if (found != schemes.end()) + if (const auto found{ schemes.TryLookup(_ColorSchemeName) }) { - found->second.ApplyScheme(terminalSettings); + found.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; @@ -259,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; } @@ -282,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; } @@ -301,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; } @@ -329,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 { @@ -342,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; } @@ -374,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: @@ -540,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; } @@ -555,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: @@ -656,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, @@ -691,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: @@ -713,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(const 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(const winrt::guid& conType) noexcept { - _retroTerminalEffect = value; + _ConnectionType = conType; } diff --git a/src/cascadia/TerminalApp/Profile.h b/src/cascadia/TerminalApp/Profile.h index 2ab88f0c884..8286043c725 100644 --- a/src/cascadia/TerminalApp/Profile.h +++ b/src/cascadia/TerminalApp/Profile.h @@ -14,8 +14,13 @@ Author(s): --*/ #pragma once -#include "ColorScheme.g.h" -#include "SettingsTypes.h" + +#include "Profile.g.h" +#include "TerminalSettings.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 Windows::Foundation::Collections::IMapView& 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(const winrt::guid& guid) noexcept; + + bool HasConnectionType() const noexcept; + winrt::guid ConnectionType() const noexcept; + void ConnectionType(const 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..0fc1fa0bb6a 100644 --- a/src/cascadia/TerminalApp/SettingsTypes.h +++ b/src/cascadia/TerminalApp/SettingsTypes.h @@ -11,21 +11,8 @@ Module Name: #pragma once -namespace TerminalApp +namespace winrt::TerminalApp { - enum class CloseOnExitMode - { - Never = 0, - Graceful, - Always - }; - - struct LaunchPosition - { - std::optional x; - std::optional y; - }; - enum class ExpandCommandType : uint32_t { None = 0, 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..f4a0ee3c25e 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -107,8 +107,12 @@ ColorScheme.idl - - + + GlobalAppSettings.idl + + + Profile.idl + @@ -186,8 +190,12 @@ ColorScheme.idl - - + + GlobalAppSettings.idl + + + Profile.idl + @@ -276,6 +284,8 @@ + + diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters index 3056b71130d..347c2e138cd 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters @@ -151,6 +151,12 @@ settings + + settings + + + settings + diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index e3afffd1913..f9ac37f3efe 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -487,13 +487,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()); @@ -503,7 +502,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()); @@ -742,10 +741,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 }); @@ -781,20 +780,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 @@ -809,8 +809,8 @@ namespace winrt::TerminalApp::implementation winrt::guid()); } - else if (profile->HasConnectionType() && - profile->GetConnectionType() == TelnetConnectionType) + else if (hasConnectionType && + connectionType == TelnetConnectionType) { connection = TerminalConnection::TelnetConnection(settings.Commandline()); } @@ -982,10 +982,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 { @@ -2020,7 +2020,7 @@ namespace winrt::TerminalApp::implementation auto profiles = _settings->GetProfiles(); for (auto& profile : profiles) { - const GUID profileGuid = profile.GetGuid(); + const auto profileGuid = profile.Guid(); try { @@ -2090,17 +2090,17 @@ namespace winrt::TerminalApp::implementation // Return Value: // - IMap TerminalPage::_ExpandCommands(IMapView commandsToExpand, - gsl::span profiles, - const std::unordered_map& schemes) + gsl::span profiles, + IMapView schemes) { std::vector<::TerminalApp::SettingsLoadWarnings> warnings; std::vector sortedSchemes; - sortedSchemes.reserve(schemes.size()); + sortedSchemes.reserve(schemes.Size()); for (const auto& nameAndScheme : schemes) { - sortedSchemes.push_back(nameAndScheme.second); + sortedSchemes.push_back(nameAndScheme.Value()); } std::sort(sortedSchemes.begin(), sortedSchemes.end(), @@ -2129,7 +2129,7 @@ namespace winrt::TerminalApp::implementation // - void TerminalPage::_UpdateCommandsForPalette() { - IMap copyOfCommands = _ExpandCommands(_settings->GlobalSettings().GetCommands().GetView(), + IMap copyOfCommands = _ExpandCommands(_settings->GlobalSettings().GetCommands(), _settings->GetProfiles(), _settings->GlobalSettings().GetColorSchemes()); diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 1fe524f5f84..26b5d2ab088 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -139,8 +139,8 @@ namespace winrt::TerminalApp::implementation void _UpdateTabWidthMode(); void _UpdateCommandsForPalette(); static winrt::Windows::Foundation::Collections::IMap _ExpandCommands(Windows::Foundation::Collections::IMapView commandsToExpand, - gsl::span profiles, - const std::unordered_map& schemes); + gsl::span profiles, + Windows::Foundation::Collections::IMapView schemes); void _DuplicateTabViewItem(); void _RemoveTabViewItem(const Microsoft::UI::Xaml::Controls::TabViewItem& tabViewItem); diff --git a/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h index 06054eab69a..47e2c681025 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()) { @@ -184,7 +184,7 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode) }; }; -JSON_ENUM_MAPPER(::TerminalApp::ExpandCommandType) +JSON_ENUM_MAPPER(winrt::TerminalApp::ExpandCommandType) { JSON_MAPPINGS(2) = { pair_type{ "profiles", ValueType::Profiles }, @@ -226,11 +226,11 @@ JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::TerminalControl::CopyFormat) // (abc, 100): if a value is not valid, we treat it as default // (100, 100, 100): we only read the first two values, this is equivalent to (100, 100) template<> -struct ::TerminalApp::JsonUtils::ConversionTrait<::TerminalApp::LaunchPosition> +struct ::TerminalApp::JsonUtils::ConversionTrait<::winrt::TerminalApp::LaunchPosition> { - ::TerminalApp::LaunchPosition FromJson(const Json::Value& json) + ::winrt::TerminalApp::LaunchPosition FromJson(const Json::Value& json) { - ::TerminalApp::LaunchPosition ret; + ::winrt::TerminalApp::LaunchPosition ret; std::string initialPosition{ json.asString() }; static constexpr char singleCharDelim = ','; std::stringstream tokenStream(initialPosition); @@ -244,15 +244,15 @@ struct ::TerminalApp::JsonUtils::ConversionTrait<::TerminalApp::LaunchPosition> { try { - int32_t position = std::stoi(token); + int64_t position = std::stol(token); if (initialPosIndex == 0) { - ret.x.emplace(position); + ret.X = position; } if (initialPosIndex == 1) { - ret.y.emplace(position); + ret.Y = position; } } catch (...) diff --git a/src/cascadia/TerminalApp/WslDistroGenerator.cpp b/src/cascadia/TerminalApp/WslDistroGenerator.cpp index 55d8d460b34..db67cb25717 100644 --- a/src/cascadia/TerminalApp/WslDistroGenerator.cpp +++ b/src/cascadia/TerminalApp/WslDistroGenerator.cpp @@ -17,6 +17,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 @@ -35,9 +36,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; @@ -126,10 +127,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/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 0ae788956a5..d7896b6aa32 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -241,9 +241,9 @@ void AppHost::_HandleCreateWindow(const HWND hwnd, RECT proposedRect, winrt::Ter launchMode = _logic.GetLaunchMode(); // Acquire the actual initial position - winrt::Windows::Foundation::Point initialPosition = _logic.GetLaunchInitialPositions(proposedRect.left, proposedRect.top); - proposedRect.left = gsl::narrow_cast(initialPosition.X); - proposedRect.top = gsl::narrow_cast(initialPosition.Y); + auto initialPos = _logic.GetInitialPosition(proposedRect.left, proposedRect.top); + proposedRect.left = static_cast(initialPos.X); + proposedRect.top = static_cast(initialPos.Y); long adjustedHeight = 0; long adjustedWidth = 0; 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"