mirror of
https://github.com/microsoft/terminal.git
synced 2026-07-08 17:46:05 +00:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Fix typos found by codespell. Some of it in documentation and user-visible text, mostly in code comments. While I understand you might not be interested in fixing code comments, one of the reasons being extra noise in git history, kindly note that most spell checking tools do not discriminate between documentation and code comments. So it's easier to fix everything for long maintenance. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [ ] Closes #xxx * [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [X] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: [#501](https://github.com/MicrosoftDocs/terminal/pull/501) * [ ] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed I have checked and re-checked all changes.
120 lines
3.6 KiB
C++
120 lines
3.6 KiB
C++
#include "pch.h"
|
|
#include "AppState.h"
|
|
#include "../../types/inc/utils.hpp"
|
|
|
|
using namespace winrt;
|
|
using namespace winrt::Windows::Foundation;
|
|
using namespace ::Microsoft::Console;
|
|
|
|
void AppState::_setupConsole()
|
|
{
|
|
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
hInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
DWORD dwMode = 0;
|
|
GetConsoleMode(hOutput, &dwMode);
|
|
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
|
SetConsoleMode(hOutput, dwMode);
|
|
}
|
|
|
|
void AppState::initializeState()
|
|
{
|
|
// Initialize the console handles
|
|
_setupConsole();
|
|
|
|
// Set up WinRT
|
|
init_apartment();
|
|
}
|
|
|
|
bool AppState::areWeTheKing(const bool logPIDs)
|
|
{
|
|
auto kingPID = monarch.GetPID();
|
|
auto ourPID = GetCurrentProcessId();
|
|
if (logPIDs)
|
|
{
|
|
if (ourPID == kingPID)
|
|
{
|
|
printf(fmt::format("We're the\x1b[33m king\x1b[m - our PID is {}\n", ourPID).c_str());
|
|
}
|
|
else
|
|
{
|
|
printf(fmt::format("We're a lowly peasant - the king is {}\n", kingPID).c_str());
|
|
}
|
|
}
|
|
return (ourPID == kingPID);
|
|
}
|
|
|
|
void AppState::remindKingWhoTheyAre(const winrt::MonarchPeasantSample::IPeasant& iPeasant)
|
|
{
|
|
winrt::com_ptr<MonarchPeasantSample::implementation::Monarch> monarchImpl;
|
|
monarchImpl.copy_from(winrt::get_self<MonarchPeasantSample::implementation::Monarch>(monarch));
|
|
if (monarchImpl)
|
|
{
|
|
auto ourID = iPeasant.GetID();
|
|
monarchImpl->SetSelfID(ourID);
|
|
monarchImpl->AddPeasant(iPeasant);
|
|
printf("The king is peasant #%lld\n", ourID);
|
|
}
|
|
else
|
|
{
|
|
printf("Shoot, we wanted to be able to get the monarchImpl here but couldn't\n");
|
|
}
|
|
}
|
|
|
|
winrt::MonarchPeasantSample::Monarch AppState::instantiateMonarch()
|
|
{
|
|
// Heads up! This only works because we're using
|
|
// "metadata-based-marshalling" for our WinRT types. THat means the OS is
|
|
// using the .winmd file we generate to figure out the proxy/stub
|
|
// definitions for our types automatically. This only works in the following
|
|
// cases:
|
|
//
|
|
// * If we're running unpackaged: the .winmd but be a sibling of the .exe
|
|
// * If we're running packaged: the .winmd must be in the package root
|
|
auto monarch = create_instance<winrt::MonarchPeasantSample::Monarch>(Monarch_clsid,
|
|
CLSCTX_LOCAL_SERVER);
|
|
return monarch;
|
|
}
|
|
|
|
MonarchPeasantSample::IPeasant AppState::_createOurPeasant()
|
|
{
|
|
auto peasant = winrt::make_self<MonarchPeasantSample::implementation::Peasant>();
|
|
auto ourID = monarch.AddPeasant(*peasant);
|
|
printf("The monarch assigned us the ID %llu\n", ourID);
|
|
|
|
if (areWeTheKing())
|
|
{
|
|
remindKingWhoTheyAre(*peasant);
|
|
}
|
|
|
|
return *peasant;
|
|
}
|
|
|
|
void AppState::createMonarch()
|
|
{
|
|
monarch = AppState::instantiateMonarch();
|
|
}
|
|
|
|
// return true to exit early, false if we should continue into the main loop
|
|
bool AppState::processCommandline()
|
|
{
|
|
const bool isKing = areWeTheKing(false);
|
|
// If we're the king, we _definitely_ want to process the arguments, we were
|
|
// launched with them!
|
|
//
|
|
// Otherwise, the King will tell us if we should make a new window
|
|
const bool createNewWindow = isKing || monarch.ProposeCommandline({ args }, { L"placeholder CWD" });
|
|
|
|
if (createNewWindow)
|
|
{
|
|
peasant = _createOurPeasant();
|
|
peasant.ExecuteCommandline({ args }, { L"placeholder CWD" });
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
printf("The Monarch instructed us to not create a new window. We'll be exiting now.\n");
|
|
}
|
|
|
|
return true;
|
|
}
|