Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate the AdaptDefaults class #12390

Merged
5 commits merged into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/cascadia/TerminalCore/ITerminalApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Microsoft::Terminal::Core
ITerminalApi& operator=(ITerminalApi&&) = default;

virtual bool PrintString(std::wstring_view string) noexcept = 0;
virtual bool ExecuteChar(wchar_t wch) noexcept = 0;

virtual TextAttribute GetTextAttributes() const noexcept = 0;
virtual void SetTextAttributes(const TextAttribute& attrs) noexcept = 0;
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class Microsoft::Terminal::Core::Terminal final :
#pragma region ITerminalApi
// These methods are defined in TerminalApi.cpp
bool PrintString(std::wstring_view stringView) noexcept override;
bool ExecuteChar(wchar_t wch) noexcept override;
TextAttribute GetTextAttributes() const noexcept override;
void SetTextAttributes(const TextAttribute& attrs) noexcept override;
Microsoft::Console::Types::Viewport GetBufferSize() noexcept override;
Expand Down
8 changes: 0 additions & 8 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ try
}
CATCH_RETURN_FALSE()

bool Terminal::ExecuteChar(wchar_t wch) noexcept
try
{
_WriteBuffer({ &wch, 1 });
return true;
}
CATCH_RETURN_FALSE()

TextAttribute Terminal::GetTextAttributes() const noexcept
{
return _buffer->GetCurrentAttributes();
Expand Down
5 changes: 0 additions & 5 deletions src/cascadia/TerminalCore/TerminalDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ TerminalDispatch::TerminalDispatch(ITerminalApi& terminalApi) noexcept :
{
}

void TerminalDispatch::Execute(const wchar_t wchControl) noexcept
{
_terminalApi.ExecuteChar(wchControl);
}

void TerminalDispatch::Print(const wchar_t wchPrintable) noexcept
{
_terminalApi.PrintString({ &wchPrintable, 1 });
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalCore/TerminalDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) noexcept override;
void Print(const wchar_t wchPrintable) noexcept override;
void PrintString(const std::wstring_view string) noexcept override;

Expand Down
74 changes: 13 additions & 61 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,9 @@ 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 }
{
}

// Routine Description:
// - Handles the print action from the state machine
// Arguments:
// - wch - The character to be printed.
// Return Value:
// - <none>
void WriteBuffer::Print(const wchar_t wch)
ConhostInternalGetSet::ConhostInternalGetSet(_In_ IIoProvider& io) :
_io{ io }
{
_DefaultCase(wch);
}

// Routine Description:
Expand All @@ -42,40 +30,7 @@ void WriteBuffer::Print(const wchar_t wch)
// - string - The string to be printed.
// Return Value:
// - <none>
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:
// - <none>
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:
// - <none>
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:
// - <none>
void WriteBuffer::_DefaultStringCase(const std::wstring_view string)
void ConhostInternalGetSet::PrintString(const std::wstring_view string)
{
size_t dwNumBytes = string.size() * sizeof(wchar_t);

Expand All @@ -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:
Expand Down
29 changes: 3 additions & 26 deletions src/host/outputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,11 @@ Module Name:

#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.
Expand All @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ void SCREEN_INFORMATION::s_RemoveScreenBuffer(_In_ SCREEN_INFORMATION* const pSc
try
{
auto getset = std::make_unique<ConhostInternalGetSet>(*this);
auto defaults = std::make_unique<WriteBuffer>(*this);
auto adapter = std::make_unique<AdaptDispatch>(std::move(getset), std::move(defaults));
auto adapter = std::make_unique<AdaptDispatch>(std::move(getset));
auto engine = std::make_unique<OutputStateMachineEngine>(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
Expand Down
1 change: 0 additions & 1 deletion src/terminal/adapter/ITermDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch
#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;

Expand Down
30 changes: 0 additions & 30 deletions src/terminal/adapter/adaptDefaults.hpp

This file was deleted.

11 changes: 4 additions & 7 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ bool NoOp() noexcept
}

// Note: AdaptDispatch will take ownership of pConApi and pDefaults
AdaptDispatch::AdaptDispatch(std::unique_ptr<ConGetSet> pConApi,
std::unique_ptr<AdaptDefaults> pDefaults) :
AdaptDispatch::AdaptDispatch(std::unique_ptr<ConGetSet> 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.
}

Expand All @@ -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 });
}
}

Expand All @@ -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);
}
}

Expand Down
12 changes: 2 additions & 10 deletions src/terminal/adapter/adaptDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Author(s):
#include "termDispatch.hpp"
#include "DispatchCommon.hpp"
#include "conGetSet.hpp"
#include "adaptDefaults.hpp"
#include "FontBuffer.hpp"
#include "terminalOutput.hpp"
#include "..\..\types\inc\sgrStack.hpp"
Expand All @@ -27,16 +26,10 @@ namespace Microsoft::Console::VirtualTerminal
class AdaptDispatch : public ITermDispatch
{
public:
AdaptDispatch(std::unique_ptr<ConGetSet> pConApi,
std::unique_ptr<AdaptDefaults> pDefaults);
AdaptDispatch(std::unique_ptr<ConGetSet> 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
Expand Down Expand Up @@ -200,7 +193,6 @@ namespace Microsoft::Console::VirtualTerminal
bool _initDefaultTabStops = true;

std::unique_ptr<ConGetSet> _pConApi;
std::unique_ptr<AdaptDefaults> _pDefaults;
TerminalOutput _termOutput;
std::unique_ptr<FontBuffer> _fontBuffer;
std::optional<unsigned int> _initialCodePage;
Expand Down
3 changes: 3 additions & 0 deletions src/terminal/adapter/conGetSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/terminal/adapter/lib/adapter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\adaptDefaults.hpp" />
<ClInclude Include="..\adaptDispatch.hpp" />
<ClInclude Include="..\charsets.hpp" />
<ClInclude Include="..\DispatchTypes.hpp" />
Expand Down
3 changes: 0 additions & 3 deletions src/terminal/adapter/lib/adapter.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\adaptDefaults.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\adaptDispatch.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
1 change: 0 additions & 1 deletion src/terminal/adapter/termDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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;

Expand Down
Loading