c33a97955f
This PR adds a sample monarch/peasant application. This is a type of application where a single "Monarch" can coordinate the actions of multiple other "Peasant" processes, as described by the specs in #7240 and #8135. This project is intended to be a standalone sample of how the architecture would work, without involving the entirety of the Windows Terminal build. Eventually, this architecture will be incorporated into `wt.exe` itself, to enable scenarios like: * Run `wt` in the current window (#4472) * Single Instance Mode (#2227) For an example of this sample running, see the below GIF: ![monarch-peasant-sample-001](https://user-images.githubusercontent.com/18356694/98262202-f39b1500-1f4a-11eb-9220-4af4d922339f.gif) This sample operates largely by printing to the console, to help the reader understand how it's working through its logic. I'm doing this mostly so we can have a _committed_ sample of this type of application, kinda like how VtPipeTerm is a sample ConPTY application. It's a lot easier to understand (& build on) when there aren't any window shenanigans, settings loading, Island instantiation, or anything else that the whole of `WindowsTerminal.exe` needs * [x] I work here * [x] This is sample code, so I'm not shipping tests for it. * [x] Go see the doc over in #8135
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#include "pch.h"
|
|
#include "SamplePeasant.h"
|
|
|
|
#include "Peasant.g.cpp"
|
|
#include "../../types/inc/utils.hpp"
|
|
|
|
using namespace winrt;
|
|
using namespace winrt::Windows::Foundation;
|
|
using namespace ::Microsoft::Console;
|
|
|
|
namespace winrt::MonarchPeasantSample::implementation
|
|
{
|
|
Peasant::Peasant()
|
|
{
|
|
}
|
|
|
|
void Peasant::AssignID(uint64_t id)
|
|
{
|
|
_id = id;
|
|
}
|
|
uint64_t Peasant::GetID()
|
|
{
|
|
return _id;
|
|
}
|
|
|
|
uint64_t Peasant::GetPID()
|
|
{
|
|
return GetCurrentProcessId();
|
|
}
|
|
|
|
bool Peasant::ExecuteCommandline(winrt::array_view<const winrt::hstring> args, winrt::hstring currentDirectory)
|
|
{
|
|
auto argsProcessed = 0;
|
|
std::wstring fullCmdline;
|
|
for (const auto& arg : args)
|
|
{
|
|
fullCmdline += argsProcessed++ == 0 ? L"sample.exe" : arg;
|
|
fullCmdline += L" ";
|
|
}
|
|
wprintf(L"\x1b[32mExecuted Commandline\x1b[m: \"");
|
|
wprintf(fullCmdline.c_str());
|
|
wprintf(L"\"\n");
|
|
return true;
|
|
}
|
|
|
|
void Peasant::raiseActivatedEvent()
|
|
{
|
|
_WindowActivatedHandlers(*this, nullptr);
|
|
}
|
|
|
|
}
|