Skip to content

Commit

Permalink
Get rid of unneeded terminal api methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
j4james committed May 2, 2022
1 parent 35d21d6 commit d3ce1a0
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 591 deletions.
14 changes: 8 additions & 6 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 @@ -240,8 +242,6 @@ HRESULT HwndTerminal::Initialize()
_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 +788,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
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,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
80 changes: 0 additions & 80 deletions src/cascadia/TerminalCore/ITerminalApi.hpp

This file was deleted.

30 changes: 30 additions & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ void Terminal::Create(COORD viewportSize, SHORT scrollbackLines, Renderer& rende
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); };

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

// Until we have a true pass-through mode (GH#1173), the decision as to
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
51 changes: 12 additions & 39 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "../../inc/DefaultSettings.h"
#include "../../buffer/out/textBuffer.hpp"
#include "../../types/inc/sgrStack.hpp"
#include "../../renderer/inc/IRenderData.hpp"
#include "../../terminal/adapter/ITerminalApi.hpp"
#include "../../terminal/parser/StateMachine.hpp"
Expand All @@ -16,7 +15,6 @@
#include "../../types/inc/Viewport.hpp"
#include "../../types/inc/GlyphWidth.hpp"
#include "../../types/IUiaData.h"
#include "../../cascadia/terminalcore/ITerminalApi.hpp"
#include "../../cascadia/terminalcore/ITerminalInput.hpp"

#include <til/ticket_lock.h>
Expand All @@ -34,6 +32,11 @@ namespace winrt::Microsoft::Terminal::Core
struct Scheme;
}

namespace Microsoft::Console::VirtualTerminal
{
class AdaptDispatch;
}

namespace Microsoft::Terminal::Core
{
class Terminal;
Expand All @@ -52,7 +55,6 @@ namespace TerminalCoreUnitTests

class Microsoft::Terminal::Core::Terminal final :
public Microsoft::Console::VirtualTerminal::ITerminalApi,
public Microsoft::Terminal::Core::ITerminalApi,
public Microsoft::Terminal::Core::ITerminalInput,
public Microsoft::Console::Render::IRenderData,
public Microsoft::Console::Types::IUiaData
Expand All @@ -77,6 +79,10 @@ class Microsoft::Terminal::Core::Terminal final :
void UpdateSettings(winrt::Microsoft::Terminal::Core::ICoreSettings settings);
void UpdateAppearance(const winrt::Microsoft::Terminal::Core::ICoreAppearance& appearance);
void SetFontInfo(const FontInfo& fontInfo);
void SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle);
void EraseScrollback();
bool IsXtermBracketedPasteModeEnabled() const;
std::wstring_view GetWorkingDirectory();

// Write comes from the PTY and goes to our parser to be stored in the output buffer
void Write(std::wstring_view stringView);
Expand All @@ -103,21 +109,9 @@ class Microsoft::Terminal::Core::Terminal final :
TextBuffer& GetTextBuffer() override;
til::rect GetViewport() const override;
void SetViewportPosition(const til::point position) override;
TextAttribute GetTextAttributes() const override;
void SetTextAttributes(const TextAttribute& attrs) override;
void SetAutoWrapMode(const bool wrapAtEOL) override;
void SetScrollingRegion(const til::inclusive_rect& scrollMargins) override;
Microsoft::Console::Types::Viewport GetBufferSize() override;
void SetCursorPosition(til::point pos) override;
til::point GetCursorPosition() override;
void SetCursorVisibility(const bool visible) override;
void EnableCursorBlinking(const bool enable) override;
void CursorLineFeed(const bool withReturn) override;
void DeleteCharacter(const til::CoordType count) override;
void InsertCharacter(const til::CoordType count) override;
void EraseCharacters(const til::CoordType numChars) override;
bool EraseInLine(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) override;
bool EraseInDisplay(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) override;
void WarningBell() override;
bool GetLineFeedMode() const override;
void LineFeed(const bool withReturn) override;
Expand All @@ -126,36 +120,15 @@ class Microsoft::Terminal::Core::Terminal final :
bool ResizeWindow(const size_t width, const size_t height) override;
void SetConsoleOutputCP(const unsigned int codepage) override;
unsigned int GetConsoleOutputCP() const override;
COLORREF GetColorTableEntry(const size_t tableIndex) const override;
void SetColorTableEntry(const size_t tableIndex, const COLORREF color) override;
void SetColorAliasIndex(const ColorAlias alias, const size_t tableIndex) override;
void SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) override;

void SetInputMode(const ::Microsoft::Console::VirtualTerminal::TerminalInput::Mode mode, const bool enabled) override;
void SetRenderMode(const ::Microsoft::Console::Render::RenderSettings::Mode mode, const bool enabled) override;

void EnableXtermBracketedPasteMode(const bool enabled) override;
bool IsXtermBracketedPasteModeEnabled() const override;

bool IsVtInputEnabled() const override;

void CopyToClipboard(std::wstring_view content) override;

void AddHyperlink(std::wstring_view uri, std::wstring_view params) override;
void EndHyperlink() override;

void SetTaskbarProgress(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState state, const size_t progress) override;
void SetWorkingDirectory(std::wstring_view uri) override;
std::wstring_view GetWorkingDirectory() override;

void PushGraphicsRendition(const ::Microsoft::Console::VirtualTerminal::VTParameters options) override;
void PopGraphicsRendition() override;

void ShowWindow(bool showOrHide) override;

void UseAlternateScreenBuffer() override;
void UseMainScreenBuffer() override;
bool IsConsolePty() const override;
bool IsVtInputEnabled() const override;
void NotifyAccessibilityChange(const til::rect& changedRect) override;
#pragma endregion

Expand Down Expand Up @@ -276,6 +249,8 @@ class Microsoft::Terminal::Core::Terminal final :
#pragma endregion

private:
std::function<void(::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle)> _pfnSetCursorStyle;
std::function<void()> _pfnEraseScrollback;
std::function<void(std::wstring_view)> _pfnWriteInput;
std::function<void()> _pfnWarningBell;
std::function<void(std::wstring_view)> _pfnTitleChanged;
Expand Down Expand Up @@ -418,8 +393,6 @@ class Microsoft::Terminal::Core::Terminal final :
void _MoveByBuffer(SelectionDirection direction, COORD& pos);
#pragma endregion

Microsoft::Console::VirtualTerminal::SgrStack _sgrStack;

#ifdef UNIT_TESTING
friend class TerminalCoreUnitTests::TerminalBufferTests;
friend class TerminalCoreUnitTests::TerminalApiTest;
Expand Down
Loading

0 comments on commit d3ce1a0

Please sign in to comment.