diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 72c34d2f629..3bc6e009b86 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -340,7 +340,7 @@ class Microsoft::Terminal::Core::Terminal final : CursorType _defaultCursorShape = CursorType::Legacy; - til::enumset _systemMode{ Mode::AutoWrap }; + til::enumset _systemMode{ Mode::AutoWrap, Mode::LineFeed }; bool _snapOnInput = true; bool _altGrAliasing = true; diff --git a/src/host/PassthroughState.cpp b/src/host/PassthroughState.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/host/PassthroughState.h b/src/host/PassthroughState.h new file mode 100644 index 00000000000..df2497efb5b --- /dev/null +++ b/src/host/PassthroughState.h @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +namespace Microsoft::Console +{ + struct PassthroughState + { + explicit PassthroughState(wil::unique_hfile output) : + _output{ std::move(output) } + { + } + + private: + wil::unique_hfile _output; + }; +} diff --git a/src/host/VtApiRoutines.cpp b/src/host/VtApiRoutines.cpp deleted file mode 100644 index fe7d0b7060e..00000000000 --- a/src/host/VtApiRoutines.cpp +++ /dev/null @@ -1,810 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#include "precomp.h" -#include "VtApiRoutines.h" -#include "../interactivity/inc/ServiceLocator.hpp" -#include "../types/inc/convert.hpp" - -using namespace Microsoft::Console::Interactivity; - -// When someone attempts to use the console APIs to do a "read back" -// of the console buffer, we have to give them **something**. -// These two structures are just some gaudy-colored replacement character -// text to give them data but represent they've done something that cannot -// be supported under VT passthrough mode. -// ---- -// They can't be supported because in passthrough we maintain no internal -// buffer to answer these questions, and there is no VT sequence that lets -// us query the final terminal's buffer state. Even if a VT sequence did exist -// (and we personally believe it shouldn't), there's a possibility that it would -// read a massive amount of data and cause severe perf issues as applications coded -// to this old API are likely leaning on it heavily and asking for this data in a -// loop via VT would be a nightmare of parsing and formatting and over-the-wire transmission. - -static constexpr CHAR_INFO s_readBackUnicode{ - { UNICODE_REPLACEMENT }, - FOREGROUND_INTENSITY | FOREGROUND_RED | BACKGROUND_GREEN -}; - -static constexpr CHAR_INFO s_readBackAscii{ - { L'?' }, - FOREGROUND_INTENSITY | FOREGROUND_RED | BACKGROUND_GREEN -}; - -VtApiRoutines::VtApiRoutines() : - m_inputCodepage(ServiceLocator::LocateGlobals().getConsoleInformation().CP), - m_outputCodepage(ServiceLocator::LocateGlobals().getConsoleInformation().OutputCP), - m_inputMode(), - m_outputMode(), - m_pUsualRoutines(), - m_pVtEngine(), - m_listeningForDSR(false) -{ -} - -#pragma warning(push) -#pragma warning(disable : 4100) // unreferenced param - -void VtApiRoutines::GetConsoleInputCodePageImpl(ULONG& codepage) noexcept -{ - codepage = m_inputCodepage; - return; -} - -void VtApiRoutines::GetConsoleOutputCodePageImpl(ULONG& codepage) noexcept -{ - codepage = m_outputCodepage; - return; -} - -void VtApiRoutines::GetConsoleInputModeImpl(InputBuffer& context, - ULONG& mode) noexcept -{ - mode = m_inputMode; - return; -} - -void VtApiRoutines::GetConsoleOutputModeImpl(SCREEN_INFORMATION& context, - ULONG& mode) noexcept -{ - mode = m_outputMode; - return; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleInputModeImpl(InputBuffer& context, - const ULONG mode) noexcept -{ - m_inputMode = mode; - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleOutputModeImpl(SCREEN_INFORMATION& context, - const ULONG Mode) noexcept -{ - m_outputMode = Mode; - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::GetNumberOfConsoleInputEventsImpl(const InputBuffer& context, - ULONG& events) noexcept -{ - return m_pUsualRoutines->GetNumberOfConsoleInputEventsImpl(context, events); -} - -void VtApiRoutines::_SynchronizeCursor(std::unique_ptr& waiter) noexcept -{ - // If we're about to tell the caller to wait, let's synchronize the cursor we have with what - // the terminal is presenting in case there's a cooked read going on. - // TODO GH#10001: we only need to do this in cooked read mode. - if (waiter) - { - m_listeningForDSR = true; - (void)m_pVtEngine->_ListenForDSR(); - (void)m_pVtEngine->RequestCursor(); - } -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleInputImpl( - IConsoleInputObject& context, - InputEventQueue& outEvents, - const size_t eventReadCount, - INPUT_READ_HANDLE_DATA& readHandleState, - const bool IsUnicode, - const bool IsPeek, - std::unique_ptr& waiter) noexcept -{ - const auto hr = m_pUsualRoutines->GetConsoleInputImpl(context, outEvents, eventReadCount, readHandleState, IsUnicode, IsPeek, waiter); - _SynchronizeCursor(waiter); - return hr; -} - -[[nodiscard]] HRESULT VtApiRoutines::ReadConsoleImpl(IConsoleInputObject& context, - std::span buffer, - size_t& written, - std::unique_ptr& waiter, - const std::wstring_view initialData, - const std::wstring_view exeName, - INPUT_READ_HANDLE_DATA& readHandleState, - const bool IsUnicode, - const HANDLE clientHandle, - const DWORD controlWakeupMask, - DWORD& controlKeyState) noexcept -{ - const auto hr = m_pUsualRoutines->ReadConsoleImpl(context, buffer, written, waiter, initialData, exeName, readHandleState, IsUnicode, clientHandle, controlWakeupMask, controlKeyState); - // If we're about to tell the caller to wait, let's synchronize the cursor we have with what - // the terminal is presenting in case there's a cooked read going on. - // TODO GH10001: we only need to do this in cooked read mode. - if (clientHandle) - { - m_listeningForDSR = true; - (void)m_pVtEngine->_ListenForDSR(); - (void)m_pVtEngine->RequestCursor(); - } - return hr; -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleAImpl(IConsoleOutputObject& context, - const std::string_view buffer, - size_t& read, - bool requiresVtQuirk, - std::unique_ptr& waiter) noexcept -{ - if (CP_UTF8 == m_outputCodepage) - { - (void)m_pVtEngine->WriteTerminalUtf8(buffer); - } - else - { - (void)m_pVtEngine->WriteTerminalW(ConvertToW(m_outputCodepage, buffer)); - } - - (void)m_pVtEngine->_Flush(); - read = buffer.size(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleWImpl(IConsoleOutputObject& context, - const std::wstring_view buffer, - size_t& read, - bool requiresVtQuirk, - std::unique_ptr& waiter) noexcept -{ - (void)m_pVtEngine->WriteTerminalW(buffer); - (void)m_pVtEngine->_Flush(); - read = buffer.size(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleLangIdImpl(LANGID& langId) noexcept -{ - return m_pUsualRoutines->GetConsoleLangIdImpl(langId); -} - -[[nodiscard]] HRESULT VtApiRoutines::FillConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const WORD attribute, - const size_t lengthToWrite, - const til::point startingCoordinate, - size_t& cellsModified) noexcept -{ - (void)m_pVtEngine->_CursorPosition(startingCoordinate); - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(attribute), true); - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(attribute >> 4), false); - (void)m_pVtEngine->_WriteFill(lengthToWrite, s_readBackAscii.Char.AsciiChar); - (void)m_pVtEngine->_Flush(); - cellsModified = lengthToWrite; - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::FillConsoleOutputCharacterAImpl(IConsoleOutputObject& OutContext, - const char character, - const size_t lengthToWrite, - const til::point startingCoordinate, - size_t& cellsModified) noexcept -{ - // I mean... if you get your jollies by using UTF8 for single byte codepoints... - // we may as well skip a lot of conversion work and just write it out. - if (m_outputCodepage == CP_UTF8 && character <= 0x7F) - { - (void)m_pVtEngine->_CursorPosition(startingCoordinate); - (void)m_pVtEngine->_WriteFill(lengthToWrite, character); - (void)m_pVtEngine->_Flush(); - cellsModified = lengthToWrite; - return S_OK; - } - else - { - const auto wstr = ConvertToW(m_outputCodepage, std::string_view{ &character, 1 }); - return FillConsoleOutputCharacterWImpl(OutContext, wstr.front(), lengthToWrite, startingCoordinate, cellsModified); - } -} - -[[nodiscard]] HRESULT VtApiRoutines::FillConsoleOutputCharacterWImpl(IConsoleOutputObject& OutContext, - const wchar_t character, - const size_t lengthToWrite, - const til::point startingCoordinate, - size_t& cellsModified, - const bool enablePowershellShim) noexcept -{ - (void)m_pVtEngine->_CursorPosition(startingCoordinate); - const std::wstring_view sv{ &character, 1 }; - - // TODO GH10001: horrible. it'll WC2MB over and over...we should do that once then emit... and then rep... - // TODO GH10001: there's probably an optimization for if ((character & 0x7F) == character) --> call the UTF8 one. - for (size_t i = 0; i < lengthToWrite; ++i) - { - (void)m_pVtEngine->WriteTerminalW(sv); - } - - (void)m_pVtEngine->_Flush(); - cellsModified = lengthToWrite; - return S_OK; -} - -//// Process based. Restrict in protocol side? -//HRESULT GenerateConsoleCtrlEventImpl(const ULONG ProcessGroupFilter, -// const ULONG ControlEvent); - -void VtApiRoutines::SetConsoleActiveScreenBufferImpl(SCREEN_INFORMATION& newContext) noexcept -{ - return; -} - -void VtApiRoutines::FlushConsoleInputBuffer(InputBuffer& context) noexcept -{ - m_pUsualRoutines->FlushConsoleInputBuffer(context); -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleInputCodePageImpl(const ULONG codepage) noexcept -{ - m_inputCodepage = codepage; - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleOutputCodePageImpl(const ULONG codepage) noexcept -{ - m_outputCodepage = codepage; - return S_OK; -} - -void VtApiRoutines::GetConsoleCursorInfoImpl(const SCREEN_INFORMATION& context, - ULONG& size, - bool& isVisible) noexcept -{ - // TODO GH10001: good luck capturing this out of the input buffer when it comes back in. - //m_pVtEngine->RequestCursor(); - return; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleCursorInfoImpl(SCREEN_INFORMATION& context, - const ULONG size, - const bool isVisible) noexcept -{ - isVisible ? (void)m_pVtEngine->_ShowCursor() : (void)m_pVtEngine->_HideCursor(); - (void)m_pVtEngine->_Flush(); - return S_OK; -} - -//// driver will pare down for non-Ex method -void VtApiRoutines::GetConsoleScreenBufferInfoExImpl(const SCREEN_INFORMATION& context, - CONSOLE_SCREEN_BUFFER_INFOEX& data) noexcept -{ - // TODO GH10001: this is technically full of potentially incorrect data. do we care? should we store it in here with set? - return m_pUsualRoutines->GetConsoleScreenBufferInfoExImpl(context, data); -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleScreenBufferInfoExImpl(SCREEN_INFORMATION& context, - const CONSOLE_SCREEN_BUFFER_INFOEX& data) noexcept -{ - (void)m_pVtEngine->_ResizeWindow(data.srWindow.Right - data.srWindow.Left, data.srWindow.Bottom - data.srWindow.Top); - (void)m_pVtEngine->_CursorPosition(til::wrap_coord(data.dwCursorPosition)); - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(data.wAttributes), true); - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(data.wAttributes >> 4), false); - //color table? - // popup attributes... hold internally? - // TODO GH10001: popups are gonna erase the stuff behind them... deal with that somehow. - (void)m_pVtEngine->_Flush(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleScreenBufferSizeImpl(SCREEN_INFORMATION& context, - const til::size size) noexcept -{ - // Don't transmit. The terminal figures out its own buffer size. - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleCursorPositionImpl(SCREEN_INFORMATION& context, - const til::point position) noexcept -{ - if (m_listeningForDSR) - { - context.GetActiveBuffer().GetTextBuffer().GetCursor().SetPosition(position); - m_pVtEngine->SetTerminalCursorTextPosition(position); - } - else - { - (void)m_pVtEngine->_CursorPosition(position); - (void)m_pVtEngine->_Flush(); - } - return S_OK; -} - -void VtApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& context, - til::size& size) noexcept -{ - m_pUsualRoutines->GetLargestConsoleWindowSizeImpl(context, size); // This is likely super weird but not weirder than existing ConPTY answers. - return; -} - -[[nodiscard]] HRESULT VtApiRoutines::ScrollConsoleScreenBufferAImpl(SCREEN_INFORMATION& context, - const til::inclusive_rect& source, - const til::point target, - std::optional clip, - const char fillCharacter, - const WORD fillAttribute) noexcept -{ - // TODO GH10001: Use DECCRA - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::ScrollConsoleScreenBufferWImpl(SCREEN_INFORMATION& context, - const til::inclusive_rect& source, - const til::point target, - std::optional clip, - const wchar_t fillCharacter, - const WORD fillAttribute, - const bool enableCmdShim) noexcept -{ - // TODO GH10001: Use DECCRA - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleTextAttributeImpl(SCREEN_INFORMATION& context, - const WORD attribute) noexcept -{ - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(attribute), true); - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(attribute >> 4), false); - (void)m_pVtEngine->_Flush(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleWindowInfoImpl(SCREEN_INFORMATION& context, - const bool isAbsolute, - const til::inclusive_rect& windowRect) noexcept -{ - (void)m_pVtEngine->_ResizeWindow(windowRect.right - windowRect.left + 1, windowRect.bottom - windowRect.top + 1); - (void)m_pVtEngine->_Flush(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputAttributeImpl(const SCREEN_INFORMATION& context, - const til::point origin, - std::span buffer, - size_t& written) noexcept -{ - std::fill_n(buffer.data(), buffer.size(), s_readBackUnicode.Attributes); // should be same as the ascii one. - written = buffer.size(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputCharacterAImpl(const SCREEN_INFORMATION& context, - const til::point origin, - std::span buffer, - size_t& written) noexcept -{ - std::fill_n(buffer.data(), buffer.size(), s_readBackAscii.Char.AsciiChar); - written = buffer.size(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputCharacterWImpl(const SCREEN_INFORMATION& context, - const til::point origin, - std::span buffer, - size_t& written) noexcept -{ - std::fill_n(buffer.data(), buffer.size(), s_readBackUnicode.Char.UnicodeChar); - written = buffer.size(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleInputAImpl(InputBuffer& context, - const std::span buffer, - size_t& written, - const bool append) noexcept -{ - return m_pUsualRoutines->WriteConsoleInputAImpl(context, buffer, written, append); -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleInputWImpl(InputBuffer& context, - const std::span buffer, - size_t& written, - const bool append) noexcept -{ - return m_pUsualRoutines->WriteConsoleInputWImpl(context, buffer, written, append); -} - -extern HRESULT _ConvertCellsToWInplace(const UINT codepage, - std::span buffer, - const Viewport& rectangle) noexcept; - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputAImpl(SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& requestRectangle, - Microsoft::Console::Types::Viewport& writtenRectangle) noexcept -{ - // No UTF8 optimization because the entire `CHAR_INFO` grid system doesn't make sense for UTF-8 - // with up to 4 bytes per cell...or more! - - RETURN_IF_FAILED(_ConvertCellsToWInplace(m_outputCodepage, buffer, requestRectangle)); - return WriteConsoleOutputWImpl(context, buffer, requestRectangle, writtenRectangle); -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputWImpl(SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& requestRectangle, - Microsoft::Console::Types::Viewport& writtenRectangle) noexcept -{ - auto cursor = requestRectangle.Origin(); - - const size_t width = requestRectangle.Width(); - size_t pos = 0; - - while (pos < buffer.size()) - { - (void)m_pVtEngine->_CursorPosition(cursor); - - const auto subspan = buffer.subspan(pos, width); - - for (const auto& ci : subspan) - { - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(ci.Attributes), true); - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(ci.Attributes >> 4), false); - (void)m_pVtEngine->WriteTerminalW(std::wstring_view{ &ci.Char.UnicodeChar, 1 }); - } - - ++cursor.y; - pos += width; - } - - (void)m_pVtEngine->_Flush(); - - //TODO GH10001: trim to buffer size? - writtenRectangle = requestRectangle; - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const std::span attrs, - const til::point target, - size_t& used) noexcept -{ - (void)m_pVtEngine->_CursorPosition(target); - - for (const auto& attr : attrs) - { - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(attr), true); - (void)m_pVtEngine->_SetGraphicsRendition16Color(static_cast(attr >> 4), false); - (void)m_pVtEngine->WriteTerminalUtf8(std::string_view{ &s_readBackAscii.Char.AsciiChar, 1 }); - } - - (void)m_pVtEngine->_Flush(); - - used = attrs.size(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputCharacterAImpl(IConsoleOutputObject& OutContext, - const std::string_view text, - const til::point target, - size_t& used) noexcept -{ - if (m_outputCodepage == CP_UTF8) - { - (void)m_pVtEngine->_CursorPosition(target); - (void)m_pVtEngine->WriteTerminalUtf8(text); - (void)m_pVtEngine->_Flush(); - return S_OK; - } - else - { - return WriteConsoleOutputCharacterWImpl(OutContext, ConvertToW(m_outputCodepage, text), target, used); - } -} - -[[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputCharacterWImpl(IConsoleOutputObject& OutContext, - const std::wstring_view text, - const til::point target, - size_t& used) noexcept -{ - (void)m_pVtEngine->_CursorPosition(target); - (void)m_pVtEngine->WriteTerminalW(text); - (void)m_pVtEngine->_Flush(); - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputAImpl(const SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& sourceRectangle, - Microsoft::Console::Types::Viewport& readRectangle) noexcept -{ - std::fill_n(buffer.data(), buffer.size(), s_readBackAscii); - // TODO GH10001: do we need to constrict readRectangle to within the known buffer size... probably. - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputWImpl(const SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& sourceRectangle, - Microsoft::Console::Types::Viewport& readRectangle) noexcept -{ - std::fill_n(buffer.data(), buffer.size(), s_readBackUnicode); - // TODO GH10001: do we need to constrict readRectangle to within the known buffer size... probably. - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleTitleAImpl(std::span title, - size_t& written, - size_t& needed) noexcept -{ - written = 0; - needed = 0; - - if (!title.empty()) - { - title.front() = ANSI_NULL; - } - - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleTitleWImpl(std::span title, - size_t& written, - size_t& needed) noexcept -{ - written = 0; - needed = 0; - - if (!title.empty()) - { - title.front() = UNICODE_NULL; - } - - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleOriginalTitleAImpl(std::span title, - size_t& written, - size_t& needed) noexcept -{ - written = 0; - needed = 0; - - if (!title.empty()) - { - title.front() = ANSI_NULL; - } - - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleOriginalTitleWImpl(std::span title, - size_t& written, - size_t& needed) noexcept -{ - written = 0; - needed = 0; - - if (!title.empty()) - { - title.front() = UNICODE_NULL; - } - - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleTitleAImpl(const std::string_view title) noexcept -{ - return SetConsoleTitleWImpl(ConvertToW(m_inputCodepage, title)); -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleTitleWImpl(const std::wstring_view title) noexcept -{ - (void)m_pVtEngine->UpdateTitle(title); - (void)m_pVtEngine->_Flush(); - return S_OK; -} - -void VtApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept -{ - buttons = 2; - return; -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleFontSizeImpl(const SCREEN_INFORMATION& context, - const DWORD index, - til::size& size) noexcept -{ - size.width = 8; - size.height = 12; - return S_OK; -} - -//// driver will pare down for non-Ex method -[[nodiscard]] HRESULT VtApiRoutines::GetCurrentConsoleFontExImpl(const SCREEN_INFORMATION& context, - const bool isForMaximumWindowSize, - CONSOLE_FONT_INFOEX& consoleFontInfoEx) noexcept -{ - return S_OK; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleDisplayModeImpl(SCREEN_INFORMATION& context, - const ULONG flags, - til::size& newSize) noexcept -{ - return S_OK; -} - -void VtApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept -{ - flags = 0; - return; -} - -[[nodiscard]] HRESULT VtApiRoutines::AddConsoleAliasAImpl(const std::string_view source, - const std::string_view target, - const std::string_view exeName) noexcept -{ - return m_pUsualRoutines->AddConsoleAliasAImpl(source, target, exeName); -} - -[[nodiscard]] HRESULT VtApiRoutines::AddConsoleAliasWImpl(const std::wstring_view source, - const std::wstring_view target, - const std::wstring_view exeName) noexcept -{ - return m_pUsualRoutines->AddConsoleAliasWImpl(source, target, exeName); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasAImpl(const std::string_view source, - std::span target, - size_t& written, - const std::string_view exeName) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasAImpl(source, target, written, exeName); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasWImpl(const std::wstring_view source, - std::span target, - size_t& written, - const std::wstring_view exeName) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasWImpl(source, target, written, exeName); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasesLengthAImpl(const std::string_view exeName, - size_t& bufferRequired) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasesLengthAImpl(exeName, bufferRequired); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasesLengthWImpl(const std::wstring_view exeName, - size_t& bufferRequired) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasesLengthWImpl(exeName, bufferRequired); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesLengthAImpl(size_t& bufferRequired) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasExesLengthAImpl(bufferRequired); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesLengthWImpl(size_t& bufferRequired) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasExesLengthWImpl(bufferRequired); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasesAImpl(const std::string_view exeName, - std::span alias, - size_t& written) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasesAImpl(exeName, alias, written); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasesWImpl(const std::wstring_view exeName, - std::span alias, - size_t& written) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasesWImpl(exeName, alias, written); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesAImpl(std::span aliasExes, - size_t& written) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasExesAImpl(aliasExes, written); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesWImpl(std::span aliasExes, - size_t& written) noexcept -{ - return m_pUsualRoutines->GetConsoleAliasExesWImpl(aliasExes, written); -} - -[[nodiscard]] HRESULT VtApiRoutines::ExpungeConsoleCommandHistoryAImpl(const std::string_view exeName) noexcept -{ - return m_pUsualRoutines->ExpungeConsoleCommandHistoryAImpl(exeName); -} - -[[nodiscard]] HRESULT VtApiRoutines::ExpungeConsoleCommandHistoryWImpl(const std::wstring_view exeName) noexcept -{ - return m_pUsualRoutines->ExpungeConsoleCommandHistoryWImpl(exeName); -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleNumberOfCommandsAImpl(const std::string_view exeName, - const size_t numberOfCommands) noexcept -{ - return m_pUsualRoutines->SetConsoleNumberOfCommandsAImpl(exeName, numberOfCommands); -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleNumberOfCommandsWImpl(const std::wstring_view exeName, - const size_t numberOfCommands) noexcept -{ - return m_pUsualRoutines->SetConsoleNumberOfCommandsWImpl(exeName, numberOfCommands); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleCommandHistoryLengthAImpl(const std::string_view exeName, - size_t& length) noexcept -{ - return m_pUsualRoutines->GetConsoleCommandHistoryLengthAImpl(exeName, length); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleCommandHistoryLengthWImpl(const std::wstring_view exeName, - size_t& length) noexcept -{ - return m_pUsualRoutines->GetConsoleCommandHistoryLengthWImpl(exeName, length); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleCommandHistoryAImpl(const std::string_view exeName, - std::span commandHistory, - size_t& written) noexcept -{ - return m_pUsualRoutines->GetConsoleCommandHistoryAImpl(exeName, commandHistory, written); -} - -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleCommandHistoryWImpl(const std::wstring_view exeName, - std::span commandHistory, - size_t& written) noexcept -{ - return m_pUsualRoutines->GetConsoleCommandHistoryWImpl(exeName, commandHistory, written); -} - -void VtApiRoutines::GetConsoleWindowImpl(HWND& hwnd) noexcept -{ - hwnd = ServiceLocator::LocatePseudoWindow(); - return; -} - -void VtApiRoutines::GetConsoleSelectionInfoImpl(CONSOLE_SELECTION_INFO& consoleSelectionInfo) noexcept -{ - consoleSelectionInfo = { 0 }; - return; -} - -void VtApiRoutines::GetConsoleHistoryInfoImpl(CONSOLE_HISTORY_INFO& consoleHistoryInfo) noexcept -{ - m_pUsualRoutines->GetConsoleHistoryInfoImpl(consoleHistoryInfo); - return; -} - -[[nodiscard]] HRESULT VtApiRoutines::SetConsoleHistoryInfoImpl(const CONSOLE_HISTORY_INFO& consoleHistoryInfo) noexcept -{ - return m_pUsualRoutines->SetConsoleHistoryInfoImpl(consoleHistoryInfo); -} - -[[nodiscard]] HRESULT VtApiRoutines::SetCurrentConsoleFontExImpl(IConsoleOutputObject& context, - const bool isForMaximumWindowSize, - const CONSOLE_FONT_INFOEX& consoleFontInfoEx) noexcept -{ - return S_OK; -} - -#pragma warning(pop) diff --git a/src/host/VtApiRoutines.h b/src/host/VtApiRoutines.h deleted file mode 100644 index 7dc77f78b09..00000000000 --- a/src/host/VtApiRoutines.h +++ /dev/null @@ -1,366 +0,0 @@ -/*++ -Copyright (c) Microsoft Corporation -Licensed under the MIT license. - -Module Name: -- VtApiRoutines.h - -Abstract: -- This file defines the interface to respond to all API calls by using VT on behalf of the client - -Author: -- Michael Niksa (miniksa) 26-Jul-2021 - -Revision History: -- Adapted from original items in srvinit.cpp, getset.cpp, directio.cpp, stream.cpp ---*/ - -#pragma once - -#include "../server/IApiRoutines.h" -#include "../renderer/vt/Xterm256Engine.hpp" - -class VtApiRoutines : public IApiRoutines -{ -public: - VtApiRoutines(); - -#pragma region ObjectManagement - /*HRESULT CreateInitialObjects(_Out_ InputBuffer** const ppInputObject, - _Out_ SCREEN_INFORMATION** const ppOutputObject); - */ - -#pragma endregion - -#pragma region L1 - void GetConsoleInputCodePageImpl(ULONG& codepage) noexcept override; - - void GetConsoleOutputCodePageImpl(ULONG& codepage) noexcept override; - - void GetConsoleInputModeImpl(InputBuffer& context, - ULONG& mode) noexcept override; - - void GetConsoleOutputModeImpl(SCREEN_INFORMATION& context, - ULONG& mode) noexcept override; - - [[nodiscard]] HRESULT SetConsoleInputModeImpl(InputBuffer& context, - const ULONG mode) noexcept override; - - [[nodiscard]] HRESULT SetConsoleOutputModeImpl(SCREEN_INFORMATION& context, - const ULONG Mode) noexcept override; - - [[nodiscard]] HRESULT GetNumberOfConsoleInputEventsImpl(const InputBuffer& context, - ULONG& events) noexcept override; - - [[nodiscard]] HRESULT GetConsoleInputImpl(IConsoleInputObject& context, - InputEventQueue& outEvents, - const size_t eventReadCount, - INPUT_READ_HANDLE_DATA& readHandleState, - const bool IsUnicode, - const bool IsPeek, - std::unique_ptr& waiter) noexcept override; - - [[nodiscard]] HRESULT ReadConsoleImpl(IConsoleInputObject& context, - std::span buffer, - size_t& written, - std::unique_ptr& waiter, - const std::wstring_view initialData, - const std::wstring_view exeName, - INPUT_READ_HANDLE_DATA& readHandleState, - const bool IsUnicode, - const HANDLE clientHandle, - const DWORD controlWakeupMask, - DWORD& controlKeyState) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleAImpl(IConsoleOutputObject& context, - const std::string_view buffer, - size_t& read, - bool requiresVtQuirk, - std::unique_ptr& waiter) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleWImpl(IConsoleOutputObject& context, - const std::wstring_view buffer, - size_t& read, - bool requiresVtQuirk, - std::unique_ptr& waiter) noexcept override; - -#pragma region ThreadCreationInfo - [[nodiscard]] HRESULT GetConsoleLangIdImpl(LANGID& langId) noexcept override; -#pragma endregion - -#pragma endregion - -#pragma region L2 - - [[nodiscard]] HRESULT FillConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const WORD attribute, - const size_t lengthToWrite, - const til::point startingCoordinate, - size_t& cellsModified) noexcept override; - - [[nodiscard]] HRESULT FillConsoleOutputCharacterAImpl(IConsoleOutputObject& OutContext, - const char character, - const size_t lengthToWrite, - const til::point startingCoordinate, - size_t& cellsModified) noexcept override; - - [[nodiscard]] HRESULT FillConsoleOutputCharacterWImpl(IConsoleOutputObject& OutContext, - const wchar_t character, - const size_t lengthToWrite, - const til::point startingCoordinate, - size_t& cellsModified, - const bool enablePowershellShim = false) noexcept override; - - //// Process based. Restrict in protocol side? - //HRESULT GenerateConsoleCtrlEventImpl(const ULONG ProcessGroupFilter, - // const ULONG ControlEvent); - - void SetConsoleActiveScreenBufferImpl(SCREEN_INFORMATION& newContext) noexcept override; - - void FlushConsoleInputBuffer(InputBuffer& context) noexcept override; - - [[nodiscard]] HRESULT SetConsoleInputCodePageImpl(const ULONG codepage) noexcept override; - - [[nodiscard]] HRESULT SetConsoleOutputCodePageImpl(const ULONG codepage) noexcept override; - - void GetConsoleCursorInfoImpl(const SCREEN_INFORMATION& context, - ULONG& size, - bool& isVisible) noexcept override; - - [[nodiscard]] HRESULT SetConsoleCursorInfoImpl(SCREEN_INFORMATION& context, - const ULONG size, - const bool isVisible) noexcept override; - - //// driver will pare down for non-Ex method - void GetConsoleScreenBufferInfoExImpl(const SCREEN_INFORMATION& context, - CONSOLE_SCREEN_BUFFER_INFOEX& data) noexcept override; - - [[nodiscard]] HRESULT SetConsoleScreenBufferInfoExImpl(SCREEN_INFORMATION& context, - const CONSOLE_SCREEN_BUFFER_INFOEX& data) noexcept override; - - [[nodiscard]] HRESULT SetConsoleScreenBufferSizeImpl(SCREEN_INFORMATION& context, - const til::size size) noexcept override; - - [[nodiscard]] HRESULT SetConsoleCursorPositionImpl(SCREEN_INFORMATION& context, - const til::point position) noexcept override; - - void GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& context, - til::size& size) noexcept override; - - [[nodiscard]] HRESULT ScrollConsoleScreenBufferAImpl(SCREEN_INFORMATION& context, - const til::inclusive_rect& source, - const til::point target, - std::optional clip, - const char fillCharacter, - const WORD fillAttribute) noexcept override; - - [[nodiscard]] HRESULT ScrollConsoleScreenBufferWImpl(SCREEN_INFORMATION& context, - const til::inclusive_rect& source, - const til::point target, - std::optional clip, - const wchar_t fillCharacter, - const WORD fillAttribute, - const bool enableCmdShim = false) noexcept override; - - [[nodiscard]] HRESULT SetConsoleTextAttributeImpl(SCREEN_INFORMATION& context, - const WORD attribute) noexcept override; - - [[nodiscard]] HRESULT SetConsoleWindowInfoImpl(SCREEN_INFORMATION& context, - const bool isAbsolute, - const til::inclusive_rect& windowRect) noexcept override; - - [[nodiscard]] HRESULT ReadConsoleOutputAttributeImpl(const SCREEN_INFORMATION& context, - const til::point origin, - std::span buffer, - size_t& written) noexcept override; - - [[nodiscard]] HRESULT ReadConsoleOutputCharacterAImpl(const SCREEN_INFORMATION& context, - const til::point origin, - std::span buffer, - size_t& written) noexcept override; - - [[nodiscard]] HRESULT ReadConsoleOutputCharacterWImpl(const SCREEN_INFORMATION& context, - const til::point origin, - std::span buffer, - size_t& written) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleInputAImpl(InputBuffer& context, - const std::span buffer, - size_t& written, - const bool append) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleInputWImpl(InputBuffer& context, - const std::span buffer, - size_t& written, - const bool append) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleOutputAImpl(SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& requestRectangle, - Microsoft::Console::Types::Viewport& writtenRectangle) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleOutputWImpl(SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& requestRectangle, - Microsoft::Console::Types::Viewport& writtenRectangle) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const std::span attrs, - const til::point target, - size_t& used) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleOutputCharacterAImpl(IConsoleOutputObject& OutContext, - const std::string_view text, - const til::point target, - size_t& used) noexcept override; - - [[nodiscard]] HRESULT WriteConsoleOutputCharacterWImpl(IConsoleOutputObject& OutContext, - const std::wstring_view text, - const til::point target, - size_t& used) noexcept override; - - [[nodiscard]] HRESULT ReadConsoleOutputAImpl(const SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& sourceRectangle, - Microsoft::Console::Types::Viewport& readRectangle) noexcept override; - - [[nodiscard]] HRESULT ReadConsoleOutputWImpl(const SCREEN_INFORMATION& context, - std::span buffer, - const Microsoft::Console::Types::Viewport& sourceRectangle, - Microsoft::Console::Types::Viewport& readRectangle) noexcept override; - - [[nodiscard]] HRESULT GetConsoleTitleAImpl(std::span title, - size_t& written, - size_t& needed) noexcept override; - - [[nodiscard]] HRESULT GetConsoleTitleWImpl(std::span title, - size_t& written, - size_t& needed) noexcept override; - - [[nodiscard]] HRESULT GetConsoleOriginalTitleAImpl(std::span title, - size_t& written, - size_t& needed) noexcept override; - - [[nodiscard]] HRESULT GetConsoleOriginalTitleWImpl(std::span title, - size_t& written, - size_t& needed) noexcept override; - - [[nodiscard]] HRESULT SetConsoleTitleAImpl(const std::string_view title) noexcept override; - - [[nodiscard]] HRESULT SetConsoleTitleWImpl(const std::wstring_view title) noexcept override; - -#pragma endregion - -#pragma region L3 - void GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept override; - - [[nodiscard]] HRESULT GetConsoleFontSizeImpl(const SCREEN_INFORMATION& context, - const DWORD index, - til::size& size) noexcept override; - - //// driver will pare down for non-Ex method - [[nodiscard]] HRESULT GetCurrentConsoleFontExImpl(const SCREEN_INFORMATION& context, - const bool isForMaximumWindowSize, - CONSOLE_FONT_INFOEX& consoleFontInfoEx) noexcept override; - - [[nodiscard]] HRESULT SetConsoleDisplayModeImpl(SCREEN_INFORMATION& context, - const ULONG flags, - til::size& newSize) noexcept override; - - void GetConsoleDisplayModeImpl(ULONG& flags) noexcept override; - - [[nodiscard]] HRESULT AddConsoleAliasAImpl(const std::string_view source, - const std::string_view target, - const std::string_view exeName) noexcept override; - - [[nodiscard]] HRESULT AddConsoleAliasWImpl(const std::wstring_view source, - const std::wstring_view target, - const std::wstring_view exeName) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasAImpl(const std::string_view source, - std::span target, - size_t& written, - const std::string_view exeName) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasWImpl(const std::wstring_view source, - std::span target, - size_t& written, - const std::wstring_view exeName) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasesLengthAImpl(const std::string_view exeName, - size_t& bufferRequired) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasesLengthWImpl(const std::wstring_view exeName, - size_t& bufferRequired) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasExesLengthAImpl(size_t& bufferRequired) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasExesLengthWImpl(size_t& bufferRequired) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasesAImpl(const std::string_view exeName, - std::span alias, - size_t& written) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasesWImpl(const std::wstring_view exeName, - std::span alias, - size_t& written) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasExesAImpl(std::span aliasExes, - size_t& written) noexcept override; - - [[nodiscard]] HRESULT GetConsoleAliasExesWImpl(std::span aliasExes, - size_t& written) noexcept override; - -#pragma region CMDext Private API - - [[nodiscard]] HRESULT ExpungeConsoleCommandHistoryAImpl(const std::string_view exeName) noexcept override; - - [[nodiscard]] HRESULT ExpungeConsoleCommandHistoryWImpl(const std::wstring_view exeName) noexcept override; - - [[nodiscard]] HRESULT SetConsoleNumberOfCommandsAImpl(const std::string_view exeName, - const size_t numberOfCommands) noexcept override; - - [[nodiscard]] HRESULT SetConsoleNumberOfCommandsWImpl(const std::wstring_view exeName, - const size_t numberOfCommands) noexcept override; - - [[nodiscard]] HRESULT GetConsoleCommandHistoryLengthAImpl(const std::string_view exeName, - size_t& length) noexcept override; - - [[nodiscard]] HRESULT GetConsoleCommandHistoryLengthWImpl(const std::wstring_view exeName, - size_t& length) noexcept override; - - [[nodiscard]] HRESULT GetConsoleCommandHistoryAImpl(const std::string_view exeName, - std::span commandHistory, - size_t& written) noexcept override; - - [[nodiscard]] HRESULT GetConsoleCommandHistoryWImpl(const std::wstring_view exeName, - std::span commandHistory, - size_t& written) noexcept override; - -#pragma endregion - - void GetConsoleWindowImpl(HWND& hwnd) noexcept override; - - void GetConsoleSelectionInfoImpl(CONSOLE_SELECTION_INFO& consoleSelectionInfo) noexcept override; - - void GetConsoleHistoryInfoImpl(CONSOLE_HISTORY_INFO& consoleHistoryInfo) noexcept override; - - [[nodiscard]] HRESULT SetConsoleHistoryInfoImpl(const CONSOLE_HISTORY_INFO& consoleHistoryInfo) noexcept override; - - [[nodiscard]] HRESULT SetCurrentConsoleFontExImpl(IConsoleOutputObject& context, - const bool isForMaximumWindowSize, - const CONSOLE_FONT_INFOEX& consoleFontInfoEx) noexcept override; - -#pragma endregion - - IApiRoutines* m_pUsualRoutines; - UINT& m_inputCodepage; - UINT& m_outputCodepage; - ULONG m_inputMode; - ULONG m_outputMode; - bool m_listeningForDSR; - Microsoft::Console::Render::Xterm256Engine* m_pVtEngine; - -private: - void _SynchronizeCursor(std::unique_ptr& waiter) noexcept; -}; diff --git a/src/host/VtIo.cpp b/src/host/VtIo.cpp index dd8b635efd9..1bd2bb58a74 100644 --- a/src/host/VtIo.cpp +++ b/src/host/VtIo.cpp @@ -14,8 +14,6 @@ #include "input.h" // ProcessCtrlEvents #include "output.h" // CloseConsoleProcessState -#include "VtApiRoutines.h" - using namespace Microsoft::Console; using namespace Microsoft::Console::Render; using namespace Microsoft::Console::VirtualTerminal; @@ -156,65 +154,24 @@ VtIo::VtIo() : auto initialViewport = Viewport::FromDimensions({ 0, 0 }, gci.GetWindowSize().width, gci.GetWindowSize().height); - switch (_IoMode) - { - case VtIoMode::XTERM_256: - { - auto xterm256Engine = std::make_unique(std::move(_hOutput), - initialViewport); - if constexpr (Feature_VtPassthroughMode::IsEnabled()) - { - if (_passthroughMode) - { - auto vtapi = new VtApiRoutines(); - vtapi->m_pVtEngine = xterm256Engine.get(); - vtapi->m_pUsualRoutines = globals.api; - - xterm256Engine->SetPassthroughMode(true); - - if (_pVtInputThread) - { - auto pfnSetListenForDSR = std::bind(&VtInputThread::SetLookingForDSR, _pVtInputThread.get(), std::placeholders::_1); - xterm256Engine->SetLookingForDSRCallback(pfnSetListenForDSR); - } - - globals.api = vtapi; - } - } - _pVtRenderEngine = std::move(xterm256Engine); - break; - } - case VtIoMode::XTERM: + if (!Feature_VtPassthroughMode::IsEnabled() || !_passthroughMode) { - _pVtRenderEngine = std::make_unique(std::move(_hOutput), - initialViewport, - false); - if (_passthroughMode) + switch (_IoMode) { - return E_NOTIMPL; + case VtIoMode::XTERM_256: + _pVtRenderEngine = std::make_unique(std::move(_hOutput), initialViewport); + break; + case VtIoMode::XTERM: + _pVtRenderEngine = std::make_unique(std::move(_hOutput), initialViewport, false); + break; + case VtIoMode::XTERM_ASCII: + _pVtRenderEngine = std::make_unique(std::move(_hOutput), initialViewport, true); + break; + default: + return E_FAIL; } - break; - } - case VtIoMode::XTERM_ASCII: - { - _pVtRenderEngine = std::make_unique(std::move(_hOutput), - initialViewport, - true); - if (_passthroughMode) - { - return E_NOTIMPL; - } - break; - } - default: - { - return E_FAIL; - } - } - if (_pVtRenderEngine) - { _pVtRenderEngine->SetTerminalOwner(this); _pVtRenderEngine->SetResizeQuirk(_resizeQuirk); } @@ -230,6 +187,11 @@ bool VtIo::IsUsingVt() const return _initialized; } +PassthroughState* VtIo::GetPassthroughState() const noexcept +{ + return _passthroughState.get(); +} + // Routine Description: // Potentially starts this VtIo's input thread and render engine. // If the VtIo hasn't yet been given pipes, then this function will diff --git a/src/host/VtIo.hpp b/src/host/VtIo.hpp index 2ecc0d51754..c8e2388b1b7 100644 --- a/src/host/VtIo.hpp +++ b/src/host/VtIo.hpp @@ -7,6 +7,7 @@ #include "../renderer/vt/vtrenderer.hpp" #include "VtInputThread.hpp" #include "PtySignalInputThread.hpp" +#include "PassthroughState.h" class ConsoleArguments; @@ -28,6 +29,7 @@ namespace Microsoft::Console::VirtualTerminal [[nodiscard]] HRESULT CreateIoHandlers() noexcept; bool IsUsingVt() const; + PassthroughState* GetPassthroughState() const noexcept; [[nodiscard]] HRESULT StartIfNeeded(); @@ -69,7 +71,8 @@ namespace Microsoft::Console::VirtualTerminal bool _resizeQuirk{ false }; bool _passthroughMode{ false }; bool _closeEventSent{ false }; - + + std::unique_ptr _passthroughState; std::unique_ptr _pVtRenderEngine; std::unique_ptr _pVtInputThread; std::unique_ptr _pPtySignalInputThread; diff --git a/src/host/host-common.vcxitems b/src/host/host-common.vcxitems index ee482e31a93..2530d8e67fa 100644 --- a/src/host/host-common.vcxitems +++ b/src/host/host-common.vcxitems @@ -47,7 +47,6 @@ - @@ -101,7 +100,6 @@ - diff --git a/src/host/lib/hostlib.vcxproj b/src/host/lib/hostlib.vcxproj index 65fef3bffee..280fc3ff2e1 100644 --- a/src/host/lib/hostlib.vcxproj +++ b/src/host/lib/hostlib.vcxproj @@ -8,6 +8,12 @@ ConhostV2Lib StaticLibrary + + + + + + @@ -15,4 +21,4 @@ - + \ No newline at end of file diff --git a/src/host/lib/hostlib.vcxproj.filters b/src/host/lib/hostlib.vcxproj.filters index c108f2d1411..ef2341e2ec8 100644 --- a/src/host/lib/hostlib.vcxproj.filters +++ b/src/host/lib/hostlib.vcxproj.filters @@ -162,7 +162,7 @@ Source Files - + Source Files @@ -320,11 +320,12 @@ Header Files - + Header Files + - + \ No newline at end of file diff --git a/src/host/sources.inc b/src/host/sources.inc index e3a878161e0..b1d65b6f868 100644 --- a/src/host/sources.inc +++ b/src/host/sources.inc @@ -88,7 +88,6 @@ SOURCES = \ ..\conareainfo.cpp \ ..\conimeinfo.cpp \ ..\ConsoleArguments.cpp \ - ..\VtApiRoutines.cpp \ # ------------------------------------- diff --git a/src/renderer/vt/Xterm256Engine.cpp b/src/renderer/vt/Xterm256Engine.cpp index 7527db3dee7..eee293cdcb8 100644 --- a/src/renderer/vt/Xterm256Engine.cpp +++ b/src/renderer/vt/Xterm256Engine.cpp @@ -32,8 +32,6 @@ Xterm256Engine::Xterm256Engine(_In_ wil::unique_hfile hPipe, const bool usingSoftFont, const bool isSettingDefaultBrushes) noexcept { - RETURN_HR_IF(S_FALSE, _passthrough && isSettingDefaultBrushes); - RETURN_IF_FAILED(VtEngine::_RgbUpdateDrawingBrushes(textAttributes)); RETURN_IF_FAILED(_UpdateHyperlinkAttr(textAttributes, pData)); diff --git a/src/renderer/vt/Xterm256Engine.hpp b/src/renderer/vt/Xterm256Engine.hpp index 9d704c34dd8..5c8cde61831 100644 --- a/src/renderer/vt/Xterm256Engine.hpp +++ b/src/renderer/vt/Xterm256Engine.hpp @@ -18,8 +18,6 @@ Author(s): #include "XtermEngine.hpp" -class VtApiRoutines; - namespace Microsoft::Console::Render { class Xterm256Engine : public XtermEngine @@ -38,8 +36,6 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT ManuallyClearScrollback() noexcept override; - friend class ::VtApiRoutines; - private: [[nodiscard]] HRESULT _UpdateExtendedAttrs(const TextAttribute& textAttributes) noexcept; [[nodiscard]] HRESULT _UpdateHyperlinkAttr(const TextAttribute& textAttributes, diff --git a/src/renderer/vt/XtermEngine.cpp b/src/renderer/vt/XtermEngine.cpp index 14822351585..50ca98688eb 100644 --- a/src/renderer/vt/XtermEngine.cpp +++ b/src/renderer/vt/XtermEngine.cpp @@ -46,16 +46,6 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe, // during the frame. _nextCursorIsVisible = false; - // Do not perform synchronization clearing in passthrough mode. - // In passthrough, the terminal leads and we follow what it is - // handling from the client application. - // (This is in contrast to full PTY mode where WE, the ConPTY, lead and - // it follows our state.) - if (_passthrough) - { - _firstPaint = false; - } - if (_firstPaint) { // MSFT:17815688 diff --git a/src/renderer/vt/state.cpp b/src/renderer/vt/state.cpp index 8408ee3aeb6..3d79c1145d8 100644 --- a/src/renderer/vt/state.cpp +++ b/src/renderer/vt/state.cpp @@ -474,19 +474,6 @@ void VtEngine::SetResizeQuirk(const bool resizeQuirk) _resizeQuirk = resizeQuirk; } -// Method Description: -// - Configure the renderer to understand that we're operating in limited-draw -// passthrough mode. We do not need to handle full responsibility for replicating -// buffer state to the attached terminal. -// Arguments: -// - passthrough - True to turn on passthrough mode. False otherwise. -// Return Value: -// - true iff we were started with an output mode for passthrough. false otherwise. -void VtEngine::SetPassthroughMode(const bool passthrough) noexcept -{ - _passthrough = passthrough; -} - void VtEngine::SetLookingForDSRCallback(std::function pfnLooking) noexcept { _pfnSetLookingForDSR = pfnLooking; diff --git a/src/renderer/vt/vtrenderer.hpp b/src/renderer/vt/vtrenderer.hpp index 15de6e0e760..a651c1e9241 100644 --- a/src/renderer/vt/vtrenderer.hpp +++ b/src/renderer/vt/vtrenderer.hpp @@ -83,7 +83,6 @@ namespace Microsoft::Console::Render void BeginResizeRequest(); void EndResizeRequest(); void SetResizeQuirk(const bool resizeQuirk); - void SetPassthroughMode(const bool passthrough) noexcept; void SetLookingForDSRCallback(std::function pfnLooking) noexcept; void SetTerminalCursorTextPosition(const til::point coordCursor) noexcept; [[nodiscard]] virtual HRESULT ManuallyClearScrollback() noexcept; @@ -138,7 +137,6 @@ namespace Microsoft::Console::Render bool _delayedEolWrap{ false }; bool _resizeQuirk{ false }; - bool _passthrough{ false }; bool _corked{ false }; std::optional _newBottomLineBG{ std::nullopt };