New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CmdLineArgs] "--keepOpen" to keep the window/tab/pane open after the process/profile has exited. #16497
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
@@ -367,6 +370,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation | |||
JsonUtils::GetValueForKey(json, ColorSchemeKey, args->_ColorScheme); | |||
JsonUtils::GetValueForKey(json, ElevateKey, args->_Elevate); | |||
JsonUtils::GetValueForKey(json, ReloadEnvironmentVariablesKey, args->_ReloadEnvironmentVariables); | |||
JsonUtils::GetValueForKey(json, KeepOpenKey, args->_KeepOpen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct that this json code and the one in line 395 is used to read form/write to a WT arguments json file? Do I need to update a json schema? (I can't find one.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's pretty much it. The schema can be found at terminal/doc/cascadia /profiles.schema.json
@@ -576,6 +576,8 @@ void AppCommandlineArgs::_addNewTerminalArgs(AppCommandlineArgs::NewTerminalSubc | |||
_inheritEnvironment, | |||
RS_A(L"CmdInheritEnvDesc")); | |||
|
|||
subcommand.keepOpenOption = subcommand.subcommand->add_flag("-ko,--keepOpen", _keepOpenOption, RS_A(L"CmdKeepOpenDesc")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yea that's by design. The help text for wt
is different than the help text for wt new-tab
. Behind the scenes, we'll secretly treat a wt
without a subcommand as a new-tab
subcommand, but the automatically generated help text for CLI11 doesn't know how to handle that π
This comment was marked as outdated.
This comment was marked as outdated.
@zadjii-msft
|
@zadjii-msft , @DHowett |
My apologies! I think this one slipped through the cracks while I was off being distracted writing sudo. I can try and take a spin through the review - though, I might be a little more brief than usual until after Build (May 21-23) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly the rest of this looks like it should work
@@ -341,6 +346,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation | |||
_RepositionCursorWithMouse = profile.RepositionCursorWithMouse(); | |||
|
|||
_ReloadEnvironmentVariables = profile.ReloadEnvironmentVariables(); | |||
|
|||
_CloseOnExit = profile.CloseOnExit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems... weird. This should already be plumbed through to the TermControl
somewhere else...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. It's not actually used by the TermControl
. The pane itself handles that, in this blob of code:
terminal/src/cascadia/TerminalApp/TerminalPaneContent.cpp
Lines 240 to 256 in 9c16c5c
if (_profile) | |
{ | |
if (_isDefTermSession && _profile.CloseOnExit() == CloseOnExitMode::Automatic) | |
{ | |
// For 'automatic', we only care about the connection state if we were launched by Terminal | |
// Since we were launched via defterm, ignore the connection state (i.e. we treat the | |
// close on exit mode as 'always', see GH #13325 for discussion) | |
Close(); | |
} | |
const auto mode = _profile.CloseOnExit(); | |
if ((mode == CloseOnExitMode::Always) || | |
((mode == CloseOnExitMode::Graceful || mode == CloseOnExitMode::Automatic) && newConnectionState == ConnectionState::Closed)) | |
{ | |
Close(); | |
} | |
} |
Looks like that's specifically looking up the CloseOnExit value out of the profile, not the TerminalSettings
. I bet you could update that to use the value from the TerminalSettings too.
This code has an example in that file of getting settings from the cache:
if (const auto& settings{ _cache.TryLookup(_profile) }) |
That'll get you a TerminalSettingsCreateResult
, who's .DefaultSettings()
will have the value you're looking for
You'll probably want |
Summary of the Pull Request
Adding a parameter to wt.exe that stops WT from closing after the sub process has exited.
References and Relevant Issues
Detailed Description of the Pull Request / Additional comments
This PR add the command line argument
--keepOpen
(short:-o
) that stops WT from closing after the sub process has exited. This is done by overriding theProfile termination behavior
setting at runtime withNever
.The new parameter also supports to be written to/read from a command line arguments JSON file.
Validation Steps Performed
wt.exe --keepOpen ping.exe learn.microsoft.com
Exit 0
wt.exe --keepOpen cmd.exe /c echo "test"
Exit 0
wt.exe new-tab PowerShell --keepOpen -c Get-Service
wt.exe nt -p "Command Prompt" --keepOpen
Exit 0
wt.exe nt -p "PowerShell" --keepOpen
Exit 0
wt.exe nt -p "Windows PowerShell" --keepOpen
Exit 0
wt.exe -p "Command Prompt" ; split-pane -p "PowerShell" --keepOpen
Exit 0
wt.exe -p "Command Prompt" ; split-pane -p "PowerShell" -o
Exit 0
wt.exe --keepOpen -p "Command Prompt" ; split-pane -p "PowerShell"
Exit 0
wt.exe new-tab PowerShell --keepOpen --appendCommandLine -- Write-Host test
wt.exe new-tab PowerShell -o --appendCommandLine -- Write-Host test
PR Checklist
--closeOnExit
Β #16060