mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-25 02:01:28 -05:00
Previously this project used a great variety of types to present text buffer coordinates: `short`, `unsigned short`, `int`, `unsigned int`, `size_t`, `ptrdiff_t`, `COORD`/`SMALL_RECT` (aka `short`), and more. This massive commit migrates almost all use of those types over to the centralized types `til::point`/`size`/`rect`/`inclusive_rect` and their underlying type `til::CoordType` (aka `int32_t`). Due to the size of the changeset and statistics I expect it to contain bugs. The biggest risk I see is that some code potentially, maybe implicitly, expected arithmetic to be mod 2^16 and that this code now allows it to be mod 2^32. Any narrowing into `short` later on would then throw exceptions. ## PR Checklist * [x] Closes #4015 * [x] I work here * [x] Tests added/passed ## Validation Steps Performed Casual usage of OpenConsole and Windows Terminal. ✅
104 lines
4.1 KiB
C++
104 lines
4.1 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
|
|
#include "ConptyConnection.g.h"
|
|
#include "ConnectionStateHolder.h"
|
|
|
|
#include <conpty-static.h>
|
|
|
|
namespace wil
|
|
{
|
|
// These belong in WIL upstream, so when we reingest the change that has them we'll get rid of ours.
|
|
using unique_static_pseudoconsole_handle = wil::unique_any<HPCON, decltype(&::ConptyClosePseudoConsole), ::ConptyClosePseudoConsole>;
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
|
{
|
|
struct ConptyConnection : ConptyConnectionT<ConptyConnection>, ConnectionStateHolder<ConptyConnection>
|
|
{
|
|
ConptyConnection(const HANDLE hSig,
|
|
const HANDLE hIn,
|
|
const HANDLE hOut,
|
|
const HANDLE hRef,
|
|
const HANDLE hServerProcess,
|
|
const HANDLE hClientProcess);
|
|
|
|
ConptyConnection() noexcept = default;
|
|
void Initialize(const Windows::Foundation::Collections::ValueSet& settings);
|
|
|
|
static winrt::fire_and_forget final_release(std::unique_ptr<ConptyConnection> connection);
|
|
|
|
void Start();
|
|
void WriteInput(const hstring& data);
|
|
void Resize(uint32_t rows, uint32_t columns);
|
|
void Close() noexcept;
|
|
void ClearBuffer();
|
|
|
|
void ShowHide(const bool show);
|
|
|
|
void ReparentWindow(const uint64_t newParent);
|
|
|
|
winrt::guid Guid() const noexcept;
|
|
winrt::hstring Commandline() const;
|
|
|
|
static void StartInboundListener();
|
|
static void StopInboundListener();
|
|
|
|
static winrt::event_token NewConnection(const NewConnectionHandler& handler);
|
|
static void NewConnection(const winrt::event_token& token);
|
|
|
|
static Windows::Foundation::Collections::ValueSet CreateSettings(const winrt::hstring& cmdline,
|
|
const winrt::hstring& startingDirectory,
|
|
const winrt::hstring& startingTitle,
|
|
const Windows::Foundation::Collections::IMapView<hstring, hstring>& environment,
|
|
uint32_t rows,
|
|
uint32_t columns,
|
|
const winrt::guid& guid);
|
|
|
|
WINRT_CALLBACK(TerminalOutput, TerminalOutputHandler);
|
|
|
|
private:
|
|
static HRESULT NewHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client) noexcept;
|
|
static winrt::hstring _commandlineFromProcess(HANDLE process);
|
|
|
|
HRESULT _LaunchAttachedClient() noexcept;
|
|
void _indicateExitWithStatus(unsigned int status) noexcept;
|
|
void _ClientTerminated() noexcept;
|
|
|
|
til::CoordType _initialRows{};
|
|
til::CoordType _initialCols{};
|
|
uint64_t _initialParentHwnd{ 0 };
|
|
hstring _commandline{};
|
|
hstring _startingDirectory{};
|
|
hstring _startingTitle{};
|
|
bool _initialVisibility{ true };
|
|
Windows::Foundation::Collections::ValueSet _environment{ nullptr };
|
|
guid _guid{}; // A unique session identifier for connected client
|
|
hstring _clientName{}; // The name of the process hosted by this ConPTY connection (as of launch).
|
|
|
|
bool _receivedFirstByte{ false };
|
|
std::chrono::high_resolution_clock::time_point _startTime{};
|
|
|
|
wil::unique_hfile _inPipe; // The pipe for writing input to
|
|
wil::unique_hfile _outPipe; // The pipe for reading output from
|
|
wil::unique_handle _hOutputThread;
|
|
wil::unique_process_information _piClient;
|
|
wil::unique_static_pseudoconsole_handle _hPC;
|
|
wil::unique_threadpool_wait _clientExitWait;
|
|
|
|
til::u8state _u8State{};
|
|
std::wstring _u16Str{};
|
|
std::array<char, 4096> _buffer{};
|
|
bool _passthroughMode{};
|
|
|
|
DWORD _OutputThread();
|
|
};
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::TerminalConnection::factory_implementation
|
|
{
|
|
BASIC_FACTORY(ConptyConnection);
|
|
}
|