From bd58211f6f65f492bc2afacd434a934effd98842 Mon Sep 17 00:00:00 2001 From: James Holderness Date: Sun, 1 May 2022 16:56:15 +0100 Subject: [PATCH] Get rid of unneeded terminal api methods. --- .../PublicTerminalCore/HwndTerminal.cpp | 14 +- src/cascadia/TerminalControl/ControlCore.cpp | 2 +- src/cascadia/TerminalCore/ITerminalApi.hpp | 80 --- src/cascadia/TerminalCore/Terminal.cpp | 30 ++ src/cascadia/TerminalCore/Terminal.hpp | 51 +- src/cascadia/TerminalCore/TerminalApi.cpp | 475 +----------------- .../TerminalCore/terminalcore-common.vcxitems | 1 - 7 files changed, 62 insertions(+), 591 deletions(-) delete mode 100644 src/cascadia/TerminalCore/ITerminalApi.hpp diff --git a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp index 3dd7bfc0563..67a678d2a9d 100644 --- a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp +++ b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp @@ -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())); @@ -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(); @@ -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)); } } diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 616914bc462..4243fb12f86 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -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) diff --git a/src/cascadia/TerminalCore/ITerminalApi.hpp b/src/cascadia/TerminalCore/ITerminalApi.hpp deleted file mode 100644 index 6561eb62ed2..00000000000 --- a/src/cascadia/TerminalCore/ITerminalApi.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -#pragma once - -#include "../../terminal/adapter/DispatchTypes.hpp" -#include "../../terminal/input/terminalInput.hpp" -#include "../../buffer/out/TextAttribute.hpp" -#include "../../renderer/inc/RenderSettings.hpp" -#include "../../types/inc/Viewport.hpp" - -namespace Microsoft::Terminal::Core -{ - class ITerminalApi - { - public: - virtual ~ITerminalApi() {} - ITerminalApi(const ITerminalApi&) = default; - ITerminalApi(ITerminalApi&&) = default; - ITerminalApi& operator=(const ITerminalApi&) = default; - ITerminalApi& operator=(ITerminalApi&&) = default; - - virtual void PrintString(std::wstring_view string) = 0; - - virtual void ReturnResponse(std::wstring_view responseString) = 0; - - virtual TextAttribute GetTextAttributes() const = 0; - virtual void SetTextAttributes(const TextAttribute& attrs) = 0; - - virtual Microsoft::Console::Types::Viewport GetBufferSize() = 0; - virtual void SetCursorPosition(til::point pos) = 0; - virtual til::point GetCursorPosition() = 0; - virtual void SetCursorVisibility(const bool visible) = 0; - virtual void CursorLineFeed(const bool withReturn) = 0; - virtual void EnableCursorBlinking(const bool enable) = 0; - - virtual void DeleteCharacter(const til::CoordType count) = 0; - virtual void InsertCharacter(const til::CoordType count) = 0; - virtual void EraseCharacters(const til::CoordType numChars) = 0; - virtual bool EraseInLine(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) = 0; - virtual bool EraseInDisplay(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) = 0; - - virtual void WarningBell() = 0; - virtual void SetWindowTitle(std::wstring_view title) = 0; - - virtual COLORREF GetColorTableEntry(const size_t tableIndex) const = 0; - virtual void SetColorTableEntry(const size_t tableIndex, const COLORREF color) = 0; - virtual void SetColorAliasIndex(const ColorAlias alias, const size_t tableIndex) = 0; - - virtual void SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) = 0; - - virtual void SetInputMode(const ::Microsoft::Console::VirtualTerminal::TerminalInput::Mode mode, const bool enabled) = 0; - virtual void SetRenderMode(const ::Microsoft::Console::Render::RenderSettings::Mode mode, const bool enabled) = 0; - - virtual void EnableXtermBracketedPasteMode(const bool enabled) = 0; - virtual bool IsXtermBracketedPasteModeEnabled() const = 0; - - virtual bool IsVtInputEnabled() const = 0; - - virtual void CopyToClipboard(std::wstring_view content) = 0; - - virtual void AddHyperlink(std::wstring_view uri, std::wstring_view params) = 0; - virtual void EndHyperlink() = 0; - - virtual void SetTaskbarProgress(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState state, const size_t progress) = 0; - - virtual void SetWorkingDirectory(std::wstring_view uri) = 0; - virtual std::wstring_view GetWorkingDirectory() = 0; - - virtual void PushGraphicsRendition(const ::Microsoft::Console::VirtualTerminal::VTParameters options) = 0; - virtual void PopGraphicsRendition() = 0; - - virtual void ShowWindow(bool showOrHide) = 0; - - virtual void UseAlternateScreenBuffer() = 0; - virtual void UseMainScreenBuffer() = 0; - - protected: - ITerminalApi() = default; - }; -} diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 5fc8322eb82..2b5151bd7ae 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -78,6 +78,10 @@ void Terminal::Create(COORD viewportSize, SHORT scrollbackLines, Renderer& rende auto dispatch = std::make_unique(*this, renderer, _renderSettings, *_terminalInput); auto engine = std::make_unique(std::move(dispatch)); + auto& dispatchRef = engine->Dispatch(); + _pfnSetCursorStyle = [&](auto style) { dispatchRef.SetCursorStyle(style); }; + _pfnEraseScrollback = [&]() { dispatchRef.EraseInDisplay(DispatchTypes::EraseType::Scrollback); }; + _stateMachine = std::make_unique(std::move(engine)); // Until we have a true pass-through mode (GH#1173), the decision as to @@ -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: diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index e2171dbc825..1cefa176676 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -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" @@ -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 @@ -34,6 +32,11 @@ namespace winrt::Microsoft::Terminal::Core struct Scheme; } +namespace Microsoft::Console::VirtualTerminal +{ + class AdaptDispatch; +} + namespace Microsoft::Terminal::Core { class Terminal; @@ -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 @@ -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); @@ -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; @@ -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 @@ -276,6 +249,8 @@ class Microsoft::Terminal::Core::Terminal final : #pragma endregion private: + std::function _pfnSetCursorStyle; + std::function _pfnEraseScrollback; std::function _pfnWriteInput; std::function _pfnWarningBell; std::function _pfnTitleChanged; @@ -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; diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index ad59c3eda32..c8af8f07b2b 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -16,11 +16,6 @@ void Terminal::PrintString(const std::wstring_view string) _WriteBuffer(string); } -TextAttribute Terminal::GetTextAttributes() const -{ - return _activeBuffer().GetCurrentAttributes(); -} - void Terminal::ReturnResponse(const std::wstring_view response) { if (_pfnWriteInput) @@ -66,36 +61,18 @@ void Terminal::SetScrollingRegion(const til::inclusive_rect& /*scrollMargins*/) // TODO: This will be needed to fully support DECSTBM. } -Viewport Terminal::GetBufferSize() -{ - return _activeBuffer().GetSize(); -} - -void Terminal::SetCursorPosition(til::point pos) +void Terminal::WarningBell() { - const auto viewport = _GetMutableViewport(); - const til::point viewOrigin{ viewport.Origin() }; - auto newPos = til::unwrap_coord(viewOrigin + pos); - viewport.Clamp(newPos); - _activeBuffer().GetCursor().SetPosition(newPos); + _pfnWarningBell(); } -til::point Terminal::GetCursorPosition() +bool Terminal::GetLineFeedMode() const { - const til::point absoluteCursorPos{ _activeBuffer().GetCursor().GetPosition() }; - const auto viewport = _GetMutableViewport(); - const til::point viewOrigin{ viewport.Origin() }; - // TODO assert that the coord is > (0, 0) && <(view.W, view.H) - return absoluteCursorPos - viewOrigin; + // TODO: This will be needed to support LNM. + return false; } -// Method Description: -// - Moves the cursor down one line, and possibly also to the leftmost column. -// Arguments: -// - withReturn, set to true if a carriage return should be performed as well. -// Return value: -// - -void Terminal::CursorLineFeed(const bool withReturn) +void Terminal::LineFeed(const bool withReturn) { auto cursorPos = _activeBuffer().GetCursor().GetPosition(); @@ -111,247 +88,6 @@ void Terminal::CursorLineFeed(const bool withReturn) _AdjustCursorPosition(cursorPos); } -// Method Description: -// - deletes count characters starting from the cursor's current position -// - it moves over the remaining text to 'replace' the deleted text -// - for example, if the buffer looks like this ('|' is the cursor): [abc|def] -// - calling DeleteCharacter(1) will change it to: [abc|ef], -// - i.e. the 'd' gets deleted and the 'ef' gets shifted over 1 space and **retain their previous text attributes** -// Arguments: -// - count, the number of characters to delete -// Return value: -// - -void Terminal::DeleteCharacter(const til::CoordType count) -{ - const auto cursorPos = _activeBuffer().GetCursor().GetPosition(); - const auto copyToPos = cursorPos; - const til::point copyFromPos{ cursorPos.X + count, cursorPos.Y }; - const auto viewport = _GetMutableViewport(); - - const auto sourceWidth = viewport.RightExclusive() - copyFromPos.X; - - // Get a rectangle of the source - auto source = Viewport::FromDimensions(til::unwrap_coord(copyFromPos), gsl::narrow(sourceWidth), 1); - - // Get a rectangle of the target - const auto target = Viewport::FromDimensions(copyToPos, source.Dimensions()); - const auto walkDirection = Viewport::DetermineWalkDirection(source, target); - - auto sourcePos = source.GetWalkOrigin(walkDirection); - auto targetPos = target.GetWalkOrigin(walkDirection); - - // Iterate over the source cell data and copy it over to the target - do - { - const auto data = OutputCell(*(_activeBuffer().GetCellDataAt(sourcePos))); - _activeBuffer().Write(OutputCellIterator({ &data, 1 }), targetPos); - } while (source.WalkInBounds(sourcePos, walkDirection) && target.WalkInBounds(targetPos, walkDirection)); -} - -// Method Description: -// - Inserts count spaces starting from the cursor's current position, moving over the existing text -// - for example, if the buffer looks like this ('|' is the cursor): [abc|def] -// - calling InsertCharacter(1) will change it to: [abc| def], -// - i.e. the 'def' gets shifted over 1 space and **retain their previous text attributes** -// Arguments: -// - count, the number of spaces to insert -// Return value: -// - -void Terminal::InsertCharacter(const til::CoordType count) -{ - // NOTE: the code below is _extremely_ similar to DeleteCharacter - // We will want to use this same logic and implement a helper function instead - // that does the 'move a region from here to there' operation - // TODO: GitHub issue #2163 - const auto cursorPos = _activeBuffer().GetCursor().GetPosition(); - const auto copyFromPos = cursorPos; - const til::point copyToPos{ cursorPos.X + count, cursorPos.Y }; - const auto viewport = _GetMutableViewport(); - const auto sourceWidth = viewport.RightExclusive() - copyFromPos.X; - - // Get a rectangle of the source - auto source = Viewport::FromDimensions(copyFromPos, gsl::narrow(sourceWidth), 1); - - // Get a rectangle of the target - const auto target = Viewport::FromDimensions(til::unwrap_coord(copyToPos), source.Dimensions()); - const auto walkDirection = Viewport::DetermineWalkDirection(source, target); - - auto sourcePos = source.GetWalkOrigin(walkDirection); - auto targetPos = target.GetWalkOrigin(walkDirection); - - // Iterate over the source cell data and copy it over to the target - do - { - const auto data = OutputCell(*(_activeBuffer().GetCellDataAt(sourcePos))); - _activeBuffer().Write(OutputCellIterator({ &data, 1 }), targetPos); - } while (source.WalkInBounds(sourcePos, walkDirection) && target.WalkInBounds(targetPos, walkDirection)); - const auto eraseIter = OutputCellIterator(UNICODE_SPACE, _activeBuffer().GetCurrentAttributes(), count); - _activeBuffer().Write(eraseIter, cursorPos); -} - -void Terminal::EraseCharacters(const til::CoordType numChars) -{ - const auto absoluteCursorPos = _activeBuffer().GetCursor().GetPosition(); - const auto viewport = _GetMutableViewport(); - const auto distanceToRight = viewport.RightExclusive() - absoluteCursorPos.X; - const auto fillLimit = std::min(numChars, distanceToRight); - const auto eraseIter = OutputCellIterator(UNICODE_SPACE, _activeBuffer().GetCurrentAttributes(), fillLimit); - _activeBuffer().Write(eraseIter, absoluteCursorPos); -} - -// Method description: -// - erases a line of text, either from -// 1. beginning to the cursor's position -// 2. cursor's position to end -// 3. beginning to end -// - depending on the erase type -// Arguments: -// - the erase type -// Return value: -// - true if succeeded, false otherwise -bool Terminal::EraseInLine(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) -{ - const auto cursorPos = _activeBuffer().GetCursor().GetPosition(); - const auto viewport = _GetMutableViewport(); - til::point startPos; - startPos.Y = cursorPos.Y; - // nlength determines the number of spaces we need to write - DWORD nlength = 0; - - // Determine startPos.X and nlength by the eraseType - switch (eraseType) - { - case DispatchTypes::EraseType::FromBeginning: - nlength = cursorPos.X - viewport.Left() + 1; - break; - case DispatchTypes::EraseType::ToEnd: - startPos.X = cursorPos.X; - nlength = viewport.RightExclusive() - startPos.X; - break; - case DispatchTypes::EraseType::All: - startPos.X = viewport.Left(); - nlength = viewport.RightExclusive() - startPos.X; - break; - default: - return false; - } - - const auto eraseIter = OutputCellIterator(UNICODE_SPACE, _activeBuffer().GetCurrentAttributes(), nlength); - - // Explicitly turn off end-of-line wrap-flag-setting when erasing cells. - _activeBuffer().Write(eraseIter, til::unwrap_coord(startPos), false); - return true; -} - -// Method description: -// - erases text in the buffer in two ways depending on erase type -// 1. 'erases' all text visible to the user (i.e. the text in the viewport) -// 2. erases all the text in the scrollback -// Arguments: -// - the erase type -// Return Value: -// - true if succeeded, false otherwise -bool Terminal::EraseInDisplay(const DispatchTypes::EraseType eraseType) -{ - // Store the relative cursor position so we can restore it later after we move the viewport - const auto cursorPos = _activeBuffer().GetCursor().GetPosition(); -#pragma warning(suppress : 26496) // This is written by ConvertToOrigin, cpp core checks is wrong saying it should be const. - auto relativeCursor = cursorPos; - const auto viewport = _GetMutableViewport(); - - viewport.ConvertToOrigin(&relativeCursor); - - // Initialize the new location of the viewport - // the top and bottom parameters are determined by the eraseType - SMALL_RECT newWin; - newWin.Left = viewport.Left(); - newWin.Right = viewport.RightExclusive(); - - if (eraseType == DispatchTypes::EraseType::All) - { - // If we're in the alt buffer, take a shortcut. Just increment the buffer enough to cycle the whole thing out and start fresh. This - if (_inAltBuffer()) - { - for (auto i = 0; i < viewport.Height(); i++) - { - _activeBuffer().IncrementCircularBuffer(); - } - return true; - } - // In this case, we simply move the viewport down, effectively pushing whatever text was on the screen into the scrollback - // and thus 'erasing' the text visible to the user - const auto coordLastChar = _activeBuffer().GetLastNonSpaceCharacter(viewport); - if (coordLastChar.X == 0 && coordLastChar.Y == 0) - { - // Nothing to clear, just return - return true; - } - - short sNewTop = coordLastChar.Y + 1; - - // Increment the circular buffer only if the new location of the viewport would be 'below' the buffer - const auto delta = (sNewTop + viewport.Height()) - (_activeBuffer().GetSize().Height()); - for (auto i = 0; i < delta; i++) - { - _activeBuffer().IncrementCircularBuffer(); - sNewTop--; - } - - newWin.Top = sNewTop; - newWin.Bottom = sNewTop + viewport.Height(); - } - else if (eraseType == DispatchTypes::EraseType::Scrollback) - { - // We only want to erase the scrollback, and leave everything else on the screen as it is - // so we grab the text in the viewport and rotate it up to the top of the buffer - COORD scrollFromPos{ 0, 0 }; - viewport.ConvertFromOrigin(&scrollFromPos); - _activeBuffer().ScrollRows(scrollFromPos.Y, viewport.Height(), -scrollFromPos.Y); - - // Since we only did a rotation, the text that was in the scrollback is now _below_ where we are going to move the viewport - // and we have to make sure we erase that text - const auto eraseStart = viewport.Height(); - const auto eraseEnd = _activeBuffer().GetLastNonSpaceCharacter(viewport).Y; - for (auto i = eraseStart; i <= eraseEnd; i++) - { - _activeBuffer().GetRowByOffset(i).Reset(_activeBuffer().GetCurrentAttributes()); - } - - // Reset the scroll offset now because there's nothing for the user to 'scroll' to - _scrollOffset = 0; - - newWin.Top = 0; - newWin.Bottom = viewport.Height(); - } - else - { - return false; - } - - // Move the viewport, adjust the scroll bar if needed, and restore the old cursor position - _mutableViewport = Viewport::FromExclusive(newWin); - Terminal::_NotifyScrollEvent(); - SetCursorPosition(til::point{ relativeCursor }); - - return true; -} - -void Terminal::WarningBell() -{ - _pfnWarningBell(); -} - -bool Terminal::GetLineFeedMode() const -{ - // TODO: This will be needed to support LNM. - return false; -} - -void Terminal::LineFeed(const bool withReturn) -{ - CursorLineFeed(withReturn); -} - void Terminal::SetWindowTitle(const std::wstring_view title) { if (!_suppressApplicationTitle) @@ -383,179 +119,16 @@ unsigned int Terminal::GetConsoleOutputCP() const return CP_UTF8; } -// Method Description: -// - Retrieves the value in the colortable at the specified index. -// Arguments: -// - tableIndex: the index of the color table to retrieve. -// Return Value: -// - the COLORREF value for the color at that index in the table. -COLORREF Terminal::GetColorTableEntry(const size_t tableIndex) const -{ - return _renderSettings.GetColorTableEntry(tableIndex); -} - -// Method Description: -// - Updates the value in the colortable at index tableIndex to the new color -// color. color is a COLORREF, format 0x00BBGGRR. -// Arguments: -// - tableIndex: the index of the color table to update. -// - color: the new COLORREF to use as that color table value. -// Return Value: -// - -void Terminal::SetColorTableEntry(const size_t tableIndex, const COLORREF color) -{ - _renderSettings.SetColorTableEntry(tableIndex, color); - - if (tableIndex == _renderSettings.GetColorAliasIndex(ColorAlias::DefaultBackground)) - { - _pfnBackgroundColorChanged(color); - } - - // Repaint everything - the colors might have changed - _activeBuffer().TriggerRedrawAll(); -} - -// Method Description: -// - Sets the position in the color table for the given color alias. -// Arguments: -// - alias: the color alias to update. -// - tableIndex: the new position of the alias in the color table. -// Return Value: -// - -void Terminal::SetColorAliasIndex(const ColorAlias alias, const size_t tableIndex) -{ - _renderSettings.SetColorAliasIndex(alias, tableIndex); -} - -// Method Description: -// - Sets the cursor style to the given style. -// Arguments: -// - cursorStyle: the style to be set for the cursor -// Return Value: -// - -void Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) -{ - auto finalCursorType = CursorType::Legacy; - auto shouldBlink = false; - - switch (cursorStyle) - { - case DispatchTypes::CursorStyle::UserDefault: - finalCursorType = _defaultCursorShape; - shouldBlink = true; - break; - case DispatchTypes::CursorStyle::BlinkingBlock: - finalCursorType = CursorType::FullBox; - shouldBlink = true; - break; - case DispatchTypes::CursorStyle::SteadyBlock: - finalCursorType = CursorType::FullBox; - shouldBlink = false; - break; - case DispatchTypes::CursorStyle::BlinkingUnderline: - finalCursorType = CursorType::Underscore; - shouldBlink = true; - break; - case DispatchTypes::CursorStyle::SteadyUnderline: - finalCursorType = CursorType::Underscore; - shouldBlink = false; - break; - case DispatchTypes::CursorStyle::BlinkingBar: - finalCursorType = CursorType::VerticalBar; - shouldBlink = true; - break; - case DispatchTypes::CursorStyle::SteadyBar: - finalCursorType = CursorType::VerticalBar; - shouldBlink = false; - break; - - default: - // Invalid argument should be ignored. - return; - } - - _activeBuffer().GetCursor().SetType(finalCursorType); - _activeBuffer().GetCursor().SetBlinkingAllowed(shouldBlink); -} - -void Terminal::SetInputMode(const TerminalInput::Mode mode, const bool enabled) -{ - _terminalInput->SetInputMode(mode, enabled); -} - -void Terminal::SetRenderMode(const RenderSettings::Mode mode, const bool enabled) -{ - _renderSettings.SetRenderMode(mode, enabled); - - // Repaint everything - the colors will have changed - _activeBuffer().TriggerRedrawAll(); -} - void Terminal::EnableXtermBracketedPasteMode(const bool enabled) { _bracketedPasteMode = enabled; } -bool Terminal::IsXtermBracketedPasteModeEnabled() const -{ - return _bracketedPasteMode; -} - -bool Terminal::IsVtInputEnabled() const -{ - return false; -} - -void Terminal::SetCursorVisibility(const bool visible) -{ - _activeBuffer().GetCursor().SetIsVisible(visible); -} - -void Terminal::EnableCursorBlinking(const bool enable) -{ - _activeBuffer().GetCursor().SetBlinkingAllowed(enable); - - // GH#2642 - From what we've gathered from other terminals, when blinking is - // disabled, the cursor should remain On always, and have the visibility - // controlled by the IsVisible property. So when you do a printf "\e[?12l" - // to disable blinking, the cursor stays stuck On. At this point, only the - // cursor visibility property controls whether the user can see it or not. - // (Yes, the cursor can be On and NOT Visible) - _activeBuffer().GetCursor().SetIsOn(true); -} - void Terminal::CopyToClipboard(std::wstring_view content) { _pfnCopyToClipboard(content); } -// Method Description: -// - Updates the buffer's current text attributes to start a hyperlink -// Arguments: -// - The hyperlink URI -// - The customID provided (if there was one) -// Return Value: -// - -void Terminal::AddHyperlink(std::wstring_view uri, std::wstring_view params) -{ - auto attr = _activeBuffer().GetCurrentAttributes(); - const auto id = _activeBuffer().GetHyperlinkId(uri, params); - attr.SetHyperlinkId(id); - _activeBuffer().SetCurrentAttributes(attr); - _activeBuffer().AddHyperlinkToMap(uri, id); -} - -// Method Description: -// - Updates the buffer's current text attributes to end a hyperlink -// Return Value: -// - -void Terminal::EndHyperlink() -{ - auto attr = _activeBuffer().GetCurrentAttributes(); - attr.SetHyperlinkId(0); - _activeBuffer().SetCurrentAttributes(attr); -} - // Method Description: // - Updates the taskbar progress indicator // Arguments: @@ -611,37 +184,6 @@ void Terminal::SetWorkingDirectory(std::wstring_view uri) _workingDirectory = uri; } -std::wstring_view Terminal::GetWorkingDirectory() -{ - return _workingDirectory; -} - -// Method Description: -// - Saves the current text attributes to an internal stack. -// Arguments: -// - options, cOptions: if present, specify which portions of the current text attributes -// should be saved. Only a small subset of GraphicsOptions are actually supported; -// others are ignored. If no options are specified, all attributes are stored. -// Return Value: -// - -void Terminal::PushGraphicsRendition(const VTParameters options) -{ - _sgrStack.Push(_activeBuffer().GetCurrentAttributes(), options); -} - -// Method Description: -// - Restores text attributes from the internal stack. If only portions of text attributes -// were saved, combines those with the current attributes. -// Arguments: -// - -// Return Value: -// - -void Terminal::PopGraphicsRendition() -{ - const auto current = _activeBuffer().GetCurrentAttributes(); - _activeBuffer().SetCurrentAttributes(_sgrStack.Pop(current)); -} - void Terminal::UseAlternateScreenBuffer() { // the new alt buffer is exactly the size of the viewport. @@ -766,6 +308,11 @@ bool Terminal::IsConsolePty() const return false; } +bool Terminal::IsVtInputEnabled() const +{ + return false; +} + void Terminal::NotifyAccessibilityChange(const til::rect& /*changedRect*/) { // This is only needed in conhost. Terminal handles accessibility in another way. diff --git a/src/cascadia/TerminalCore/terminalcore-common.vcxitems b/src/cascadia/TerminalCore/terminalcore-common.vcxitems index 809aae0d703..7feb43f7d5d 100644 --- a/src/cascadia/TerminalCore/terminalcore-common.vcxitems +++ b/src/cascadia/TerminalCore/terminalcore-common.vcxitems @@ -13,7 +13,6 @@ -