Skip to content

Commit

Permalink
whoop, we pass the commandline from the peasant, to the monarch, and …
Browse files Browse the repository at this point in the history
…then back!
  • Loading branch information
zadjii-msft committed Dec 16, 2020
1 parent 36539cf commit 27ace16
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 26 deletions.
4 changes: 4 additions & 0 deletions src/cascadia/Remoting/CommandlineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ using namespace winrt::Windows::Foundation;

namespace winrt::Microsoft::Terminal::Remoting::implementation
{
// If you try to move this into the header, you will experience P A I N
// It must be defined after CommandlineArgs.g.cpp, otherwise the compiler
// will give you just the most impossible tmplate errors to try and
// decipher.
void CommandlineArgs::Args(winrt::array_view<const winrt::hstring> const& value)
{
_args = { value.begin(), value.end() };
Expand Down
22 changes: 11 additions & 11 deletions src/cascadia/Remoting/Monarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
bool Monarch::ProposeCommandline(array_view<const winrt::hstring> args,
winrt::hstring cwd)
{
auto argsProcessed = 0;
std::wstring fullCmdline;
for (const auto& arg : args)
{
fullCmdline += argsProcessed++ == 0 ? L"sample.exe" : arg;
fullCmdline += L" ";
}
wprintf(L"\x1b[36mProposed Commandline\x1b[m: \"");
wprintf(fullCmdline.c_str());
wprintf(L"\"\n");
// auto argsProcessed = 0;
// std::wstring fullCmdline;
// for (const auto& arg : args)
// {
// fullCmdline += argsProcessed++ == 0 ? L"sample.exe" : arg;
// fullCmdline += L" ";
// }
// wprintf(L"\x1b[36mProposed Commandline\x1b[m: \"");
// wprintf(fullCmdline.c_str());
// wprintf(L"\"\n");

bool createNewWindow = true;

Expand All @@ -113,7 +113,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// We'll need three args at least - [WindowsTerminal.exe, -s,
// id] to be able to have a session ID passed on the commandline.

if (args[1] == L"-s" || args[1] == L"--session")
if (args[1] == L"-w" || args[1] == L"--window")
{
auto sessionId = std::stoi({ args[2].data(), args[2].size() });
printf("Found a commandline intended for session %d\n", sessionId);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/Remoting/Peasant.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
private:
uint64_t _id{ 0 };

winrt::Microsoft::Terminal::Remoting::CommandlineArgs _initialArgs; //{ nullptr };
winrt::Microsoft::Terminal::Remoting::CommandlineArgs _initialArgs{ nullptr };

// array_view<const winrt::hstring> _args;
// winrt::hstring _cwd;
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/Remoting/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
_registrationHostClass = 0;
}

void WindowManager::ProposeCommandline(array_view<const winrt::hstring> args, const winrt::hstring cwd)
void WindowManager::ProposeCommandline(array_view<const winrt::hstring> args,
const winrt::hstring cwd)
{
const bool isKing = _areWeTheKing();
// If we're the king, we _definitely_ want to process the arguments, we were
Expand Down
51 changes: 38 additions & 13 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,11 @@ void AppHost::SetTaskbarProgress(const winrt::Windows::Foundation::IInspectable&
// - <none>
void AppHost::_HandleCommandlineArgs()
{
if (auto commandline{ GetCommandLineW() })
if (auto peasant{ _windowManager.CurrentWindow() })
{
int argc = 0;

// Get the argv, and turn them into a hstring array to pass to the app.
wil::unique_any<LPWSTR*, decltype(&::LocalFree), ::LocalFree> argv{ CommandLineToArgvW(commandline, &argc) };
if (argv)
if (auto args{ peasant.InitialArgs() })
{
std::vector<winrt::hstring> args;
for (auto& elem : wil::make_range(argv.get(), argc))
{
args.emplace_back(elem);
}

const auto result = _logic.SetStartupCommandline({ args });
const auto result = _logic.SetStartupCommandline(args.Args());
const auto message = _logic.ParseCommandlineMessage();
if (!message.empty())
{
Expand All @@ -177,6 +167,41 @@ void AppHost::_HandleCommandlineArgs()
}
}
}
// if (auto commandline{ GetCommandLineW() })
// {
// int argc = 0;

// // Get the argv, and turn them into a hstring array to pass to the app.
// wil::unique_any<LPWSTR*, decltype(&::LocalFree), ::LocalFree> argv{ CommandLineToArgvW(commandline, &argc) };
// if (argv)
// {
// std::vector<winrt::hstring> args;
// for (auto& elem : wil::make_range(argv.get(), argc))
// {
// args.emplace_back(elem);
// }

// const auto result = _logic.SetStartupCommandline({ args });
// const auto message = _logic.ParseCommandlineMessage();
// if (!message.empty())
// {
// const auto displayHelp = result == 0;
// const auto messageTitle = displayHelp ? IDS_HELP_DIALOG_TITLE : IDS_ERROR_DIALOG_TITLE;
// const auto messageIcon = displayHelp ? MB_ICONWARNING : MB_ICONERROR;
// // TODO:GH#4134: polish this dialog more, to make the text more
// // like msiexec /?
// MessageBoxW(nullptr,
// message.data(),
// GetStringResource(messageTitle).data(),
// MB_OK | messageIcon);

// if (_logic.ShouldExitEarly())
// {
// ExitProcess(result);
// }
// }
// }
// }
}

// Method Description:
Expand Down

1 comment on commit 27ace16

@github-actions

This comment was marked as outdated.

Please sign in to comment.