From dc4026d184df2489276d46de02a222131cd4d333 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 5 Apr 2024 12:29:27 -0700 Subject: [PATCH] Add support for restoring non-terminal panes, and opening them with `splitPane`, `newTab` (#16914) This changes `NewTabArgs`, `SplitPaneArgs`, and `NewWindowArgs` to accept a `INewContentArgs`, rather than just a `NewTerminalArgs`. This allows a couple things: * Users can open arbitrary types of panes with the existing `splitPane`, `newWindow` actions, just by passing `"type": "scartchpad"` (for example). This is a lot more flexible than re-defining different `"openScratchpad"`, `"openTasksPane"`, etc, etc actions for every kind of pane. * This allows us to use the existing machinery of session restore to also restore non-terminal panes. The `type` property was added to `newTab`, `splitPane`, `newWindow`. When omitted, we still just treat the json as a blob of NewTerminalArgs. There's not actually any other kinds of `INewContentArgs` in this PR (other than the placeholder `GenericContentArgs`). In [`dev/migrie/fhl/md-pane`](https://github.com/microsoft/terminal/compare/dev/migrie/f/tasks-pane...dev/migrie/fhl/md-pane), I have a type of pane that would LOVE to add some args here. So that's forward-thinking. There's really just two stealth types of pane for now: `settings`, and `scratchpad`. Those I DON'T have as constants or anything in this PR. They probably should be? Though, I suspect around the time of the tasks & MD panes, I'll come up with whatever structure I actually want them to take. ### future considerations here * In the future, this should allow extensions to say "I know how to host `foo` content", for 3p content. * The `wt` CLI args were not yet updated to also accept `--type` yet. There's no reason we couldn't easily do that. * I considered adding `ICanHasCommandline` to allow arbitrary content to generate a `wt` commandline-serializable string. Punted on that for now. ## other PRs * #16170 * #16171 * #16172 * #16895 * #16914 <-- you are here Closes #17014 --- .../CommandlineTest.cpp | 593 ++++++++++-------- .../LocalTests_TerminalApp/SettingsTests.cpp | 508 ++++++++------- .../TerminalApp/AppActionHandlers.cpp | 91 ++- src/cascadia/TerminalApp/IPaneContent.idl | 2 +- src/cascadia/TerminalApp/Pane.cpp | 2 +- src/cascadia/TerminalApp/Pane.h | 2 +- .../TerminalApp/ScratchpadContent.cpp | 4 +- src/cascadia/TerminalApp/ScratchpadContent.h | 2 +- .../TerminalApp/SettingsPaneContent.cpp | 7 +- .../TerminalApp/SettingsPaneContent.h | 2 +- src/cascadia/TerminalApp/TabManagement.cpp | 37 +- src/cascadia/TerminalApp/TerminalPage.cpp | 111 +++- src/cascadia/TerminalApp/TerminalPage.h | 10 +- .../TerminalApp/TerminalPaneContent.cpp | 2 +- .../TerminalApp/TerminalPaneContent.h | 2 +- src/cascadia/TerminalApp/TerminalTab.cpp | 23 - src/cascadia/TerminalApp/TerminalWindow.cpp | 2 +- .../TerminalSettingsModel/ActionArgs.cpp | 13 +- .../TerminalSettingsModel/ActionArgs.h | 202 ++++-- .../TerminalSettingsModel/ActionArgs.idl | 35 +- .../UnitTests_SettingsModel/CommandTests.cpp | 27 +- .../DeserializationTests.cpp | 72 ++- .../KeyBindingsTests.cpp | 49 +- .../TerminalSettingsTests.cpp | 248 ++++---- .../WindowsTerminal/WindowEmperor.cpp | 4 +- 25 files changed, 1182 insertions(+), 868 deletions(-) diff --git a/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp b/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp index 3d0837d0a64..f3c0efa463d 100644 --- a/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp +++ b/src/cascadia/LocalTests_TerminalApp/CommandlineTest.cpp @@ -381,14 +381,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - auto myCommand = myArgs.TerminalArgs().Commandline(); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + auto myCommand = terminalArgs.Commandline(); VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg \"", myCommand); } { @@ -397,14 +398,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - auto myCommand = myArgs.TerminalArgs().Commandline(); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + auto myCommand = terminalArgs.Commandline(); VERIFY_ARE_EQUAL(L"\" with spaces\"", myCommand); } } @@ -421,14 +423,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - auto myCommand = myArgs.TerminalArgs().Commandline(); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + auto myCommand = terminalArgs.Commandline(); VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg ; with spaces\"", myCommand); } } @@ -468,14 +471,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -489,15 +493,16 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"cmd", myArgs.TerminalArgs().Profile()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"cmd", terminalArgs.Profile()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -511,15 +516,16 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"c:\\Foo", myArgs.TerminalArgs().StartingDirectory()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_FALSE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"c:\\Foo", terminalArgs.StartingDirectory()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -533,15 +539,16 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"powershell.exe", myArgs.TerminalArgs().Commandline()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"powershell.exe", terminalArgs.Commandline()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -555,16 +562,17 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - auto myCommand = myArgs.TerminalArgs().Commandline(); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + auto myCommand = terminalArgs.Commandline(); VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg with spaces\"", myCommand); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -578,16 +586,17 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - auto myCommand = myArgs.TerminalArgs().Commandline(); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + auto myCommand = terminalArgs.Commandline(); VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg with spaces\" another-arg \"more spaces in this one\"", myCommand); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -601,15 +610,16 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"Windows PowerShell", myArgs.TerminalArgs().Profile()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"Windows PowerShell", terminalArgs.Profile()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -623,14 +633,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"wsl -d Alpine", terminalArgs.Commandline()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -644,16 +655,17 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"wsl -d Alpine", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"1", terminalArgs.Profile()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -669,15 +681,16 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_ARE_EQUAL(til::color(myArgs.TerminalArgs().TabColor().Value()), expectedColor); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NOT_NULL(terminalArgs.TabColor()); + VERIFY_ARE_EQUAL(til::color(terminalArgs.TabColor().Value()), expectedColor); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -693,15 +706,16 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().ColorScheme().empty()); - VERIFY_ARE_EQUAL(expectedScheme, myArgs.TerminalArgs().ColorScheme()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_IS_FALSE(terminalArgs.ColorScheme().empty()); + VERIFY_ARE_EQUAL(expectedScheme, terminalArgs.ColorScheme()); } } @@ -732,7 +746,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(SplitType::Manual, myArgs.SplitMode()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { AppCommandlineArgs appArgs{}; @@ -752,7 +767,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Down, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(SplitType::Manual, myArgs.SplitMode()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { AppCommandlineArgs appArgs{}; @@ -774,7 +790,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Right, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(SplitType::Manual, myArgs.SplitMode()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { AppCommandlineArgs appArgs{}; @@ -795,7 +812,8 @@ namespace TerminalAppLocalTests auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitType::Duplicate, myArgs.SplitMode()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { AppCommandlineArgs appArgs{}; @@ -815,16 +833,17 @@ namespace TerminalAppLocalTests auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"wsl -d Alpine", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"1", terminalArgs.Profile()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -844,16 +863,17 @@ namespace TerminalAppLocalTests auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Down, myArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"wsl -d Alpine", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"1", terminalArgs.Profile()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } { AppCommandlineArgs appArgs{}; @@ -873,16 +893,17 @@ namespace TerminalAppLocalTests auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine -H", myArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"wsl -d Alpine -H", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"1", terminalArgs.Profile()); + VERIFY_IS_TRUE(terminalArgs.ColorScheme().empty()); } } @@ -923,13 +944,14 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } { AppCommandlineArgs appArgs{}; @@ -943,14 +965,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"cmd", myArgs.TerminalArgs().Profile()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"cmd", terminalArgs.Profile()); } { AppCommandlineArgs appArgs{}; @@ -964,14 +987,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"c:\\Foo", myArgs.TerminalArgs().StartingDirectory()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_FALSE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"c:\\Foo", terminalArgs.StartingDirectory()); } { AppCommandlineArgs appArgs{}; @@ -985,14 +1009,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"powershell.exe", myArgs.TerminalArgs().Commandline()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"powershell.exe", terminalArgs.Commandline()); } { AppCommandlineArgs appArgs{}; @@ -1006,14 +1031,15 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg with spaces\"", myArgs.TerminalArgs().Commandline()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg with spaces\"", terminalArgs.Commandline()); } } @@ -1469,32 +1495,38 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(2u, appArgs._startupActions.size()); - auto actionAndArgs = appArgs._startupActions.at(0); - VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); - VERIFY_IS_NOT_NULL(actionAndArgs.Args()); - auto myArgs = actionAndArgs.Args().try_as(); - VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - - actionAndArgs = appArgs._startupActions.at(1); - VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); - VERIFY_IS_NOT_NULL(actionAndArgs.Args()); - myArgs = actionAndArgs.Args().try_as(); - VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"slpit-pane", myArgs.TerminalArgs().Commandline()); + { + auto actionAndArgs = appArgs._startupActions.at(0); + VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); + VERIFY_IS_NOT_NULL(actionAndArgs.Args()); + auto myArgs = actionAndArgs.Args().try_as(); + VERIFY_IS_NOT_NULL(myArgs); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + } + + { + auto actionAndArgs = appArgs._startupActions.at(1); + VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); + VERIFY_IS_NOT_NULL(actionAndArgs.Args()); + auto myArgs = actionAndArgs.Args().try_as(); + VERIFY_IS_NOT_NULL(myArgs); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"slpit-pane", terminalArgs.Commandline()); + } } { @@ -1511,8 +1543,9 @@ namespace TerminalAppLocalTests auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_ARE_EQUAL(L"slpit-pane -H", myArgs.TerminalArgs().Commandline()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_ARE_EQUAL(L"slpit-pane -H", terminalArgs.Commandline()); } } @@ -1530,9 +1563,10 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"C:\\", myArgs.TerminalArgs().StartingDirectory()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_ARE_EQUAL(L"wsl -d Alpine", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"C:\\", terminalArgs.StartingDirectory()); } { // two parsing terminators, new-tab command AppCommandlineArgs appArgs{}; @@ -1546,9 +1580,10 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine -- sleep 10", myArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"C:\\", myArgs.TerminalArgs().StartingDirectory()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_ARE_EQUAL(L"wsl -d Alpine -- sleep 10", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"C:\\", terminalArgs.StartingDirectory()); } { // two parsing terminators, *no* command AppCommandlineArgs appArgs{}; @@ -1562,9 +1597,10 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_ARE_EQUAL(L"wsl -d Alpine -- sleep 10", myArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"C:\\", myArgs.TerminalArgs().StartingDirectory()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_ARE_EQUAL(L"wsl -d Alpine -- sleep 10", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"C:\\", terminalArgs.StartingDirectory()); } } @@ -1578,13 +1614,14 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } void CommandlineTest::TestMultipleCommandExecuteCommandlineAction() @@ -1598,13 +1635,14 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } { auto actionAndArgs = actions.at(1); @@ -1612,13 +1650,14 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor()); - VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_NULL(terminalArgs.TabColor()); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } } @@ -1739,13 +1778,14 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ProfileIndex() == nullptr); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"cmd", myArgs.TerminalArgs().Profile()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.ProfileIndex() == nullptr); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"cmd", terminalArgs.Profile()); } { Log::Comment(NoThrowString().Format(L"Pass a launch mode and command line")); @@ -1763,13 +1803,14 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(actionAndArgs.Args()); auto myArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(myArgs); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); - VERIFY_IS_FALSE(myArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(myArgs.TerminalArgs().ProfileIndex() == nullptr); - VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"powershell.exe", myArgs.TerminalArgs().Commandline()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.ProfileIndex() == nullptr); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"powershell.exe", terminalArgs.Commandline()); } } @@ -1800,7 +1841,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(0.5f, myArgs.SplitSize()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { AppCommandlineArgs appArgs{}; @@ -1820,7 +1862,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(0.3f, myArgs.SplitSize()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { AppCommandlineArgs appArgs{}; @@ -1841,7 +1884,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(0.3f, myArgs.SplitSize()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { auto actionAndArgs = appArgs._startupActions.at(2); @@ -1851,7 +1895,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(0.5f, myArgs.SplitSize()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } } { @@ -1873,7 +1918,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(0.3f, myArgs.SplitSize()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } { auto actionAndArgs = appArgs._startupActions.at(2); @@ -1883,7 +1929,8 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(myArgs); VERIFY_ARE_EQUAL(SplitDirection::Automatic, myArgs.SplitDirection()); VERIFY_ARE_EQUAL(0.7f, myArgs.SplitSize()); - VERIFY_IS_NOT_NULL(myArgs.TerminalArgs()); + auto terminalArgs{ myArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); } } } diff --git a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp index 8116e9e4574..ead353fc900 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -176,12 +176,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"${profile.name}", terminalArgs.Profile()); } const auto& expandedCommands{ settings.GlobalSettings().ActionMap().ExpandedCommands() }; @@ -201,12 +202,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile0", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile()); } { @@ -220,12 +222,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); } { @@ -239,12 +242,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); } } @@ -302,12 +306,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"${profile.name}", terminalArgs.Profile()); } const auto& expandedCommands{ settings.GlobalSettings().ActionMap().ExpandedCommands() }; @@ -328,12 +333,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile0", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile()); } { @@ -348,12 +354,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); } { @@ -368,12 +375,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); } } @@ -433,12 +441,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"${profile.name}", terminalArgs.Profile()); } const auto& expandedCommands{ settings.GlobalSettings().ActionMap().ExpandedCommands() }; @@ -459,12 +468,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile0", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile()); } { @@ -479,12 +489,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1\"", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1\"", terminalArgs.Profile()); } { @@ -499,12 +510,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); } } @@ -692,12 +704,13 @@ namespace TerminalAppLocalTests const auto& realArgs = childActionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"ssh me@first.com", realArgs.TerminalArgs().Commandline()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"ssh me@first.com", terminalArgs.Commandline()); VERIFY_IS_FALSE(child.HasNestedCommands()); } @@ -712,12 +725,13 @@ namespace TerminalAppLocalTests const auto& realArgs = childActionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"ssh me@second.com", realArgs.TerminalArgs().Commandline()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"ssh me@second.com", terminalArgs.Commandline()); VERIFY_IS_FALSE(child.HasNestedCommands()); } @@ -818,12 +832,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(name, realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(name, terminalArgs.Profile()); VERIFY_IS_FALSE(childCommand.HasNestedCommands()); } @@ -839,12 +854,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Down, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(name, realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(name, terminalArgs.Profile()); VERIFY_IS_FALSE(childCommand.HasNestedCommands()); } @@ -860,12 +876,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(name, realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(name, terminalArgs.Profile()); VERIFY_IS_FALSE(childCommand.HasNestedCommands()); } @@ -951,12 +968,13 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(name, realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(name, terminalArgs.Profile()); VERIFY_IS_FALSE(command.HasNestedCommands()); } @@ -1069,12 +1087,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(name, realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(name, terminalArgs.Profile()); VERIFY_IS_FALSE(childCommand.HasNestedCommands()); } @@ -1090,12 +1109,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Down, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(name, realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(name, terminalArgs.Profile()); VERIFY_IS_FALSE(childCommand.HasNestedCommands()); } @@ -1111,12 +1131,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(name, realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(name, terminalArgs.Profile()); VERIFY_IS_FALSE(childCommand.HasNestedCommands()); } @@ -1245,12 +1266,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"${scheme.name}", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"${scheme.name}", terminalArgs.Profile()); } const auto& expandedCommands{ settings.GlobalSettings().ActionMap().ExpandedCommands() }; @@ -1274,12 +1296,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"Campbell", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"Campbell", terminalArgs.Profile()); } { @@ -1294,12 +1317,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"Campbell PowerShell", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"Campbell PowerShell", terminalArgs.Profile()); } { @@ -1314,12 +1338,13 @@ namespace TerminalAppLocalTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Automatic, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"Vintage", realArgs.TerminalArgs().Profile()); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"Vintage", terminalArgs.Profile()); } } @@ -1385,15 +1410,16 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile0", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NULL(realArgs.TerminalArgs().Elevate()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile()); + VERIFY_IS_NULL(terminalArgs.Elevate()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(false, termSettings.Elevate()); @@ -1407,15 +1433,16 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NULL(realArgs.TerminalArgs().Elevate()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); + VERIFY_IS_NULL(terminalArgs.Elevate()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(true, termSettings.Elevate()); @@ -1429,15 +1456,16 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NULL(realArgs.TerminalArgs().Elevate()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); + VERIFY_IS_NULL(terminalArgs.Elevate()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(false, termSettings.Elevate()); @@ -1452,16 +1480,17 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile0", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().Elevate()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Elevate().Value()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile()); + VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); + VERIFY_IS_FALSE(terminalArgs.Elevate().Value()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(false, termSettings.Elevate()); @@ -1475,16 +1504,17 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().Elevate()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Elevate().Value()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); + VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); + VERIFY_IS_FALSE(terminalArgs.Elevate().Value()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(false, termSettings.Elevate()); @@ -1498,16 +1528,17 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().Elevate()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Elevate().Value()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); + VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); + VERIFY_IS_FALSE(terminalArgs.Elevate().Value()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(false, termSettings.Elevate()); @@ -1522,16 +1553,17 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile0", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().Elevate()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Elevate().Value()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile0", terminalArgs.Profile()); + VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); + VERIFY_IS_TRUE(terminalArgs.Elevate().Value()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(true, termSettings.Elevate()); @@ -1544,16 +1576,17 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().Elevate()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Elevate().Value()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); + VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); + VERIFY_IS_TRUE(terminalArgs.Elevate().Value()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(true, termSettings.Elevate()); @@ -1567,16 +1600,17 @@ namespace TerminalAppLocalTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().Elevate()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Elevate().Value()); - - const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, realArgs.TerminalArgs(), nullptr); + auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); + VERIFY_IS_NOT_NULL(terminalArgs.Elevate()); + VERIFY_IS_TRUE(terminalArgs.Elevate().Value()); + + const auto termSettingsResult = TerminalSettings::CreateWithNewTerminalArgs(settings, terminalArgs, nullptr); const auto termSettings = termSettingsResult.DefaultSettings(); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); VERIFY_ARE_EQUAL(true, termSettings.Elevate()); diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 22a0582dfda..2fd6680574f 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -238,6 +238,32 @@ namespace winrt::TerminalApp::implementation } } + // * Helper to try and get a ProfileIndex out of a NewTerminalArgs out of a + // NewContentArgs. For the new tab and split pane action, we want to _not_ + // handle the event if an invalid profile index was passed. + // + // Return value: + // * True if the args are NewTerminalArgs, and the profile index was out of bounds. + // * False otherwise. + static bool _shouldBailForInvalidProfileIndex(const CascadiaSettings& settings, const INewContentArgs& args) + { + if (!args) + { + return false; + } + if (const auto& terminalArgs{ args.try_as() }) + { + if (const auto index = terminalArgs.ProfileIndex()) + { + if (gsl::narrow(index.Value()) >= settings.ActiveProfiles().Size()) + { + return true; + } + } + } + return false; + } + void TerminalPage::_HandleSplitPane(const IInspectable& sender, const ActionEventArgs& args) { @@ -247,16 +273,10 @@ namespace winrt::TerminalApp::implementation } else if (const auto& realArgs = args.ActionArgs().try_as()) { - if (const auto& newTerminalArgs{ realArgs.TerminalArgs() }) + if (_shouldBailForInvalidProfileIndex(_settings, realArgs.ContentArgs())) { - if (const auto index = realArgs.TerminalArgs().ProfileIndex()) - { - if (gsl::narrow(index.Value()) >= _settings.ActiveProfiles().Size()) - { - args.Handled(false); - return; - } - } + args.Handled(false); + return; } const auto& duplicateFromTab{ realArgs.SplitMode() == SplitType::Duplicate ? _GetFocusedTab() : nullptr }; @@ -267,7 +287,7 @@ namespace winrt::TerminalApp::implementation realArgs.SplitDirection(), // This is safe, we're already filtering so the value is (0, 1) ::base::saturated_cast(realArgs.SplitSize()), - _MakePane(realArgs.TerminalArgs(), duplicateFromTab)); + _MakePane(realArgs.ContentArgs(), duplicateFromTab)); args.Handled(true); } } @@ -445,19 +465,13 @@ namespace winrt::TerminalApp::implementation } else if (const auto& realArgs = args.ActionArgs().try_as()) { - if (const auto& newTerminalArgs{ realArgs.TerminalArgs() }) + if (_shouldBailForInvalidProfileIndex(_settings, realArgs.ContentArgs())) { - if (const auto index = newTerminalArgs.ProfileIndex()) - { - if (gsl::narrow(index.Value()) >= _settings.ActiveProfiles().Size()) - { - args.Handled(false); - return; - } - } + args.Handled(false); + return; } - LOG_IF_FAILED(_OpenNewTab(realArgs.TerminalArgs())); + LOG_IF_FAILED(_OpenNewTab(realArgs.ContentArgs())); args.Handled(true); } } @@ -869,8 +883,23 @@ namespace winrt::TerminalApp::implementation // - // Important: Don't take the param by reference, since we'll be doing work // on another thread. - fire_and_forget TerminalPage::_OpenNewWindow(const NewTerminalArgs newTerminalArgs) + fire_and_forget TerminalPage::_OpenNewWindow(const INewContentArgs newContentArgs) { + auto terminalArgs{ newContentArgs.try_as() }; + + // Do nothing for non-terminal panes. + // + // Theoretically, we could define a `IHasCommandline` interface, and + // stick `ToCommandline` on that interface, for any kind of pane that + // wants to be convertable to a wt commandline. + // + // Another idea we're thinking about is just `wt do {literal json for an + // action}`, which might be less leaky + if (terminalArgs == nullptr) + { + co_return; + } + // Hop to the BG thread co_await winrt::resume_background(); @@ -883,8 +912,7 @@ namespace winrt::TerminalApp::implementation // `-w -1` will ensure a new window is created. winrt::hstring cmdline{ fmt::format(L"-w -1 new-tab {}", - newTerminalArgs ? newTerminalArgs.ToCommandline().c_str() : - L"") + terminalArgs.ToCommandline().c_str()) }; // Build the args to ShellExecuteEx. We need to use ShellExecuteEx so we @@ -909,29 +937,32 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_HandleNewWindow(const IInspectable& /*sender*/, const ActionEventArgs& actionArgs) { - NewTerminalArgs newTerminalArgs{ nullptr }; + INewContentArgs newContentArgs{ nullptr }; // If the caller provided NewTerminalArgs, then try to use those if (actionArgs) { if (const auto& realArgs = actionArgs.ActionArgs().try_as()) { - newTerminalArgs = realArgs.TerminalArgs(); + newContentArgs = realArgs.ContentArgs(); } } // Otherwise, if no NewTerminalArgs were provided, then just use a // default-constructed one. The default-constructed one implies that // nothing about the launch should be modified (just use the default // profile). - if (!newTerminalArgs) + if (!newContentArgs) { - newTerminalArgs = NewTerminalArgs(); + newContentArgs = NewTerminalArgs{}; } - const auto profile{ _settings.GetProfileForArgs(newTerminalArgs) }; + if (const auto& terminalArgs{ newContentArgs.try_as() }) + { + const auto profile{ _settings.GetProfileForArgs(terminalArgs) }; + terminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid())); + } // Manually fill in the evaluated profile. - newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid())); - _OpenNewWindow(newTerminalArgs); + _OpenNewWindow(newContentArgs); actionArgs.Handled(true); } diff --git a/src/cascadia/TerminalApp/IPaneContent.idl b/src/cascadia/TerminalApp/IPaneContent.idl index fa258fdbd26..f4c6ce13957 100644 --- a/src/cascadia/TerminalApp/IPaneContent.idl +++ b/src/cascadia/TerminalApp/IPaneContent.idl @@ -31,7 +31,7 @@ namespace TerminalApp Windows.Foundation.IReference TabColor { get; }; Windows.UI.Xaml.Media.Brush BackgroundBrush { get; }; - Microsoft.Terminal.Settings.Model.NewTerminalArgs GetNewTerminalArgs(BuildStartupKind kind); + Microsoft.Terminal.Settings.Model.INewContentArgs GetNewTerminalArgs(BuildStartupKind kind); void Focus(Windows.UI.Xaml.FocusState reason); diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index de3c7f76c46..7d11f4edc63 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -100,7 +100,7 @@ Pane::Pane(std::shared_ptr first, // Extract the terminal settings from the current (leaf) pane's control // to be used to create an equivalent control -NewTerminalArgs Pane::GetTerminalArgsForPane(BuildStartupKind kind) const +INewContentArgs Pane::GetTerminalArgsForPane(BuildStartupKind kind) const { // Leaves are the only things that have controls assert(_IsLeaf()); diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index 37ed79b4739..67daee1694f 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -106,7 +106,7 @@ class Pane : public std::enable_shared_from_this uint32_t panesCreated; }; BuildStartupState BuildStartupActions(uint32_t currentId, uint32_t nextId, winrt::TerminalApp::BuildStartupKind kind); - winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetTerminalArgsForPane(winrt::TerminalApp::BuildStartupKind kind) const; + winrt::Microsoft::Terminal::Settings::Model::INewContentArgs GetTerminalArgsForPane(winrt::TerminalApp::BuildStartupKind kind) const; void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings); bool ResizePane(const winrt::Microsoft::Terminal::Settings::Model::ResizeDirection& direction); diff --git a/src/cascadia/TerminalApp/ScratchpadContent.cpp b/src/cascadia/TerminalApp/ScratchpadContent.cpp index 0f39daa1bee..16346c9b038 100644 --- a/src/cascadia/TerminalApp/ScratchpadContent.cpp +++ b/src/cascadia/TerminalApp/ScratchpadContent.cpp @@ -48,9 +48,9 @@ namespace winrt::TerminalApp::implementation CloseRequested.raise(*this, nullptr); } - NewTerminalArgs ScratchpadContent::GetNewTerminalArgs(const BuildStartupKind /* kind */) const + INewContentArgs ScratchpadContent::GetNewTerminalArgs(const BuildStartupKind /* kind */) const { - return nullptr; + return BaseContentArgs(L"scratchpad"); } winrt::hstring ScratchpadContent::Icon() const diff --git a/src/cascadia/TerminalApp/ScratchpadContent.h b/src/cascadia/TerminalApp/ScratchpadContent.h index cd01414e677..407773fedd1 100644 --- a/src/cascadia/TerminalApp/ScratchpadContent.h +++ b/src/cascadia/TerminalApp/ScratchpadContent.h @@ -19,7 +19,7 @@ namespace winrt::TerminalApp::implementation void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic); void Close(); - winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(BuildStartupKind kind) const; + winrt::Microsoft::Terminal::Settings::Model::INewContentArgs GetNewTerminalArgs(BuildStartupKind kind) const; winrt::hstring Title() { return L"Scratchpad"; } uint64_t TaskbarState() { return 0; } diff --git a/src/cascadia/TerminalApp/SettingsPaneContent.cpp b/src/cascadia/TerminalApp/SettingsPaneContent.cpp index 3e89c38296b..7e48ae9f6be 100644 --- a/src/cascadia/TerminalApp/SettingsPaneContent.cpp +++ b/src/cascadia/TerminalApp/SettingsPaneContent.cpp @@ -50,12 +50,9 @@ namespace winrt::TerminalApp::implementation CloseRequested.raise(*this, nullptr); } - NewTerminalArgs SettingsPaneContent::GetNewTerminalArgs(const BuildStartupKind /*kind*/) const + INewContentArgs SettingsPaneContent::GetNewTerminalArgs(const BuildStartupKind /*kind*/) const { - // For now, we're doing a terrible thing in TerminalTab itself to - // generate an OpenSettings action manually, without asking for the pane - // structure. - return nullptr; + return BaseContentArgs(L"settings"); } winrt::hstring SettingsPaneContent::Icon() const diff --git a/src/cascadia/TerminalApp/SettingsPaneContent.h b/src/cascadia/TerminalApp/SettingsPaneContent.h index ee3322bf06b..6169df84beb 100644 --- a/src/cascadia/TerminalApp/SettingsPaneContent.h +++ b/src/cascadia/TerminalApp/SettingsPaneContent.h @@ -20,7 +20,7 @@ namespace winrt::TerminalApp::implementation winrt::Windows::Foundation::Size MinimumSize(); void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic); void Close(); - winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(const BuildStartupKind kind) const; + winrt::Microsoft::Terminal::Settings::Model::INewContentArgs GetNewTerminalArgs(const BuildStartupKind kind) const; winrt::hstring Title() { return RS_(L"SettingsTab"); } uint64_t TaskbarState() { return 0; } diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 3f833bb8ba9..f2039d0043e 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -62,30 +62,33 @@ namespace winrt::TerminalApp::implementation // - existingConnection: An optional connection that is already established to a PTY // for this tab to host instead of creating one. // If not defined, the tab will create the connection. - HRESULT TerminalPage::_OpenNewTab(const NewTerminalArgs& newTerminalArgs) + HRESULT TerminalPage::_OpenNewTab(const INewContentArgs& newContentArgs) try { - const auto profile{ _settings.GetProfileForArgs(newTerminalArgs) }; - // GH#11114: GetProfileForArgs can return null if the index is higher - // than the number of available profiles. - if (!profile) + if (const auto& newTerminalArgs{ newContentArgs.try_as() }) { - return S_FALSE; - } - const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings) }; + const auto profile{ _settings.GetProfileForArgs(newTerminalArgs) }; + // GH#11114: GetProfileForArgs can return null if the index is higher + // than the number of available profiles. + if (!profile) + { + return S_FALSE; + } + const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings) }; - // Try to handle auto-elevation - if (_maybeElevate(newTerminalArgs, settings, profile)) - { - return S_OK; + // Try to handle auto-elevation + if (_maybeElevate(newTerminalArgs, settings, profile)) + { + return S_OK; + } + // We can't go in the other direction (elevated->unelevated) + // unfortunately. This seems to be due to Centennial quirks. It works + // unpackaged, but not packaged. } - // We can't go in the other direction (elevated->unelevated) - // unfortunately. This seems to be due to Centennial quirks. It works - // unpackaged, but not packaged. - // + // This call to _MakePane won't return nullptr, we already checked that // case above with the _maybeElevate call. - _CreateNewTabFromPane(_MakePane(newTerminalArgs, nullptr)); + _CreateNewTabFromPane(_MakePane(newContentArgs, nullptr)); return S_OK; } CATCH_RETURN(); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index ec7c066d5ff..2f1b66b561a 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -21,6 +21,7 @@ #include "ColorHelper.h" #include "DebugTapConnection.h" #include "SettingsPaneContent.h" +#include "ScratchpadContent.h" #include "TabRowControl.h" #include "Utils.h" @@ -315,6 +316,7 @@ namespace winrt::TerminalApp::implementation // Check that there's at least one action that's not just an elevated newTab action. for (const auto& action : _startupActions) { + // Only new terminal panes will be requesting elevation. NewTerminalArgs newTerminalArgs{ nullptr }; if (action.Action() == ShortcutAction::NewTab) @@ -322,7 +324,7 @@ namespace winrt::TerminalApp::implementation const auto& args{ action.Args().try_as() }; if (args) { - newTerminalArgs = args.TerminalArgs(); + newTerminalArgs = args.ContentArgs().try_as(); } else { @@ -335,7 +337,7 @@ namespace winrt::TerminalApp::implementation const auto& args{ action.Args().try_as() }; if (args) { - newTerminalArgs = args.TerminalArgs(); + newTerminalArgs = args.ContentArgs().try_as(); } else { @@ -3095,9 +3097,9 @@ namespace winrt::TerminalApp::implementation // - If the newTerminalArgs required us to open the pane as a new elevated // connection, then we'll return nullptr. Otherwise, we'll return a new // Pane for this connection. - std::shared_ptr TerminalPage::_MakePane(const NewTerminalArgs& newTerminalArgs, - const winrt::TerminalApp::TabBase& sourceTab, - TerminalConnection::ITerminalConnection existingConnection) + std::shared_ptr TerminalPage::_MakeTerminalPane(const NewTerminalArgs& newTerminalArgs, + const winrt::TerminalApp::TabBase& sourceTab, + TerminalConnection::ITerminalConnection existingConnection) { // First things first - Check for making a pane from content ID. if (newTerminalArgs && @@ -3165,6 +3167,7 @@ namespace winrt::TerminalApp::implementation const auto control = _CreateNewControlAndContent(controlSettings, connection); auto paneContent{ winrt::make(profile, _terminalSettingsCache, control) }; + auto resultPane = std::make_shared(paneContent); if (debugConnection) // this will only be set if global debugging is on and tap is active @@ -3189,6 +3192,41 @@ namespace winrt::TerminalApp::implementation return resultPane; } + std::shared_ptr TerminalPage::_MakePane(const INewContentArgs& contentArgs, + const winrt::TerminalApp::TabBase& sourceTab, + TerminalConnection::ITerminalConnection existingConnection) + + { + if (const auto& newTerminalArgs{ contentArgs.try_as() }) + { + // Terminals are of course special, and have to deal with debug taps, duplicating the tab, etc. + return _MakeTerminalPane(newTerminalArgs, sourceTab, existingConnection); + } + + IPaneContent content{ nullptr }; + + const auto& paneType{ contentArgs.Type() }; + if (paneType == L"scratchpad") + { + const auto& scratchPane{ winrt::make_self() }; + + // This is maybe a little wacky - add our key event handler to the pane + // we made. So that we can get actions for keys that the content didn't + // handle. + scratchPane->GetRoot().KeyDown({ get_weak(), &TerminalPage::_KeyDownHandler }); + + content = *scratchPane; + } + else if (paneType == L"settings") + { + content = _makeSettingsContent(); + } + + assert(content); + + return std::make_shared(content); + } + void TerminalPage::_restartPaneConnection( const TerminalApp::TerminalPaneContent& paneContent, const winrt::Windows::Foundation::IInspectable&) @@ -3841,6 +3879,39 @@ namespace winrt::TerminalApp::implementation CATCH_RETURN() } + TerminalApp::IPaneContent TerminalPage::_makeSettingsContent() + { + if (auto app{ winrt::Windows::UI::Xaml::Application::Current().try_as() }) + { + if (auto appPrivate{ winrt::get_self(app) }) + { + // Lazily load the Settings UI components so that we don't do it on startup. + appPrivate->PrepareForSettingsUI(); + } + } + + // Create the SUI pane content + auto settingsContent{ winrt::make_self(_settings) }; + auto sui = settingsContent->SettingsUI(); + + if (_hostingHwnd) + { + sui.SetHostingWindow(reinterpret_cast(*_hostingHwnd)); + } + + // GH#8767 - let unhandled keys in the SUI try to run commands too. + sui.KeyDown({ get_weak(), &TerminalPage::_KeyDownHandler }); + + sui.OpenJson([weakThis{ get_weak() }](auto&& /*s*/, winrt::Microsoft::Terminal::Settings::Model::SettingsTarget e) { + if (auto page{ weakThis.get() }) + { + page->_LaunchSettings(e); + } + }); + + return *settingsContent; + } + // Method Description: // - Creates a settings UI tab and focuses it. If there's already a settings UI tab open, // just focus the existing one. @@ -3853,36 +3924,8 @@ namespace winrt::TerminalApp::implementation // If we're holding the settings tab's switch command, don't create a new one, switch to the existing one. if (!_settingsTab) { - if (auto app{ winrt::Windows::UI::Xaml::Application::Current().try_as() }) - { - if (auto appPrivate{ winrt::get_self(app) }) - { - // Lazily load the Settings UI components so that we don't do it on startup. - appPrivate->PrepareForSettingsUI(); - } - } - - // Create the SUI pane content - auto settingsContent{ winrt::make_self(_settings) }; - auto sui = settingsContent->SettingsUI(); - - if (_hostingHwnd) - { - sui.SetHostingWindow(reinterpret_cast(*_hostingHwnd)); - } - - // GH#8767 - let unhandled keys in the SUI try to run commands too. - sui.KeyDown({ this, &TerminalPage::_KeyDownHandler }); - - sui.OpenJson([weakThis{ get_weak() }](auto&& /*s*/, winrt::Microsoft::Terminal::Settings::Model::SettingsTarget e) { - if (auto page{ weakThis.get() }) - { - page->_LaunchSettings(e); - } - }); - // Create the tab - auto resultPane = std::make_shared(*settingsContent); + auto resultPane = std::make_shared(_makeSettingsContent()); _settingsTab = _CreateNewTabFromPane(resultPane); } else diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index eece631419b..1fd2acfaee6 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -292,7 +292,7 @@ namespace winrt::TerminalApp::implementation winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _CreateNewTabFlyoutProfile(const Microsoft::Terminal::Settings::Model::Profile profile, int profileIndex); void _OpenNewTabDropdown(); - HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs); + HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::INewContentArgs& newContentArgs); TerminalApp::TerminalTab _CreateNewTabFromPane(std::shared_ptr pane, uint32_t insertPosition = -1); std::wstring _evaluatePathForCwd(std::wstring_view path); @@ -301,7 +301,7 @@ namespace winrt::TerminalApp::implementation winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(const TerminalApp::TerminalPaneContent& paneContent); void _restartPaneConnection(const TerminalApp::TerminalPaneContent&, const winrt::Windows::Foundation::IInspectable&); - winrt::fire_and_forget _OpenNewWindow(const Microsoft::Terminal::Settings::Model::NewTerminalArgs newTerminalArgs); + winrt::fire_and_forget _OpenNewWindow(const Microsoft::Terminal::Settings::Model::INewContentArgs newContentArgs); void _OpenNewTerminalViaDropdown(const Microsoft::Terminal::Settings::Model::NewTerminalArgs newTerminalArgs); @@ -435,7 +435,11 @@ namespace winrt::TerminalApp::implementation winrt::Microsoft::Terminal::Control::TermControl _SetupControl(const winrt::Microsoft::Terminal::Control::TermControl& term); winrt::Microsoft::Terminal::Control::TermControl _AttachControlToContent(const uint64_t& contentGuid); - std::shared_ptr _MakePane(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs = nullptr, + TerminalApp::IPaneContent _makeSettingsContent(); + std::shared_ptr _MakeTerminalPane(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs = nullptr, + const winrt::TerminalApp::TabBase& sourceTab = nullptr, + winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr); + std::shared_ptr _MakePane(const Microsoft::Terminal::Settings::Model::INewContentArgs& newContentArgs = nullptr, const winrt::TerminalApp::TabBase& sourceTab = nullptr, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr); diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.cpp b/src/cascadia/TerminalApp/TerminalPaneContent.cpp index 406ab283510..652486e441a 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.cpp +++ b/src/cascadia/TerminalApp/TerminalPaneContent.cpp @@ -92,7 +92,7 @@ namespace winrt::TerminalApp::implementation return _control.TabColor(); } - NewTerminalArgs TerminalPaneContent::GetNewTerminalArgs(const BuildStartupKind kind) const + INewContentArgs TerminalPaneContent::GetNewTerminalArgs(const BuildStartupKind kind) const { NewTerminalArgs args{}; const auto& controlSettings = _control.Settings(); diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.h b/src/cascadia/TerminalApp/TerminalPaneContent.h index e308a5cfb00..2995e5f1872 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.h +++ b/src/cascadia/TerminalApp/TerminalPaneContent.h @@ -28,7 +28,7 @@ namespace winrt::TerminalApp::implementation void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic); void Close(); - winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(BuildStartupKind kind) const; + winrt::Microsoft::Terminal::Settings::Model::INewContentArgs GetNewTerminalArgs(BuildStartupKind kind) const; void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings); diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 639f855e88e..ceb3860f1ff 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -447,30 +447,7 @@ namespace winrt::TerminalApp::implementation // 1 for the child after the first split. auto state = _rootPane->BuildStartupActions(0, 1, kind); - // HORRIBLE - // - // Workaround till we know how we actually want to handle state - // restoring other kinds of panes. If this is a settings tab, just - // restore it as a settings tab. Don't bother recreating terminal args - // for every pane. - // - // In the future, we'll want to definitely get rid of - // Pane::GetTerminalArgsForPane, and somehow instead find a better way - // of re-creating the pane state. Probably through a combo of ResizePane - // actions and SetPaneOrientation actions. - if (const auto& settings{ _rootPane->GetContent().try_as() }) { - ActionAndArgs action; - action.Action(ShortcutAction::OpenSettings); - OpenSettingsArgs args{ SettingsTarget::SettingsUI }; - action.Args(args); - - state.args = std::vector{ std::move(action) }; - } - else - { - state = _rootPane->BuildStartupActions(0, 1, kind); - ActionAndArgs newTabAction{}; newTabAction.Action(ShortcutAction::NewTab); NewTabArgs newTabArgs{ state.firstPane->GetTerminalArgsForPane(kind) }; diff --git a/src/cascadia/TerminalApp/TerminalWindow.cpp b/src/cascadia/TerminalApp/TerminalWindow.cpp index 4a37b0a733e..bd246bb53de 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.cpp +++ b/src/cascadia/TerminalApp/TerminalWindow.cpp @@ -1238,7 +1238,7 @@ namespace winrt::TerminalApp::implementation // Create the equivalent NewTab action. const auto newAction = Settings::Model::ActionAndArgs{ Settings::Model::ShortcutAction::NewTab, Settings::Model::NewTabArgs(firstAction.Args() ? - firstAction.Args().try_as().TerminalArgs() : + firstAction.Args().try_as().ContentArgs() : nullptr) }; args.SetAt(0, newAction); } diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp index 598b77a4051..24f4e445953 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp @@ -6,6 +6,7 @@ #include "ActionArgs.h" #include "ActionEventArgs.g.cpp" +#include "BaseContentArgs.g.cpp" #include "NewTerminalArgs.g.cpp" #include "CopyTextArgs.g.cpp" #include "NewTabArgs.g.cpp" @@ -245,9 +246,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation winrt::hstring NewTabArgs::GenerateName() const { winrt::hstring newTerminalArgsStr; - if (TerminalArgs()) + if (ContentArgs()) { - newTerminalArgsStr = TerminalArgs().GenerateName(); + newTerminalArgsStr = ContentArgs().GenerateName(); } if (newTerminalArgsStr.empty()) @@ -465,9 +466,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation } winrt::hstring newTerminalArgsStr; - if (TerminalArgs()) + if (ContentArgs()) { - newTerminalArgsStr = TerminalArgs().GenerateName(); + newTerminalArgsStr = ContentArgs().GenerateName(); } if (SplitMode() != SplitType::Duplicate && !newTerminalArgsStr.empty()) @@ -769,9 +770,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation winrt::hstring NewWindowArgs::GenerateName() const { winrt::hstring newTerminalArgsStr; - if (TerminalArgs()) + if (ContentArgs()) { - newTerminalArgsStr = TerminalArgs().GenerateName(); + newTerminalArgsStr = ContentArgs().GenerateName(); } if (newTerminalArgsStr.empty()) diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.h b/src/cascadia/TerminalSettingsModel/ActionArgs.h index 4062cee426c..bf34a6af140 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.h +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.h @@ -6,6 +6,7 @@ // HEY YOU: When adding ActionArgs types, make sure to add the corresponding // *.g.cpp to ActionArgs.cpp! #include "ActionEventArgs.g.h" +#include "BaseContentArgs.g.h" #include "NewTerminalArgs.g.h" #include "CopyTextArgs.g.h" #include "NewTabArgs.g.h" @@ -71,7 +72,7 @@ public: \ _##name = value; \ } \ \ -private: \ +protected: \ std::optional _##name{ std::nullopt }; // Notes on defining ActionArgs and ActionEventArgs: @@ -295,6 +296,56 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation WINRT_PROPERTY(bool, Handled, false); }; + struct BaseContentArgs : public BaseContentArgsT + { + BaseContentArgs(winrt::hstring type) : + _Type{ type } {} + + BaseContentArgs() : + BaseContentArgs(L"") {} + + ACTION_ARG(winrt::hstring, Type, L""); + + static constexpr std::string_view TypeKey{ "type" }; + + public: + bool Equals(INewContentArgs other) const + { + return other.Type() == _Type; + } + size_t Hash() const + { + til::hasher h; + Hash(h); + return h.finalize(); + } + void Hash(til::hasher& h) const + { + h.write(Type()); + } + INewContentArgs Copy() const + { + auto copy{ winrt::make_self() }; + copy->_Type = _Type; + return *copy; + } + winrt::hstring GenerateName() const + { + return winrt::hstring{ L"type: " } + Type(); + } + static Json::Value ToJson(const Model::BaseContentArgs& val) + { + if (!val) + { + return {}; + } + auto args{ get_self(val) }; + Json::Value json{ Json::ValueType::objectValue }; + JsonUtils::SetValueForKey(json, TypeKey, args->_Type); + return json; + } + }; + // Although it may _seem_ like NewTerminalArgs can use ACTION_ARG_BODY, it // actually can't, because it isn't an `IActionArgs`, which breaks some // assumptions made in the macro. @@ -303,6 +354,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation NewTerminalArgs() = default; NewTerminalArgs(int32_t& profileIndex) : _ProfileIndex{ profileIndex } {}; + + ACTION_ARG(winrt::hstring, Type, L""); + ACTION_ARG(winrt::hstring, Commandline, L""); ACTION_ARG(winrt::hstring, StartingDirectory, L""); ACTION_ARG(winrt::hstring, TabTitle, L""); @@ -335,7 +389,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation hstring GenerateName() const; hstring ToCommandline() const; - bool Equals(const Model::NewTerminalArgs& other) + bool Equals(const Model::INewContentArgs& other) { auto otherAsUs = other.try_as(); if (otherAsUs) @@ -433,6 +487,45 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation h.write(ContentId()); } }; + + static std::tuple> ContentArgsFromJson(const Json::Value& json) + { + winrt::hstring type; + JsonUtils::GetValueForKey(json, "type", type); + if (type.empty()) + { + auto terminalArgs = winrt::Microsoft::Terminal::Settings::Model::implementation::NewTerminalArgs::FromJson(json); + // Don't let the user specify the __content property in their + // settings. That's an internal-use-only property. + if (terminalArgs.ContentId()) + { + return { terminalArgs, { SettingsLoadWarnings::InvalidUseOfContent } }; + } + return { terminalArgs, {} }; + } + + // For now, we don't support any other concrete types of content + // with args. Just return a placeholder type that only includes the type + return { *winrt::make_self(type), {} }; + } + static Json::Value ContentArgsToJson(const Model::INewContentArgs& contentArgs) + { + if (contentArgs == nullptr) + { + return {}; + } + // TerminalArgs don't have a type. + if (contentArgs.Type().empty()) + { + return winrt::Microsoft::Terminal::Settings::Model::implementation::NewTerminalArgs::ToJson(contentArgs.try_as()); + } + + // For now, we don't support any other concrete types of content + // with args. Just return a placeholder. + auto base{ winrt::make_self(contentArgs.Type()) }; + return BaseContentArgs::ToJson(*base); + } + } template<> @@ -463,6 +556,20 @@ struct til::hash_trait } } }; +template<> +struct til::hash_trait +{ + using M = winrt::Microsoft::Terminal::Settings::Model::INewContentArgs; + + void operator()(hasher& h, const M& value) const noexcept + { + if (value) + { + h.write(value.Type()); + h.write(value.Hash()); + } + } +}; namespace winrt::Microsoft::Terminal::Settings::Model::implementation { @@ -473,9 +580,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation struct NewTabArgs : public NewTabArgsT { NewTabArgs() = default; - NewTabArgs(const Model::NewTerminalArgs& terminalArgs) : - _TerminalArgs{ terminalArgs } {}; - WINRT_PROPERTY(Model::NewTerminalArgs, TerminalArgs, nullptr); + NewTabArgs(const Model::INewContentArgs& terminalArgs) : + _ContentArgs{ terminalArgs } {}; + WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, nullptr); public: hstring GenerateName() const; @@ -485,7 +592,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation auto otherAsUs = other.try_as(); if (otherAsUs) { - return otherAsUs->_TerminalArgs.Equals(_TerminalArgs); + return otherAsUs->_ContentArgs.Equals(_ContentArgs); } return false; }; @@ -493,15 +600,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { // LOAD BEARING: Not using make_self here _will_ break you in the future! auto args = winrt::make_self(); - args->_TerminalArgs = NewTerminalArgs::FromJson(json); - - // Don't let the user specify the __content property in their - // settings. That's an internal-use-only property. - if (args->_TerminalArgs.ContentId()) - { - return { *args, { SettingsLoadWarnings::InvalidUseOfContent } }; - } - return { *args, {} }; + auto [content, warnings] = ContentArgsFromJson(json); + args->_ContentArgs = content; + return { *args, warnings }; } static Json::Value ToJson(const IActionArgs& val) { @@ -510,18 +611,18 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return {}; } const auto args{ get_self(val) }; - return NewTerminalArgs::ToJson(args->_TerminalArgs); + return ContentArgsToJson(args->_ContentArgs); } IActionArgs Copy() const { auto copy{ winrt::make_self() }; - copy->_TerminalArgs = _TerminalArgs.Copy(); + copy->_ContentArgs = _ContentArgs.Copy(); return *copy; } size_t Hash() const { til::hasher h; - h.write(TerminalArgs()); + h.write(ContentArgs()); return h.finalize(); } }; @@ -529,22 +630,23 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation struct SplitPaneArgs : public SplitPaneArgsT { SplitPaneArgs() = default; - SplitPaneArgs(SplitType splitMode, SplitDirection direction, double size, const Model::NewTerminalArgs& terminalArgs) : + SplitPaneArgs(SplitType splitMode, SplitDirection direction, double size, const Model::INewContentArgs& terminalArgs) : _SplitMode{ splitMode }, _SplitDirection{ direction }, _SplitSize{ size }, - _TerminalArgs{ terminalArgs } {}; - SplitPaneArgs(SplitDirection direction, double size, const Model::NewTerminalArgs& terminalArgs) : + _ContentArgs{ terminalArgs } {}; + SplitPaneArgs(SplitDirection direction, double size, const Model::INewContentArgs& terminalArgs) : _SplitDirection{ direction }, _SplitSize{ size }, - _TerminalArgs{ terminalArgs } {}; - SplitPaneArgs(SplitDirection direction, const Model::NewTerminalArgs& terminalArgs) : + _ContentArgs{ terminalArgs } {}; + SplitPaneArgs(SplitDirection direction, const Model::INewContentArgs& terminalArgs) : _SplitDirection{ direction }, - _TerminalArgs{ terminalArgs } {}; + _ContentArgs{ terminalArgs } {}; SplitPaneArgs(SplitType splitMode) : _SplitMode{ splitMode } {}; + ACTION_ARG(Model::SplitDirection, SplitDirection, SplitDirection::Automatic); - WINRT_PROPERTY(Model::NewTerminalArgs, TerminalArgs, nullptr); + WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, nullptr); ACTION_ARG(SplitType, SplitMode, SplitType::Manual); ACTION_ARG(double, SplitSize, .5); @@ -561,8 +663,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation if (otherAsUs) { return otherAsUs->_SplitDirection == _SplitDirection && - (otherAsUs->_TerminalArgs ? otherAsUs->_TerminalArgs.Equals(_TerminalArgs) : - otherAsUs->_TerminalArgs == _TerminalArgs) && + (otherAsUs->_ContentArgs ? otherAsUs->_ContentArgs.Equals(_ContentArgs) : + otherAsUs->_ContentArgs == _ContentArgs) && otherAsUs->_SplitSize == _SplitSize && otherAsUs->_SplitMode == _SplitMode; } @@ -572,7 +674,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { // LOAD BEARING: Not using make_self here _will_ break you in the future! auto args = winrt::make_self(); - args->_TerminalArgs = NewTerminalArgs::FromJson(json); JsonUtils::GetValueForKey(json, SplitKey, args->_SplitDirection); JsonUtils::GetValueForKey(json, SplitModeKey, args->_SplitMode); JsonUtils::GetValueForKey(json, SplitSizeKey, args->_SplitSize); @@ -581,14 +682,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return { nullptr, { SettingsLoadWarnings::InvalidSplitSize } }; } - // Don't let the user specify the __content property in their - // settings. That's an internal-use-only property. - if (args->_TerminalArgs.ContentId()) - { - return { *args, { SettingsLoadWarnings::InvalidUseOfContent } }; - } - - return { *args, {} }; + auto [content, warnings] = ContentArgsFromJson(json); + args->_ContentArgs = content; + return { *args, warnings }; } static Json::Value ToJson(const IActionArgs& val) { @@ -597,7 +693,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return {}; } const auto args{ get_self(val) }; - auto json{ NewTerminalArgs::ToJson(args->_TerminalArgs) }; + auto json{ ContentArgsToJson(args->_ContentArgs) }; JsonUtils::SetValueForKey(json, SplitKey, args->_SplitDirection); JsonUtils::SetValueForKey(json, SplitModeKey, args->_SplitMode); JsonUtils::SetValueForKey(json, SplitSizeKey, args->_SplitSize); @@ -607,7 +703,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { auto copy{ winrt::make_self() }; copy->_SplitDirection = _SplitDirection; - copy->_TerminalArgs = _TerminalArgs.Copy(); + copy->_ContentArgs = _ContentArgs.Copy(); copy->_SplitMode = _SplitMode; copy->_SplitSize = _SplitSize; return *copy; @@ -616,7 +712,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { til::hasher h; h.write(SplitDirection()); - h.write(TerminalArgs()); + h.write(ContentArgs()); h.write(SplitMode()); h.write(SplitSize()); return h.finalize(); @@ -626,9 +722,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation struct NewWindowArgs : public NewWindowArgsT { NewWindowArgs() = default; - NewWindowArgs(const Model::NewTerminalArgs& terminalArgs) : - _TerminalArgs{ terminalArgs } {}; - WINRT_PROPERTY(Model::NewTerminalArgs, TerminalArgs, nullptr); + NewWindowArgs(const Model::INewContentArgs& terminalArgs) : + _ContentArgs{ terminalArgs } {}; + WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, nullptr); public: hstring GenerateName() const; @@ -638,7 +734,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation auto otherAsUs = other.try_as(); if (otherAsUs) { - return otherAsUs->_TerminalArgs.Equals(_TerminalArgs); + return otherAsUs->_ContentArgs.Equals(_ContentArgs); } return false; }; @@ -646,16 +742,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { // LOAD BEARING: Not using make_self here _will_ break you in the future! auto args = winrt::make_self(); - args->_TerminalArgs = NewTerminalArgs::FromJson(json); - - // Don't let the user specify the __content property in their - // settings. That's an internal-use-only property. - if (args->_TerminalArgs.ContentId()) - { - return { *args, { SettingsLoadWarnings::InvalidUseOfContent } }; - } - - return { *args, {} }; + auto [content, warnings] = ContentArgsFromJson(json); + args->_ContentArgs = content; + return { *args, warnings }; } static Json::Value ToJson(const IActionArgs& val) { @@ -664,18 +753,18 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return {}; } const auto args{ get_self(val) }; - return NewTerminalArgs::ToJson(args->_TerminalArgs); + return ContentArgsToJson(args->_ContentArgs); } IActionArgs Copy() const { auto copy{ winrt::make_self() }; - copy->_TerminalArgs = _TerminalArgs.Copy(); + copy->_ContentArgs = _ContentArgs.Copy(); return *copy; } size_t Hash() const { til::hasher h; - h.write(TerminalArgs()); + h.write(ContentArgs()); return h.finalize(); } }; @@ -829,6 +918,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation { BASIC_FACTORY(ActionEventArgs); + BASIC_FACTORY(BaseContentArgs); BASIC_FACTORY(CopyTextArgs); BASIC_FACTORY(SwitchToTabArgs); BASIC_FACTORY(NewTerminalArgs); diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.idl b/src/cascadia/TerminalSettingsModel/ActionArgs.idl index f8e6f4eb9cd..05ed70069a9 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.idl +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.idl @@ -122,10 +122,22 @@ namespace Microsoft.Terminal.Settings.Model All = 0xffffffff, }; - [default_interface] runtimeclass NewTerminalArgs { + interface INewContentArgs { + String Type { get; }; + Boolean Equals(INewContentArgs other); + UInt64 Hash(); + INewContentArgs Copy(); + String GenerateName(); + }; + + runtimeclass BaseContentArgs : [default] INewContentArgs { + BaseContentArgs(); + BaseContentArgs(String type); + }; + + runtimeclass NewTerminalArgs : INewContentArgs { NewTerminalArgs(); NewTerminalArgs(Int32 profileIndex); - NewTerminalArgs Copy(); String Commandline; String StartingDirectory; @@ -153,10 +165,7 @@ namespace Microsoft.Terminal.Settings.Model UInt64 ContentId{ get; set; }; - Boolean Equals(NewTerminalArgs other); - String GenerateName(); String ToCommandline(); - UInt64 Hash(); }; [default_interface] runtimeclass ActionEventArgs : IActionEventArgs @@ -175,8 +184,8 @@ namespace Microsoft.Terminal.Settings.Model [default_interface] runtimeclass NewTabArgs : IActionArgs { - NewTabArgs(NewTerminalArgs terminalArgs); - NewTerminalArgs TerminalArgs { get; }; + NewTabArgs(INewContentArgs contentArgs); + INewContentArgs ContentArgs { get; }; }; [default_interface] runtimeclass MovePaneArgs : IActionArgs @@ -221,13 +230,13 @@ namespace Microsoft.Terminal.Settings.Model [default_interface] runtimeclass SplitPaneArgs : IActionArgs { - SplitPaneArgs(SplitType splitMode, SplitDirection split, Double size, NewTerminalArgs terminalArgs); - SplitPaneArgs(SplitDirection split, Double size, NewTerminalArgs terminalArgs); - SplitPaneArgs(SplitDirection split, NewTerminalArgs terminalArgs); + SplitPaneArgs(SplitType splitMode, SplitDirection split, Double size, INewContentArgs contentArgs); + SplitPaneArgs(SplitDirection split, Double size, INewContentArgs contentArgs); + SplitPaneArgs(SplitDirection split, INewContentArgs contentArgs); SplitPaneArgs(SplitType splitMode); SplitDirection SplitDirection { get; }; - NewTerminalArgs TerminalArgs { get; }; + INewContentArgs ContentArgs { get; }; SplitType SplitMode { get; }; Double SplitSize { get; }; }; @@ -347,8 +356,8 @@ namespace Microsoft.Terminal.Settings.Model [default_interface] runtimeclass NewWindowArgs : IActionArgs { - NewWindowArgs(NewTerminalArgs terminalArgs); - NewTerminalArgs TerminalArgs { get; }; + NewWindowArgs(INewContentArgs contentArgs); + INewContentArgs ContentArgs { get; }; }; [default_interface] runtimeclass PrevTabArgs : IActionArgs diff --git a/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp b/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp index 8db1141736f..b4940852c91 100644 --- a/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/CommandTests.cpp @@ -473,7 +473,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); VERIFY_ARE_EQUAL(L"", cmdline); @@ -486,7 +487,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewTab, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); VERIFY_ARE_EQUAL(L"--profile \"foo\"", cmdline); @@ -499,7 +501,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); VERIFY_ARE_EQUAL(L"--profile \"foo\"", cmdline); @@ -512,7 +515,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); VERIFY_ARE_EQUAL(L"-- \"bar.exe\"", cmdline); @@ -525,7 +529,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); Log::Comment(NoThrowString().Format( @@ -540,7 +545,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); Log::Comment(NoThrowString().Format( @@ -555,7 +561,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); Log::Comment(NoThrowString().Format( @@ -570,7 +577,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); Log::Comment(NoThrowString().Format( @@ -585,7 +593,8 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action()); const auto& realArgs = command.ActionAndArgs().Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); - const auto& terminalArgs = realArgs.TerminalArgs(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto& terminalArgs = realArgs.ContentArgs().try_as(); VERIFY_IS_NOT_NULL(terminalArgs); auto cmdline = terminalArgs.ToCommandline(); Log::Comment(NoThrowString().Format( diff --git a/src/cascadia/UnitTests_SettingsModel/DeserializationTests.cpp b/src/cascadia/UnitTests_SettingsModel/DeserializationTests.cpp index bd17076bc94..50462a72346 100644 --- a/src/cascadia/UnitTests_SettingsModel/DeserializationTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/DeserializationTests.cpp @@ -1390,11 +1390,13 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } Log::Comment(L"Note that we're skipping ctrl+B, since that doesn't have `keys` set."); @@ -1407,11 +1409,13 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } { const KeyChord kc{ true, false, false, false, static_cast('D'), 0 }; @@ -1421,11 +1425,13 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } { const KeyChord kc{ true, false, false, false, static_cast('E'), 0 }; @@ -1435,11 +1441,13 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Down, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } { const KeyChord kc{ true, false, false, false, static_cast('F'), 0 }; @@ -1449,11 +1457,13 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Down, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } Log::Comment(L"Now verify the commands"); @@ -1478,11 +1488,13 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); } { // This was renamed to null (aka removed from the name map) in F. So this does not exist. diff --git a/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp b/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp index c5f4be49045..afe22c8930c 100644 --- a/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp @@ -27,6 +27,7 @@ namespace SettingsModelUnitTests TEST_METHOD(ManyKeysSameAction); TEST_METHOD(LayerKeybindings); TEST_METHOD(HashDeduplication); + TEST_METHOD(HashContentArgs); TEST_METHOD(UnbindKeybindings); TEST_METHOD(LayerScancodeKeybindings); TEST_METHOD(TestExplicitUnbind); @@ -161,6 +162,32 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(1u, actionMap->_ActionMap.size()); } + void KeyBindingsTests::HashContentArgs() + { + Log::Comment(L"These are two actions with different content args. They should have different hashes for their terminal args."); + const auto actionMap = winrt::make_self(); + actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": { "action": "newTab", } , "keys": ["ctrl+c"] } ])"), OriginTag::None); + actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": { "action": "newTab", "index": 0 } , "keys": ["ctrl+shift+c"] } ])"), OriginTag::None); + VERIFY_ARE_EQUAL(2u, actionMap->_ActionMap.size()); + + KeyChord ctrlC{ VirtualKeyModifiers::Control, static_cast('C'), 0 }; + KeyChord ctrlShiftC{ VirtualKeyModifiers::Control | VirtualKeyModifiers::Shift, static_cast('C'), 0 }; + + auto hashFromKey = [&](auto& kc) { + auto actionAndArgs = ::TestUtils::GetActionAndArgs(*actionMap, kc); + VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); + const auto& realArgs = actionAndArgs.Args().as(); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + return terminalArgs.Hash(); + }; + + const auto hashOne = hashFromKey(ctrlC); + const auto hashTwo = hashFromKey(ctrlShiftC); + + VERIFY_ARE_NOT_EQUAL(hashOne, hashTwo); + } + void KeyBindingsTests::UnbindKeybindings() { const std::string bindings0String{ R"([ { "command": "copy", "keys": ["ctrl+c"] } ])" }; @@ -318,8 +345,10 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().as(); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_NULL(realArgs.TerminalArgs().ProfileIndex()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_NULL(terminalArgs.ProfileIndex()); } { Log::Comment(NoThrowString().Format( @@ -329,9 +358,11 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().as(); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().ProfileIndex()); - VERIFY_ARE_EQUAL(0, realArgs.TerminalArgs().ProfileIndex().Value()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_NOT_NULL(terminalArgs.ProfileIndex()); + VERIFY_ARE_EQUAL(0, terminalArgs.ProfileIndex().Value()); } { Log::Comment(NoThrowString().Format( @@ -342,9 +373,11 @@ namespace SettingsModelUnitTests VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action()); const auto& realArgs = actionAndArgs.Args().as(); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs().ProfileIndex()); - VERIFY_ARE_EQUAL(11, realArgs.TerminalArgs().ProfileIndex().Value()); + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_NOT_NULL(terminalArgs.ProfileIndex()); + VERIFY_ARE_EQUAL(11, terminalArgs.ProfileIndex().Value()); } { diff --git a/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp b/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp index f45fd1624f7..051d722f941 100644 --- a/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp @@ -320,14 +320,16 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); @@ -341,15 +343,17 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}", realArgs.TerminalArgs().Profile()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"{6239a42c-1111-49a3-80bd-e8fdd045185c}", terminalArgs.Profile()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); @@ -363,15 +367,17 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"pwsh.exe", termSettings.Commandline()); @@ -385,15 +391,17 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Right, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); @@ -407,15 +415,17 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Down, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"foo.exe", realArgs.TerminalArgs().Commandline()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"foo.exe", terminalArgs.Commandline()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); // This action specified a command but no profile; it gets reassigned to the base profile VERIFY_ARE_EQUAL(settings->ProfileDefaults(), profile); @@ -430,16 +440,18 @@ namespace SettingsModelUnitTests VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value VERIFY_ARE_EQUAL(SplitDirection::Down, realArgs.SplitDirection()); - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - VERIFY_ARE_EQUAL(L"foo.exe", realArgs.TerminalArgs().Commandline()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); + VERIFY_ARE_EQUAL(L"foo.exe", terminalArgs.Commandline()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline()); @@ -452,14 +464,16 @@ namespace SettingsModelUnitTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); @@ -472,15 +486,17 @@ namespace SettingsModelUnitTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"c:\\foo", realArgs.TerminalArgs().StartingDirectory()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_FALSE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"c:\\foo", terminalArgs.StartingDirectory()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); @@ -494,16 +510,18 @@ namespace SettingsModelUnitTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"c:\\foo", realArgs.TerminalArgs().StartingDirectory()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_FALSE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_TRUE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"c:\\foo", terminalArgs.StartingDirectory()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); @@ -517,15 +535,17 @@ namespace SettingsModelUnitTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"bar", realArgs.TerminalArgs().TabTitle()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_FALSE(terminalArgs.TabTitle().empty()); + VERIFY_IS_TRUE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"bar", terminalArgs.TabTitle()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid0, profile.Guid()); VERIFY_ARE_EQUAL(L"cmd.exe", termSettings.Commandline()); @@ -539,16 +559,18 @@ namespace SettingsModelUnitTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_TRUE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"bar", realArgs.TerminalArgs().TabTitle()); - VERIFY_ARE_EQUAL(L"profile2", realArgs.TerminalArgs().Profile()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_TRUE(terminalArgs.Commandline().empty()); + VERIFY_IS_TRUE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_FALSE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"bar", terminalArgs.TabTitle()); + VERIFY_ARE_EQUAL(L"profile2", terminalArgs.Profile()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(profile2Guid, profile.Guid()); VERIFY_ARE_EQUAL(L"wsl.exe", termSettings.Commandline()); @@ -562,18 +584,20 @@ namespace SettingsModelUnitTests const auto& realArgs = actionAndArgs.Args().try_as(); VERIFY_IS_NOT_NULL(realArgs); // Verify the args have the expected value - VERIFY_IS_NOT_NULL(realArgs.TerminalArgs()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Commandline().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().StartingDirectory().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().TabTitle().empty()); - VERIFY_IS_FALSE(realArgs.TerminalArgs().Profile().empty()); - VERIFY_ARE_EQUAL(L"foo.exe", realArgs.TerminalArgs().Commandline()); - VERIFY_ARE_EQUAL(L"c:\\foo", realArgs.TerminalArgs().StartingDirectory()); - VERIFY_ARE_EQUAL(L"bar", realArgs.TerminalArgs().TabTitle()); - VERIFY_ARE_EQUAL(L"profile1", realArgs.TerminalArgs().Profile()); - - const auto profile{ settings->GetProfileForArgs(realArgs.TerminalArgs()) }; - const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, realArgs.TerminalArgs(), nullptr) }; + VERIFY_IS_NOT_NULL(realArgs.ContentArgs()); + const auto terminalArgs{ realArgs.ContentArgs().try_as() }; + VERIFY_IS_NOT_NULL(terminalArgs); + VERIFY_IS_FALSE(terminalArgs.Commandline().empty()); + VERIFY_IS_FALSE(terminalArgs.StartingDirectory().empty()); + VERIFY_IS_FALSE(terminalArgs.TabTitle().empty()); + VERIFY_IS_FALSE(terminalArgs.Profile().empty()); + VERIFY_ARE_EQUAL(L"foo.exe", terminalArgs.Commandline()); + VERIFY_ARE_EQUAL(L"c:\\foo", terminalArgs.StartingDirectory()); + VERIFY_ARE_EQUAL(L"bar", terminalArgs.TabTitle()); + VERIFY_ARE_EQUAL(L"profile1", terminalArgs.Profile()); + + const auto profile{ settings->GetProfileForArgs(terminalArgs) }; + const auto settingsStruct{ TerminalSettings::CreateWithNewTerminalArgs(*settings, terminalArgs, nullptr) }; const auto termSettings = settingsStruct.DefaultSettings(); VERIFY_ARE_EQUAL(guid1, profile.Guid()); VERIFY_ARE_EQUAL(L"foo.exe", termSettings.Commandline()); diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index 0fc28a20433..a8f0961e420 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -504,11 +504,11 @@ void WindowEmperor::_finalizeSessionPersistence() const if (const auto tabArgs = args.try_as()) { - terminalArgs = tabArgs.TerminalArgs(); + terminalArgs = tabArgs.ContentArgs().try_as(); } else if (const auto paneArgs = args.try_as()) { - terminalArgs = paneArgs.TerminalArgs(); + terminalArgs = paneArgs.ContentArgs().try_as(); } if (terminalArgs)