Skip to content

Commit

Permalink
HOLY SHIT I GOT THE COMANDLINE TO EXECUTE IN THE CURRENT WINDOW!!!!!!…
Browse files Browse the repository at this point in the history
…!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  • Loading branch information
zadjii-msft committed Dec 17, 2020
1 parent 27ace16 commit 9a41647
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/cascadia/Remoting/Monarch.cpp
Expand Up @@ -117,6 +117,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
{
auto sessionId = std::stoi({ args[2].data(), args[2].size() });
printf("Found a commandline intended for session %d\n", sessionId);

// TODO:MG
// HACK: do an args[2:] to slice off the `-w window` args.
array_view<const winrt::hstring> argsNoWindow{ args.begin() + 2, args.end() };
if (sessionId < 0)
{
printf("That certainly isn't a valid ID, they should make a new window.\n");
Expand All @@ -127,7 +131,13 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
printf("Session 0 is actually #%llu\n", _mostRecentPeasant);
if (auto mruPeasant = _getPeasant(_mostRecentPeasant))
{
auto eventArgs = winrt::make_self<implementation::CommandlineArgs>(args, cwd);
// TODO In the morning:
// Right now, this commandline includes the "-w window" param, and CLI11 is biting it when parsing that.
// Either:
// * hack yank it for the time being (args[2:])
// * actually have an AppCommandlineArgs do the parsing.

auto eventArgs = winrt::make_self<implementation::CommandlineArgs>(argsNoWindow, cwd);
mruPeasant.ExecuteCommandline(*eventArgs);
createNewWindow = false;
}
Expand All @@ -136,7 +146,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
{
if (auto otherPeasant = _getPeasant(sessionId))
{
auto eventArgs = winrt::make_self<implementation::CommandlineArgs>(args, cwd);
auto eventArgs = winrt::make_self<implementation::CommandlineArgs>(argsNoWindow, cwd);
otherPeasant.ExecuteCommandline(*eventArgs);
createNewWindow = false;
}
Expand All @@ -163,6 +173,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation

return createNewWindow;
}

void Monarch::ToggleWindowingBehavior()
{
switch (_windowingBehavior)
Expand Down
5 changes: 2 additions & 3 deletions src/cascadia/Remoting/WindowManager.cpp
Expand Up @@ -45,14 +45,13 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation

auto eventArgs = winrt::make_self<implementation::CommandlineArgs>(args, cwd);
_peasant.ExecuteCommandline(*eventArgs);
_shouldCreateWindow = false;
_shouldCreateWindow = true;
}
else
{
// printf("The Monarch instructed us to not create a new window. We'll be exiting now.\n");
_shouldCreateWindow = false;
}

_shouldCreateWindow = true;
}

bool WindowManager::ShouldCreateWindow()
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/AppActionHandlers.cpp
Expand Up @@ -453,7 +453,7 @@ namespace winrt::TerminalApp::implementation
if (_startupActions.Size() != 0)
{
actionArgs.Handled(true);
_ProcessStartupActions(actions, false);
ProcessStartupActions(actions, false);
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Expand Up @@ -1111,6 +1111,19 @@ namespace winrt::TerminalApp::implementation
return result;
}

int32_t AppLogic::ExecuteCommandline(array_view<const winrt::hstring> args)
{
::TerminalApp::AppCommandlineArgs appArgs;
auto result = appArgs.ParseArgs(args);
if (result == 0)
{
auto actions = winrt::single_threaded_vector<ActionAndArgs>(std::move(appArgs.GetStartupActions()));
_root->ProcessStartupActions(actions, false);
}

return result; // TODO:MG does a return value make sense
}

// Method Description:
// - If there were any errors parsing the commandline that was used to
// initialize the terminal, this will return a string containing that
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Expand Up @@ -29,6 +29,7 @@ namespace winrt::TerminalApp::implementation
[[nodiscard]] Microsoft::Terminal::Settings::Model::CascadiaSettings GetSettings() const noexcept;

int32_t SetStartupCommandline(array_view<const winrt::hstring> actions);
int32_t ExecuteCommandline(array_view<const winrt::hstring> actions);
winrt::hstring ParseCommandlineMessage();
bool ShouldExitEarly();

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Expand Up @@ -29,6 +29,7 @@ namespace TerminalApp
Boolean IsElevated();

Int32 SetStartupCommandline(String[] commands);
Int32 ExecuteCommandline(String[] commands);
String ParseCommandlineMessage { get; };
Boolean ShouldExitEarly { get; };

Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Expand Up @@ -331,7 +331,7 @@ namespace winrt::TerminalApp::implementation
}
else
{
_ProcessStartupActions(_startupActions, true);
ProcessStartupActions(_startupActions, true);
}
}
}
Expand All @@ -347,8 +347,8 @@ namespace winrt::TerminalApp::implementation
// should fire an Initialized event.
// Return Value:
// - <none>
winrt::fire_and_forget TerminalPage::_ProcessStartupActions(Windows::Foundation::Collections::IVector<ActionAndArgs> actions,
const bool initial)
winrt::fire_and_forget TerminalPage::ProcessStartupActions(Windows::Foundation::Collections::IVector<ActionAndArgs> actions,
const bool initial)
{
// If there are no actions left, do nothing.
if (actions.Size() == 0)
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Expand Up @@ -81,6 +81,8 @@ namespace winrt::TerminalApp::implementation
void ShowKeyboardServiceWarning();
winrt::hstring KeyboardServiceDisabledText();

winrt::fire_and_forget ProcessStartupActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> actions, const bool initial);

// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
Expand Down Expand Up @@ -137,7 +139,6 @@ namespace winrt::TerminalApp::implementation
StartupState _startupState{ StartupState::NotInitialized };

Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> _startupActions;
winrt::fire_and_forget _ProcessStartupActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::ActionAndArgs> actions, const bool initial);

void _ShowAboutDialog();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowCloseWarningDialog();
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Expand Up @@ -59,6 +59,10 @@ AppHost::AppHost() noexcept :
{
return;
}
if (auto peasant{ _windowManager.CurrentWindow() })
{
peasant.ExecuteCommandlineRequested({ this, &AppHost::_DispatchCommandline });
}
}

// If there were commandline args to our process, try and process them here.
Expand Down Expand Up @@ -542,3 +546,9 @@ bool AppHost::HasWindow()
// // returns true if we should create a new window
// return true;
// }

void AppHost::_DispatchCommandline(winrt::Windows::Foundation::IInspectable sender,
winrt::Microsoft::Terminal::Remoting::CommandlineArgs args)
{
_logic.ExecuteCommandline(args.Args());
}
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Expand Up @@ -49,4 +49,7 @@ class AppHost
// void _RegisterAsMonarch();
// void _CreateMonarch();
// bool _ProposeCommandlineToMonarch();

void _DispatchCommandline(winrt::Windows::Foundation::IInspectable sender,
winrt::Microsoft::Terminal::Remoting::CommandlineArgs args);
};

3 comments on commit 9a41647

@github-actions

This comment was marked as outdated.

@oising
Copy link
Collaborator

@oising oising commented on 9a41647 Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone's excited :)

@zadjii-msft
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, yea I am! After months of prototyping and debate, this is finally coming together. It feels good ☺️

Please sign in to comment.