diff --git a/src/cascadia/TerminalCore/ITerminalApi.hpp b/src/cascadia/TerminalCore/ITerminalApi.hpp index 7b9d4b1b63..ebff6fd207 100644 --- a/src/cascadia/TerminalCore/ITerminalApi.hpp +++ b/src/cascadia/TerminalCore/ITerminalApi.hpp @@ -20,7 +20,6 @@ namespace Microsoft::Terminal::Core ITerminalApi& operator=(ITerminalApi&&) = default; virtual void PrintString(std::wstring_view string) = 0; - virtual void ExecuteChar(wchar_t wch) = 0; virtual TextAttribute GetTextAttributes() const = 0; virtual void SetTextAttributes(const TextAttribute& attrs) = 0; diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index adec74b2e9..5a6d328ecf 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -96,7 +96,6 @@ public: #pragma region ITerminalApi // These methods are defined in TerminalApi.cpp void PrintString(std::wstring_view stringView) override; - void ExecuteChar(wchar_t wch) override; TextAttribute GetTextAttributes() const override; void SetTextAttributes(const TextAttribute& attrs) override; Microsoft::Console::Types::Viewport GetBufferSize() override; diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 4b516e9ee8..6e89bce460 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -16,11 +16,6 @@ void Terminal::PrintString(std::wstring_view stringView) _WriteBuffer(stringView); } -void Terminal::ExecuteChar(wchar_t wch) -{ - _WriteBuffer({ &wch, 1 }); -} - TextAttribute Terminal::GetTextAttributes() const { return _buffer->GetCurrentAttributes(); diff --git a/src/cascadia/TerminalCore/TerminalDispatch.cpp b/src/cascadia/TerminalCore/TerminalDispatch.cpp index 7984cc28c4..6adf0daed6 100644 --- a/src/cascadia/TerminalCore/TerminalDispatch.cpp +++ b/src/cascadia/TerminalCore/TerminalDispatch.cpp @@ -19,11 +19,6 @@ TerminalDispatch::TerminalDispatch(ITerminalApi& terminalApi) noexcept : { } -void TerminalDispatch::Execute(const wchar_t wchControl) -{ - _terminalApi.ExecuteChar(wchControl); -} - void TerminalDispatch::Print(const wchar_t wchPrintable) { _terminalApi.PrintString({ &wchPrintable, 1 }); diff --git a/src/cascadia/TerminalCore/TerminalDispatch.hpp b/src/cascadia/TerminalCore/TerminalDispatch.hpp index c4e7cf24f5..1ec29bf8e0 100644 --- a/src/cascadia/TerminalCore/TerminalDispatch.hpp +++ b/src/cascadia/TerminalCore/TerminalDispatch.hpp @@ -12,7 +12,6 @@ class TerminalDispatch : public Microsoft::Console::VirtualTerminal::TermDispatc public: TerminalDispatch(::Microsoft::Terminal::Core::ITerminalApi& terminalApi) noexcept; - void Execute(const wchar_t wchControl) override; void Print(const wchar_t wchPrintable) override; void PrintString(const std::wstring_view string) override; diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index 08a8c8020b..cbae451915 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -19,63 +19,18 @@ using Microsoft::Console::Interactivity::ServiceLocator; using Microsoft::Console::VirtualTerminal::StateMachine; using Microsoft::Console::VirtualTerminal::TerminalInput; -WriteBuffer::WriteBuffer(_In_ Microsoft::Console::IIoProvider& io) : - _io{ io }, - _ntstatus{ STATUS_INVALID_DEVICE_STATE } +ConhostInternalGetSet::ConhostInternalGetSet(_In_ IIoProvider& io) : + _io{ io } { } -// Routine Description: -// - Handles the print action from the state machine -// Arguments: -// - wch - The character to be printed. -// Return Value: -// - -void WriteBuffer::Print(const wchar_t wch) -{ - _DefaultCase(wch); -} - // Routine Description: // - Handles the print action from the state machine // Arguments: // - string - The string to be printed. // Return Value: // - -void WriteBuffer::PrintString(const std::wstring_view string) -{ - _DefaultStringCase(string); -} - -// Routine Description: -// - Handles the execute action from the state machine -// Arguments: -// - wch - The C0 control character to be executed. -// Return Value: -// - -void WriteBuffer::Execute(const wchar_t wch) -{ - _DefaultCase(wch); -} - -// Routine Description: -// - Default text editing/printing handler for all characters that were not routed elsewhere by other state machine intercepts. -// Arguments: -// - wch - The character to be processed by our default text editing/printing mechanisms. -// Return Value: -// - -void WriteBuffer::_DefaultCase(const wchar_t wch) -{ - _DefaultStringCase({ &wch, 1 }); -} - -// Routine Description: -// - Default text editing/printing handler for all characters that were not routed elsewhere by other state machine intercepts. -// Arguments: -// - string - The string to be processed by our default text editing/printing mechanisms. -// Return Value: -// - -void WriteBuffer::_DefaultStringCase(const std::wstring_view string) +void ConhostInternalGetSet::PrintString(const std::wstring_view string) { size_t dwNumBytes = string.size() * sizeof(wchar_t); @@ -88,21 +43,18 @@ void WriteBuffer::_DefaultStringCase(const std::wstring_view string) // Defer the cursor drawing while we are iterating the string, for a better performance. // We can not waste time displaying a cursor event when we know more text is coming right behind it. cursor.StartDeferDrawing(); - _ntstatus = WriteCharsLegacy(_io.GetActiveOutputBuffer(), - string.data(), - string.data(), - string.data(), - &dwNumBytes, - nullptr, - _io.GetActiveOutputBuffer().GetTextBuffer().GetCursor().GetPosition().X, - WC_LIMIT_BACKSPACE | WC_DELAY_EOL_WRAP, - nullptr); + const auto ntstatus = WriteCharsLegacy(_io.GetActiveOutputBuffer(), + string.data(), + string.data(), + string.data(), + &dwNumBytes, + nullptr, + _io.GetActiveOutputBuffer().GetTextBuffer().GetCursor().GetPosition().X, + WC_LIMIT_BACKSPACE | WC_DELAY_EOL_WRAP, + nullptr); cursor.EndDeferDrawing(); -} -ConhostInternalGetSet::ConhostInternalGetSet(_In_ IIoProvider& io) : - _io{ io } -{ + THROW_IF_NTSTATUS_FAILED(ntstatus); } // Routine Description: diff --git a/src/host/outputStream.hpp b/src/host/outputStream.hpp index 581730cf91..458e1ab550 100644 --- a/src/host/outputStream.hpp +++ b/src/host/outputStream.hpp @@ -14,36 +14,11 @@ Author: #pragma once -#include "../terminal/adapter/adaptDefaults.hpp" +#include "../terminal/adapter/conGetSet.hpp" #include "../types/inc/IInputEvent.hpp" #include "../inc/conattrs.hpp" #include "IIoProvider.hpp" -class SCREEN_INFORMATION; - -// The WriteBuffer class provides helpers for writing text into the TextBuffer that is backing a particular console screen buffer. -class WriteBuffer : public Microsoft::Console::VirtualTerminal::AdaptDefaults -{ -public: - WriteBuffer(_In_ Microsoft::Console::IIoProvider& io); - - // Implement Adapter callbacks for default cases (non-escape sequences) - void Print(const wchar_t wch) override; - void PrintString(const std::wstring_view string) override; - void Execute(const wchar_t wch) override; - - [[nodiscard]] NTSTATUS GetResult() { return _ntstatus; }; - -private: - void _DefaultCase(const wchar_t wch); - void _DefaultStringCase(const std::wstring_view string); - - Microsoft::Console::IIoProvider& _io; - NTSTATUS _ntstatus; -}; - -#include "../terminal/adapter/conGetSet.hpp" - // The ConhostInternalGetSet is for the Conhost process to call the entrypoints for its own Get/Set APIs. // Normally, these APIs are accessible from the outside of the conhost process (like by the process being "hosted") through // the kernelbase/32 exposed public APIs and routed by the console driver (condrv) to this console host. @@ -54,6 +29,8 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal:: public: ConhostInternalGetSet(_In_ Microsoft::Console::IIoProvider& io); + void PrintString(const std::wstring_view string) override; + void GetConsoleScreenBufferInfoEx(CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) const override; void SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) override; diff --git a/src/host/screenInfo.cpp b/src/host/screenInfo.cpp index ee72405103..f0f3e03710 100644 --- a/src/host/screenInfo.cpp +++ b/src/host/screenInfo.cpp @@ -255,8 +255,7 @@ void SCREEN_INFORMATION::s_RemoveScreenBuffer(_In_ SCREEN_INFORMATION* const pSc try { auto getset = std::make_unique(*this); - auto defaults = std::make_unique(*this); - auto adapter = std::make_unique(std::move(getset), std::move(defaults)); + auto adapter = std::make_unique(std::move(getset)); auto engine = std::make_unique(std::move(adapter)); // Note that at this point in the setup, we haven't determined if we're // in VtIo mode or not yet. We'll set the OutputStateMachine's diff --git a/src/terminal/adapter/ITermDispatch.hpp b/src/terminal/adapter/ITermDispatch.hpp index e1c7bfdebb..f0f48fa2d2 100644 --- a/src/terminal/adapter/ITermDispatch.hpp +++ b/src/terminal/adapter/ITermDispatch.hpp @@ -29,7 +29,6 @@ public: #pragma warning(disable : 26432) // suppress rule of 5 violation on interface because tampering with this is fraught with peril virtual ~ITermDispatch() = 0; - virtual void Execute(const wchar_t wchControl) = 0; virtual void Print(const wchar_t wchPrintable) = 0; virtual void PrintString(const std::wstring_view string) = 0; diff --git a/src/terminal/adapter/adaptDefaults.hpp b/src/terminal/adapter/adaptDefaults.hpp deleted file mode 100644 index 239c16d20c..0000000000 --- a/src/terminal/adapter/adaptDefaults.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/*++ -Copyright (c) Microsoft Corporation -Licensed under the MIT license. - -Module Name: -- adaptDefaults.hpp - -Abstract: -- This serves as an abstraction for the default cases in the state machine (which is to just print or execute a simple single character. -- This can also handle processing of an entire string of printable characters, as an optimization. -- When using the Windows Console API adapter (AdaptDispatch), this must be passed in to signify where standard actions should go. - -Author(s): -- Michael Niksa (MiNiksa) 30-July-2015 -- Mike Griese (migrie) 07-March-2016 ---*/ -#pragma once - -namespace Microsoft::Console::VirtualTerminal -{ - class AdaptDefaults - { - public: - virtual ~AdaptDefaults() = default; - virtual void Print(const wchar_t wch) = 0; - // These characters need to be mutable so that they can be processed by the TerminalInput translater. - virtual void PrintString(const std::wstring_view string) = 0; - virtual void Execute(const wchar_t wch) = 0; - }; -} diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index 6599914c5d..48d89483f0 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -26,17 +26,14 @@ bool NoOp() noexcept } // Note: AdaptDispatch will take ownership of pConApi and pDefaults -AdaptDispatch::AdaptDispatch(std::unique_ptr pConApi, - std::unique_ptr pDefaults) : +AdaptDispatch::AdaptDispatch(std::unique_ptr pConApi) : _pConApi{ std::move(pConApi) }, - _pDefaults{ std::move(pDefaults) }, _usingAltBuffer(false), _isOriginModeRelative(false), // by default, the DECOM origin mode is absolute. _isDECCOLMAllowed(false), // by default, DECCOLM is not allowed. _termOutput() { THROW_HR_IF_NULL(E_INVALIDARG, _pConApi.get()); - THROW_HR_IF_NULL(E_INVALIDARG, _pDefaults.get()); _scrollMargins = { 0 }; // initially, there are no scroll margins. } @@ -55,7 +52,7 @@ void AdaptDispatch::Print(const wchar_t wchPrintable) // a character is only output if the DEL is translated to something else. if (wchTranslated != AsciiChars::DEL) { - _pDefaults->Print(wchTranslated); + _pConApi->PrintString({ &wchTranslated, 1 }); } } @@ -76,11 +73,11 @@ void AdaptDispatch::PrintString(const std::wstring_view string) { buffer.push_back(_termOutput.TranslateKey(wch)); } - _pDefaults->PrintString(buffer); + _pConApi->PrintString(buffer); } else { - _pDefaults->PrintString(string); + _pConApi->PrintString(string); } } diff --git a/src/terminal/adapter/adaptDispatch.hpp b/src/terminal/adapter/adaptDispatch.hpp index fdd4834f2b..928a4dd2ac 100644 --- a/src/terminal/adapter/adaptDispatch.hpp +++ b/src/terminal/adapter/adaptDispatch.hpp @@ -16,7 +16,6 @@ Author(s): #include "termDispatch.hpp" #include "conGetSet.hpp" -#include "adaptDefaults.hpp" #include "FontBuffer.hpp" #include "terminalOutput.hpp" #include "..\..\types\inc\sgrStack.hpp" @@ -26,16 +25,10 @@ namespace Microsoft::Console::VirtualTerminal class AdaptDispatch : public ITermDispatch { public: - AdaptDispatch(std::unique_ptr pConApi, - std::unique_ptr pDefaults); + AdaptDispatch(std::unique_ptr pConApi); - void Execute(const wchar_t wchControl) override - { - _pDefaults->Execute(wchControl); - } - - void PrintString(const std::wstring_view string) override; void Print(const wchar_t wchPrintable) override; + void PrintString(const std::wstring_view string) override; bool CursorUp(const size_t distance) override; // CUU bool CursorDown(const size_t distance) override; // CUD @@ -199,7 +192,6 @@ namespace Microsoft::Console::VirtualTerminal bool _initDefaultTabStops = true; std::unique_ptr _pConApi; - std::unique_ptr _pDefaults; TerminalOutput _termOutput; std::unique_ptr _fontBuffer; std::optional _initialCodePage; diff --git a/src/terminal/adapter/conGetSet.hpp b/src/terminal/adapter/conGetSet.hpp index 5c9d90b11d..1cfe0d2613 100644 --- a/src/terminal/adapter/conGetSet.hpp +++ b/src/terminal/adapter/conGetSet.hpp @@ -34,6 +34,9 @@ namespace Microsoft::Console::VirtualTerminal public: virtual ~ConGetSet() = default; + + virtual void PrintString(const std::wstring_view string) = 0; + virtual void GetConsoleScreenBufferInfoEx(CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) const = 0; virtual void SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) = 0; virtual void SetCursorPosition(const COORD position) = 0; diff --git a/src/terminal/adapter/lib/adapter.vcxproj b/src/terminal/adapter/lib/adapter.vcxproj index 3879691792..6ec11be72a 100644 --- a/src/terminal/adapter/lib/adapter.vcxproj +++ b/src/terminal/adapter/lib/adapter.vcxproj @@ -22,7 +22,6 @@ - diff --git a/src/terminal/adapter/lib/adapter.vcxproj.filters b/src/terminal/adapter/lib/adapter.vcxproj.filters index 96f433000d..1f333e76af 100644 --- a/src/terminal/adapter/lib/adapter.vcxproj.filters +++ b/src/terminal/adapter/lib/adapter.vcxproj.filters @@ -41,9 +41,6 @@ - - Header Files - Header Files diff --git a/src/terminal/adapter/termDispatch.hpp b/src/terminal/adapter/termDispatch.hpp index 95170b5438..0d75258ed3 100644 --- a/src/terminal/adapter/termDispatch.hpp +++ b/src/terminal/adapter/termDispatch.hpp @@ -22,7 +22,6 @@ namespace Microsoft::Console::VirtualTerminal class Microsoft::Console::VirtualTerminal::TermDispatch : public Microsoft::Console::VirtualTerminal::ITermDispatch { public: - void Execute(const wchar_t wchControl) override = 0; void Print(const wchar_t wchPrintable) override = 0; void PrintString(const std::wstring_view string) override = 0; diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 97723dff54..f102b168e8 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -58,6 +58,10 @@ using namespace Microsoft::Console::VirtualTerminal; class TestGetSet final : public ConGetSet { public: + void PrintString(const std::wstring_view /*string*/) override + { + } + void GetConsoleScreenBufferInfoEx(CONSOLE_SCREEN_BUFFER_INFOEX& sbiex) const override { Log::Comment(L"GetConsoleScreenBufferInfoEx MOCK returning data..."); @@ -649,21 +653,6 @@ private: HANDLE _hCon; }; -class DummyAdapter : public AdaptDefaults -{ - void Print(const wchar_t /*wch*/) override - { - } - - void PrintString(const std::wstring_view /*string*/) override - { - } - - void Execute(const wchar_t /*wch*/) override - { - } -}; - class AdapterTest { public: @@ -677,11 +666,9 @@ public: fSuccess = api.get() != nullptr; if (fSuccess) { - auto adapter = std::make_unique(); - // give AdaptDispatch ownership of _testGetSet _testGetSet = api.get(); // keep a copy for us but don't manage its lifetime anymore. - _pDispatch = std::make_unique(std::move(api), std::move(adapter)); + _pDispatch = std::make_unique(std::move(api)); fSuccess = _pDispatch != nullptr; } return fSuccess; diff --git a/src/terminal/parser/ft_fuzzwrapper/echoDispatch.cpp b/src/terminal/parser/ft_fuzzwrapper/echoDispatch.cpp index a72c7b80fb..73099ddf2a 100644 --- a/src/terminal/parser/ft_fuzzwrapper/echoDispatch.cpp +++ b/src/terminal/parser/ft_fuzzwrapper/echoDispatch.cpp @@ -17,8 +17,3 @@ void EchoDispatch::PrintString(const std::wstring_view string) const std::wstring nullTermString(string); // string_view not guaranteed null terminated, but wprintf needs it. wprintf(L"PrintString: \"%s\" (%zd chars)\r\n", nullTermString.data(), nullTermString.size()); } - -void EchoDispatch::Execute(const wchar_t wchControl) -{ - wprintf(L"Execute: 0x%x\r\n", wchControl); -} diff --git a/src/terminal/parser/ft_fuzzwrapper/echoDispatch.hpp b/src/terminal/parser/ft_fuzzwrapper/echoDispatch.hpp index ac144a31ad..f026dfd237 100644 --- a/src/terminal/parser/ft_fuzzwrapper/echoDispatch.hpp +++ b/src/terminal/parser/ft_fuzzwrapper/echoDispatch.hpp @@ -14,7 +14,6 @@ namespace Microsoft public: void Print(const wchar_t wchPrintable) override; void PrintString(const std::wstring_view string) override; - void Execute(const wchar_t wchControl) override; }; } } diff --git a/src/terminal/parser/ut_parser/OutputEngineTest.cpp b/src/terminal/parser/ut_parser/OutputEngineTest.cpp index 83ba7dfc76..f45b68fde2 100644 --- a/src/terminal/parser/ut_parser/OutputEngineTest.cpp +++ b/src/terminal/parser/ut_parser/OutputEngineTest.cpp @@ -36,10 +36,6 @@ namespace Microsoft class DummyDispatch final : public TermDispatch { public: - virtual void Execute(const wchar_t /*wchControl*/) override - { - } - virtual void Print(const wchar_t /*wchPrintable*/) override { } @@ -986,10 +982,6 @@ class Microsoft::Console::VirtualTerminal::OutputEngineTest final class StatefulDispatch final : public TermDispatch { public: - virtual void Execute(const wchar_t /*wchControl*/) override - { - } - virtual void Print(const wchar_t wchPrintable) override { _printString += wchPrintable;