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

Merge the TerminalDispatch and AdaptDispatch classes #13024

Merged
17 commits merged into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion src/buffer/out/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ std::pair<COORD, COORD> Search::GetFoundLocation() const noexcept
// - direction - The intended direction of the search
// Return Value:
// - Coordinate to start the search from.
COORD Search::s_GetInitialAnchor(IUiaData& uiaData, const Direction direction)
COORD Search::s_GetInitialAnchor(const IUiaData& uiaData, const Direction direction)
{
const auto& textBuffer = uiaData.GetTextBuffer();
const auto textBufferEndPosition = uiaData.GetTextBufferEndPosition();
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/out/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Search final
void _IncrementCoord(COORD& coord) const noexcept;
void _DecrementCoord(COORD& coord) const noexcept;

static COORD s_GetInitialAnchor(Microsoft::Console::Types::IUiaData& uiaData, const Direction dir);
static COORD s_GetInitialAnchor(const Microsoft::Console::Types::IUiaData& uiaData, const Direction dir);

static std::vector<std::vector<wchar_t>> s_CreateNeedleFromString(const std::wstring& wstr);

Expand Down
16 changes: 8 additions & 8 deletions src/cascadia/PublicTerminalCore/HwndTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ HRESULT HwndTerminal::Initialize()
_terminal = std::make_unique<::Microsoft::Terminal::Core::Terminal>();
auto renderThread = std::make_unique<::Microsoft::Console::Render::RenderThread>();
auto* const localPointerToThread = renderThread.get();
const auto& renderSettings = _terminal->GetRenderSettings();
auto& renderSettings = _terminal->GetRenderSettings();
renderSettings.SetColorTableEntry(TextColor::DEFAULT_BACKGROUND, RGB(12, 12, 12));
renderSettings.SetColorTableEntry(TextColor::DEFAULT_FOREGROUND, RGB(204, 204, 204));
_renderer = std::make_unique<::Microsoft::Console::Render::Renderer>(renderSettings, _terminal.get(), nullptr, 0, std::move(renderThread));
RETURN_HR_IF_NULL(E_POINTER, localPointerToThread);
RETURN_IF_FAILED(localPointerToThread->Initialize(_renderer.get()));
Expand All @@ -237,11 +239,7 @@ HRESULT HwndTerminal::Initialize()

_renderEngine = std::move(dxEngine);

_terminal->SetBackgroundCallback([](auto) {});

_terminal->Create(COORD{ 80, 25 }, 1000, *_renderer);
_terminal->SetColorTableEntry(TextColor::DEFAULT_BACKGROUND, RGB(12, 12, 12));
_terminal->SetColorTableEntry(TextColor::DEFAULT_FOREGROUND, RGB(204, 204, 204));
_terminal->SetWriteInputCallback([=](std::wstring_view input) noexcept { _WriteTextToConnection(input); });
localPointerToThread->EnablePainting();

Expand Down Expand Up @@ -788,15 +786,17 @@ void _stdcall TerminalSetTheme(void* terminal, TerminalTheme theme, LPCWSTR font
{
auto lock = publicTerminal->_terminal->LockForWriting();

publicTerminal->_terminal->SetColorTableEntry(TextColor::DEFAULT_FOREGROUND, theme.DefaultForeground);
publicTerminal->_terminal->SetColorTableEntry(TextColor::DEFAULT_BACKGROUND, theme.DefaultBackground);
auto& renderSettings = publicTerminal->_terminal->GetRenderSettings();
renderSettings.SetColorTableEntry(TextColor::DEFAULT_FOREGROUND, theme.DefaultForeground);
renderSettings.SetColorTableEntry(TextColor::DEFAULT_BACKGROUND, theme.DefaultBackground);

publicTerminal->_renderEngine->SetSelectionBackground(theme.DefaultSelectionBackground, theme.SelectionBackgroundAlpha);

// Set the font colors
for (size_t tableIndex = 0; tableIndex < 16; tableIndex++)
{
// It's using gsl::at to check the index is in bounds, but the analyzer still calls this array-to-pointer-decay
[[gsl::suppress(bounds .3)]] publicTerminal->_terminal->SetColorTableEntry(tableIndex, gsl::at(theme.ColorTable, tableIndex));
[[gsl::suppress(bounds .3)]] renderSettings.SetColorTableEntry(tableIndex, gsl::at(theme.ColorTable, tableIndex));
}
}

Expand Down
30 changes: 9 additions & 21 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto pfnTabColorChanged = std::bind(&ControlCore::_terminalTabColorChanged, this, std::placeholders::_1);
_terminal->SetTabColorChangedCallback(pfnTabColorChanged);

auto pfnBackgroundColorChanged = std::bind(&ControlCore::_terminalBackgroundColorChanged, this, std::placeholders::_1);
_terminal->SetBackgroundCallback(pfnBackgroundColorChanged);

auto pfnScrollPositionChanged = std::bind(&ControlCore::_terminalScrollPositionChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
_terminal->SetScrollPositionChangedCallback(pfnScrollPositionChanged);

Expand Down Expand Up @@ -128,6 +125,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const auto& renderSettings = _terminal->GetRenderSettings();
_renderer = std::make_unique<::Microsoft::Console::Render::Renderer>(renderSettings, _terminal.get(), nullptr, 0, std::move(renderThread));

_renderer->SetBackgroundColorChangedCallback([this]() { _rendererBackgroundColorChanged(); });

_renderer->SetRendererEnteredErrorStateCallback([weakThis = get_weak()]() {
if (auto strongThis{ weakThis.get() })
{
Expand Down Expand Up @@ -1153,21 +1152,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_TabColorChangedHandlers(*this, nullptr);
}

// Method Description:
// - Called for the Terminal's BackgroundColorChanged callback. This will
// re-raise a new winrt TypedEvent that can be listened to.
// - The listeners to this event will re-query the control for the current
// value of BackgroundColor().
// Arguments:
// - <unused>
// Return Value:
// - <none>
void ControlCore::_terminalBackgroundColorChanged(const COLORREF /*color*/)
{
// Raise a BackgroundColorChanged event
_BackgroundColorChangedHandlers(*this, nullptr);
}

// Method Description:
// - Update the position and size of the scrollbar to match the given
// viewport top, viewport height, and buffer size.
Expand Down Expand Up @@ -1360,6 +1344,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_SwapChainChangedHandlers(*this, nullptr);
}

void ControlCore::_rendererBackgroundColorChanged()
{
_BackgroundColorChangedHandlers(*this, nullptr);
}

void ControlCore::BlinkAttributeTick()
{
auto lock = _terminal->LockForWriting();
Expand Down Expand Up @@ -1525,7 +1514,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
if (clearType == Control::ClearBufferType::Scrollback || clearType == Control::ClearBufferType::All)
{
_terminal->EraseInDisplay(::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType::Scrollback);
_terminal->EraseScrollback();
}

if (clearType == Control::ClearBufferType::Screen || clearType == Control::ClearBufferType::All)
Expand Down Expand Up @@ -1684,8 +1673,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

_renderEngine->SetSelectionBackground(til::color{ _settings->SelectionBackground() });

_renderer->TriggerRedrawAll();
_BackgroundColorChangedHandlers(*this, nullptr);
_renderer->TriggerRedrawAll(true);
}

bool ControlCore::HasUnfocusedAppearance() const
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void _terminalWarningBell();
void _terminalTitleChanged(std::wstring_view wstr);
void _terminalTabColorChanged(const std::optional<til::color> color);
void _terminalBackgroundColorChanged(const COLORREF color);
void _terminalScrollPositionChanged(const int viewTop,
const int viewHeight,
const int bufferSize);
Expand All @@ -277,6 +276,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
#pragma region RendererCallbacks
void _rendererWarning(const HRESULT hr);
void _renderEngineSwapChainChanged();
void _rendererBackgroundColorChanged();
#pragma endregion

void _raiseReadOnlyWarning();
Expand Down
80 changes: 0 additions & 80 deletions src/cascadia/TerminalCore/ITerminalApi.hpp

This file was deleted.

67 changes: 44 additions & 23 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "pch.h"
#include "Terminal.hpp"
#include "../../terminal/adapter/adaptDispatch.hpp"
#include "../../terminal/parser/OutputStateMachineEngine.hpp"
#include "TerminalDispatch.hpp"
#include "../../inc/unicode.hpp"
#include "../../types/inc/utils.hpp"
#include "../../types/inc/colorTable.hpp"
Expand Down Expand Up @@ -50,19 +50,6 @@ Terminal::Terminal() :
_taskbarProgress{ 0 },
_trimBlockSelection{ false }
{
auto dispatch = std::make_unique<TerminalDispatch>(*this);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));

_stateMachine = std::make_unique<StateMachine>(std::move(engine));

// Until we have a true pass-through mode (GH#1173), the decision as to
// whether C1 controls are interpreted or not is made at the conhost level.
// If they are being filtered out, then we will simply never receive them.
// But if they are being accepted by conhost, there's a chance they may get
// passed through in some situations, so it's important that our state
// machine is always prepared to accept them.
_stateMachine->SetParserMode(StateMachine::Mode::AcceptC1, true);

auto passAlongInput = [&](std::deque<std::unique_ptr<IInputEvent>>& inEventsToWrite) {
if (!_pfnWriteInput)
{
Expand All @@ -87,6 +74,23 @@ void Terminal::Create(COORD viewportSize, SHORT scrollbackLines, Renderer& rende
const TextAttribute attr{};
const UINT cursorSize = 12;
_mainBuffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, true, renderer);

auto dispatch = std::make_unique<AdaptDispatch>(*this, renderer, _renderSettings, *_terminalInput);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));

auto& dispatchRef = engine->Dispatch();
_pfnSetCursorStyle = [&](auto style) { dispatchRef.SetCursorStyle(style); };
_pfnEraseScrollback = [&]() { dispatchRef.EraseInDisplay(DispatchTypes::EraseType::Scrollback); };
j4james marked this conversation as resolved.
Show resolved Hide resolved

_stateMachine = std::make_unique<StateMachine>(std::move(engine));

// Until we have a true pass-through mode (GH#1173), the decision as to
// whether C1 controls are interpreted or not is made at the conhost level.
// If they are being filtered out, then we will simply never receive them.
// But if they are being accepted by conhost, there's a chance they may get
// passed through in some situations, so it's important that our state
// machine is always prepared to accept them.
_stateMachine->SetParserMode(StateMachine::Mode::AcceptC1, true);
}

// Method Description:
Expand Down Expand Up @@ -218,6 +222,32 @@ void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
_defaultCursorShape = cursorShape;
}

void Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle)
{
if (_pfnSetCursorStyle)
{
_pfnSetCursorStyle(cursorStyle);
}
}

void Terminal::EraseScrollback()
{
if (_pfnEraseScrollback)
{
_pfnEraseScrollback();
}
}

bool Terminal::IsXtermBracketedPasteModeEnabled() const
{
return _bracketedPasteMode;
}

std::wstring_view Terminal::GetWorkingDirectory()
{
return _workingDirectory;
}

// Method Description:
// - Resize the terminal as the result of some user interaction.
// Arguments:
Expand Down Expand Up @@ -1271,15 +1301,6 @@ void Terminal::SetCursorPositionChangedCallback(std::function<void()> pfn) noexc
_pfnCursorPositionChanged.swap(pfn);
}

// Method Description:
// - Allows setting a callback for when the background color is changed
// Arguments:
// - pfn: a function callback that takes a color
void Terminal::SetBackgroundCallback(std::function<void(const til::color)> pfn) noexcept
{
_pfnBackgroundColorChanged.swap(pfn);
}

// Method Description:
// - Allows settings a callback for settings the taskbar progress indicator
// Arguments:
Expand Down
Loading