Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cascadia/TerminalApp/AppCommandlineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ void AppCommandlineArgs::_addNewTerminalArgs(AppCommandlineArgs::NewTerminalSubc
_inheritEnvironment,
RS_A(L"CmdInheritEnvDesc"));

subcommand.keepOpenOption = subcommand.subcommand->add_flag("-o,--keepOpen", _keepOpenOption, RS_A(L"CmdKeepOpenDesc"));

// Using positionals_at_end allows us to support "wt new-tab -d wsl -d Ubuntu"
// without CLI11 thinking that we've specified -d twice.
// There's an alternate construction where we make all subcommands "prefix commands",
Expand Down Expand Up @@ -675,6 +677,11 @@ NewTerminalArgs AppCommandlineArgs::_getNewTerminalArgs(AppCommandlineArgs::NewT
}
args.ReloadEnvironmentVariables(!inheritEnv);

if (*subcommand.keepOpenOption)
{
args.KeepOpen(_keepOpenOption);
}

return args;
}

Expand Down Expand Up @@ -720,6 +727,7 @@ void AppCommandlineArgs::_resetStateToDefault()
_commandline.clear();
_suppressApplicationTitle = false;
_appendCommandLineOption = false;
_keepOpenOption = false;

_splitVertical = false;
_splitHorizontal = false;
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/AppCommandlineArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class TerminalApp::AppCommandlineArgs final
CLI::Option* colorSchemeOption;
CLI::Option* appendCommandLineOption;
CLI::Option* inheritEnvOption;
CLI::Option* keepOpenOption;
};

struct NewPaneSubcommand : public NewTerminalSubcommand
Expand Down Expand Up @@ -110,6 +111,8 @@ class TerminalApp::AppCommandlineArgs final
std::vector<std::string> _commandline;
bool _appendCommandLineOption{ false };

bool _keepOpenOption{ false };

bool _splitVertical{ false };
bool _splitHorizontal{ false };
bool _splitDuplicate{ false };
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,7 @@
<data name="RestartConnectionToolTip" xml:space="preserve">
<value>Restart the active pane connection</value>
</data>
<data name="CmdKeepOpenDesc" xml:space="preserve">
<value>If set, the window/tab/pane will stay open after the command has exited. (It is he same as setting the profile termination behavior to never.)</value>
</data>
</root>
7 changes: 7 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
ACTION_ARG(winrt::hstring, ColorScheme);
ACTION_ARG(Windows::Foundation::IReference<bool>, Elevate, nullptr);
ACTION_ARG(Windows::Foundation::IReference<bool>, ReloadEnvironmentVariables, nullptr);
ACTION_ARG(bool, KeepOpen, false)
ACTION_ARG(uint64_t, ContentId);

static constexpr std::string_view CommandlineKey{ "commandline" };
Expand All @@ -327,6 +328,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static constexpr std::string_view ColorSchemeKey{ "colorScheme" };
static constexpr std::string_view ElevateKey{ "elevate" };
static constexpr std::string_view ReloadEnvironmentVariablesKey{ "reloadEnvironmentVariables" };
static constexpr std::string_view KeepOpenKey{ "keepOpen" };
static constexpr std::string_view ContentKey{ "__content" };

public:
Expand All @@ -349,6 +351,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
otherAsUs->_ColorScheme == _ColorScheme &&
otherAsUs->_Elevate == _Elevate &&
otherAsUs->_ReloadEnvironmentVariables == _ReloadEnvironmentVariables &&
otherAsUs->_KeepOpen == _KeepOpen &&
otherAsUs->_ContentId == _ContentId;
}
return false;
Expand All @@ -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);
JsonUtils::GetValueForKey(json, ContentKey, args->_ContentId);
return *args;
}
Expand All @@ -388,6 +392,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::SetValueForKey(json, ColorSchemeKey, args->_ColorScheme);
JsonUtils::SetValueForKey(json, ElevateKey, args->_Elevate);
JsonUtils::SetValueForKey(json, ReloadEnvironmentVariablesKey, args->_ReloadEnvironmentVariables);
JsonUtils::SetValueForKey(json, KeepOpenKey, args->_KeepOpen);
JsonUtils::SetValueForKey(json, ContentKey, args->_ContentId);
return json;
}
Expand All @@ -404,6 +409,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
copy->_ColorScheme = _ColorScheme;
copy->_Elevate = _Elevate;
copy->_ReloadEnvironmentVariables = _ReloadEnvironmentVariables;
copy->_KeepOpen = _KeepOpen;
copy->_ContentId = _ContentId;
return *copy;
}
Expand All @@ -425,6 +431,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
h.write(ColorScheme());
h.write(Elevate());
h.write(ReloadEnvironmentVariables());
h.write(KeepOpen());
h.write(ContentId());
}
};
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace Microsoft.Terminal.Settings.Model
Windows.Foundation.IReference<Windows.UI.Color> TabColor;
String Profile; // Either a GUID or a profile's name if the GUID isn't a match
Boolean AppendCommandLine;
Boolean KeepOpen;

// We use IReference<> to treat some args as nullable where null means
// "use the inherited value". See ProfileIndex,
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalSettingsModel/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
defaultSettings.ReloadEnvironmentVariables(newTerminalArgs.ReloadEnvironmentVariables().Value());
}

if (newTerminalArgs.KeepOpen())
{
defaultSettings.CloseOnExit(CloseOnExitMode::Never);
}
}

return settingsPair;
Expand Down Expand Up @@ -341,6 +346,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_RepositionCursorWithMouse = profile.RepositionCursorWithMouse();

_ReloadEnvironmentVariables = profile.ReloadEnvironmentVariables();

_CloseOnExit = profile.CloseOnExit();
}

// Method Description:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/TerminalSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

INHERITABLE_SETTING(Model::TerminalSettings, bool, ReloadEnvironmentVariables, true);

INHERITABLE_SETTING(Model::TerminalSettings, CloseOnExitMode, CloseOnExit, CloseOnExitMode::Automatic);

private:
std::optional<std::array<Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE>> _ColorTable;
std::span<Microsoft::Terminal::Core::Color> _getColorTableImpl();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/TerminalSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ namespace Microsoft.Terminal.Settings.Model

Boolean Elevate;
Boolean ReloadEnvironmentVariables;
CloseOnExitMode CloseOnExit;
};
}