From c1e40bc04dccd6275fa51f95c15f9a5a942f915a Mon Sep 17 00:00:00 2001 From: Tushar Singh Date: Sun, 25 Jun 2023 12:58:45 +0530 Subject: [PATCH 1/3] add support for SGR 58/59 (underline coloring) in `--headless` mode --- src/buffer/out/TextAttribute.cpp | 34 +- src/buffer/out/TextAttribute.hpp | 10 + src/renderer/vt/Xterm256Engine.cpp | 70 ++ src/renderer/vt/Xterm256Engine.hpp | 4 + src/terminal/adapter/DispatchTypes.hpp | 9 + src/terminal/adapter/adaptDispatch.hpp | 620 +++++++++--------- .../adapter/adaptDispatchGraphics.cpp | 44 +- 7 files changed, 469 insertions(+), 322 deletions(-) diff --git a/src/buffer/out/TextAttribute.cpp b/src/buffer/out/TextAttribute.cpp index 55e3b15a5ea..ee694260df2 100644 --- a/src/buffer/out/TextAttribute.cpp +++ b/src/buffer/out/TextAttribute.cpp @@ -7,7 +7,7 @@ // Keeping TextColor compact helps us keeping TextAttribute compact, // which in turn ensures that our buffer memory usage is low. -static_assert(sizeof(TextAttribute) == 12); +static_assert(sizeof(TextAttribute) == 16); static_assert(alignof(TextAttribute) == 2); // Ensure that we can memcpy() and memmove() the struct for performance. static_assert(std::is_trivially_copyable_v); @@ -147,6 +147,11 @@ TextColor TextAttribute::GetBackground() const noexcept return _background; } +TextColor TextAttribute::GetUnderlineColor() const noexcept +{ + return _underlineColor; +} + // Method description: // - Retrieves the hyperlink ID of the text // Return value: @@ -166,6 +171,11 @@ void TextAttribute::SetBackground(const TextColor background) noexcept _background = background; } +void TextAttribute::SetUnderlineColor(const TextColor color) noexcept +{ + _underlineColor = color; +} + void TextAttribute::SetForeground(const COLORREF rgbForeground) noexcept { _foreground = TextColor(rgbForeground); @@ -176,6 +186,11 @@ void TextAttribute::SetBackground(const COLORREF rgbBackground) noexcept _background = TextColor(rgbBackground); } +void TextAttribute::SetUnderlineColor(const COLORREF rgbColor) noexcept +{ + _underlineColor = TextColor(rgbColor); +} + void TextAttribute::SetIndexedForeground(const BYTE fgIndex) noexcept { _foreground = TextColor(fgIndex, false); @@ -186,6 +201,13 @@ void TextAttribute::SetIndexedBackground(const BYTE bgIndex) noexcept _background = TextColor(bgIndex, false); } +// Method description: +// - No-op, underlines only support index256 and rgb coloring schemes. +// Arguments: +// - cIndex - index16 based color index. +void TextAttribute::SetIndexedUnderlineColor(const BYTE /*cIndex*/) noexcept +{} + void TextAttribute::SetIndexedForeground256(const BYTE fgIndex) noexcept { _foreground = TextColor(fgIndex, true); @@ -196,6 +218,11 @@ void TextAttribute::SetIndexedBackground256(const BYTE bgIndex) noexcept _background = TextColor(bgIndex, true); } +void TextAttribute::SetIndexedUnderlineColor256(const BYTE cIndex) noexcept +{ + _underlineColor = TextColor(cIndex, true); +} + void TextAttribute::SetColor(const COLORREF rgbColor, const bool fIsForeground) noexcept { if (fIsForeground) @@ -374,6 +401,11 @@ void TextAttribute::SetDefaultBackground() noexcept _background = TextColor(); } +void TextAttribute::SetDefaultUnderlineColor() noexcept +{ + _underlineColor = TextColor(); +} + // Method description: // - Resets only the rendition character attributes, which includes everything // except the Protected attribute. diff --git a/src/buffer/out/TextAttribute.hpp b/src/buffer/out/TextAttribute.hpp index 2a61e8902de..da05bb4102a 100644 --- a/src/buffer/out/TextAttribute.hpp +++ b/src/buffer/out/TextAttribute.hpp @@ -34,6 +34,7 @@ class TextAttribute final _attrs{ CharacterAttributes::Normal }, _foreground{}, _background{}, + _underlineColor{}, _hyperlinkId{ 0 } { } @@ -42,6 +43,7 @@ class TextAttribute final _attrs{ gsl::narrow_cast(wLegacyAttr & USED_META_ATTRS) }, _foreground{ gsl::at(s_legacyForegroundColorMap, wLegacyAttr & FG_ATTRS) }, _background{ gsl::at(s_legacyBackgroundColorMap, (wLegacyAttr & BG_ATTRS) >> 4) }, + _underlineColor{}, _hyperlinkId{ 0 } { } @@ -51,6 +53,7 @@ class TextAttribute final _attrs{ CharacterAttributes::Normal }, _foreground{ rgbForeground }, _background{ rgbBackground }, + _underlineColor{}, _hyperlinkId{ 0 } { } @@ -117,20 +120,26 @@ class TextAttribute final TextColor GetForeground() const noexcept; TextColor GetBackground() const noexcept; + TextColor GetUnderlineColor() const noexcept; uint16_t GetHyperlinkId() const noexcept; void SetForeground(const TextColor foreground) noexcept; void SetBackground(const TextColor background) noexcept; + void SetUnderlineColor(const TextColor color) noexcept; void SetForeground(const COLORREF rgbForeground) noexcept; void SetBackground(const COLORREF rgbBackground) noexcept; + void SetUnderlineColor(const COLORREF rgbColor) noexcept; void SetIndexedForeground(const BYTE fgIndex) noexcept; void SetIndexedBackground(const BYTE bgIndex) noexcept; + void SetIndexedUnderlineColor(const BYTE /*cIndex*/) noexcept; void SetIndexedForeground256(const BYTE fgIndex) noexcept; void SetIndexedBackground256(const BYTE bgIndex) noexcept; + void SetIndexedUnderlineColor256(const BYTE cIndex) noexcept; void SetColor(const COLORREF rgbColor, const bool fIsForeground) noexcept; void SetHyperlinkId(uint16_t id) noexcept; void SetDefaultForeground() noexcept; void SetDefaultBackground() noexcept; + void SetDefaultUnderlineColor() noexcept; void SetDefaultRenditionAttributes() noexcept; bool BackgroundIsDefault() const noexcept; @@ -175,6 +184,7 @@ class TextAttribute final uint16_t _hyperlinkId; // sizeof: 2, alignof: 2 TextColor _foreground; // sizeof: 4, alignof: 1 TextColor _background; // sizeof: 4, alignof: 1 + TextColor _underlineColor; // sizeof: 4, alignof: 1 #ifdef UNIT_TESTING friend class TextBufferTests; diff --git a/src/renderer/vt/Xterm256Engine.cpp b/src/renderer/vt/Xterm256Engine.cpp index dc506322ccf..65672666e12 100644 --- a/src/renderer/vt/Xterm256Engine.cpp +++ b/src/renderer/vt/Xterm256Engine.cpp @@ -103,6 +103,7 @@ Xterm256Engine::Xterm256Engine(_In_ wil::unique_hfile hPipe, RETURN_IF_FAILED(_SetUnderlined(true)); _lastTextAttributes.SetUnderlined(true); } + if (textAttributes.IsDoublyUnderlined() && !_lastTextAttributes.IsDoublyUnderlined()) { RETURN_IF_FAILED(_SetDoublyUnderlined(true)); @@ -144,10 +145,79 @@ Xterm256Engine::Xterm256Engine(_In_ wil::unique_hfile hPipe, RETURN_IF_FAILED(_SetReverseVideo(textAttributes.IsReverseVideo())); _lastTextAttributes.SetReverseVideo(textAttributes.IsReverseVideo()); } + + // Update underline color. + if (textAttributes.GetUnderlineColor() != _lastTextAttributes.GetUnderlineColor()) + { + RETURN_IF_FAILED(_RgbUpdateUnderlineDrawingBrushes(textAttributes.GetUnderlineColor())); + _lastTextAttributes.SetUnderlineColor(textAttributes.GetUnderlineColor()); + } + + return S_OK; +} +// Routine Description: +// - Write a VT sequence to change the current color for underlines. Writes true RGB +// color sequences. +// Arguments: +// - ulColor: Underline color which needs to be applied. +// Return Value: +// - S_OK if we succeeded, else an appropriate HRESULT for failing to allocate or write. +[[nodiscard]] HRESULT Xterm256Engine::_RgbUpdateUnderlineDrawingBrushes(const TextColor ulColor) noexcept +{ + if (ulColor.IsDefault()) + { + RETURN_IF_FAILED(_UnderlineDefaultColor()); + } + // index16 isn't supported. + else if (ulColor.IsIndex16()) + { + return S_FALSE; + } + else if (ulColor.IsIndex256()) + { + RETURN_IF_FAILED(_Underline256Color(ulColor.GetIndex())); + } + else if (ulColor.IsRgb()) + { + RETURN_IF_FAILED(_UnderlineRGBColor(ulColor.GetRGB())); + } return S_OK; } +// Method Description: +// - Formats and writes a sequence to change the current underline color to an +// indexed color from the 256-color table. +// Arguments: +// - index: color table index to emit as a VT sequence +// Return Value: +// - S_OK if we succeeded, else an appropriate HRESULT for failing to allocate or write. +[[nodiscard]] HRESULT Xterm256Engine::_Underline256Color(const BYTE index) noexcept +{ + return _WriteFormatted(FMT_COMPILE("\x1b[58;5;{}m"), index); +} + +// Method Description: +// - Formats and writes a sequence to change the current underline color to an +// RGB color. +// Arguments: +// - color: The color to emit a VT sequence for. +// Return Value: +// - S_OK if we succeeded, else an appropriate HRESULT for failing to allocate or write. +[[nodiscard]] HRESULT Xterm256Engine::_UnderlineRGBColor(const COLORREF color) noexcept +{ + const auto r = GetRValue(color); + const auto g = GetGValue(color); + const auto b = GetBValue(color); + return _WriteFormatted(FMT_COMPILE("\x1b[58;2;{};{};{}m"), r, g, b); +} + + +[[nodiscard]] HRESULT Xterm256Engine::_UnderlineDefaultColor() noexcept +{ + return _Write("\x1b[59m"); +} + // Routine Description: // - Write a VT sequence to start/stop a hyperlink // Arguments: diff --git a/src/renderer/vt/Xterm256Engine.hpp b/src/renderer/vt/Xterm256Engine.hpp index 9d704c34dd8..4e40f9cef42 100644 --- a/src/renderer/vt/Xterm256Engine.hpp +++ b/src/renderer/vt/Xterm256Engine.hpp @@ -41,6 +41,10 @@ namespace Microsoft::Console::Render friend class ::VtApiRoutines; private: + [[nodiscard]] HRESULT _Underline256Color(const BYTE index) noexcept; + [[nodiscard]] HRESULT _UnderlineRGBColor(const COLORREF color) noexcept; + [[nodiscard]] HRESULT _UnderlineDefaultColor() noexcept; + [[nodiscard]] HRESULT _RgbUpdateUnderlineDrawingBrushes(const TextColor ulColor) noexcept; [[nodiscard]] HRESULT _UpdateExtendedAttrs(const TextAttribute& textAttributes) noexcept; [[nodiscard]] HRESULT _UpdateHyperlinkAttr(const TextAttribute& textAttributes, const gsl::not_null pData) noexcept; diff --git a/src/terminal/adapter/DispatchTypes.hpp b/src/terminal/adapter/DispatchTypes.hpp index 9e342ec5f80..877716010dc 100644 --- a/src/terminal/adapter/DispatchTypes.hpp +++ b/src/terminal/adapter/DispatchTypes.hpp @@ -341,6 +341,8 @@ namespace Microsoft::Console::VirtualTerminal::DispatchTypes BackgroundDefault = 49, Overline = 53, NoOverline = 55, + UnderlineColor = 58, + UnderlineColorDefault = 59, BrightForegroundBlack = 90, BrightForegroundRed = 91, BrightForegroundGreen = 92, @@ -366,6 +368,13 @@ namespace Microsoft::Console::VirtualTerminal::DispatchTypes Unprotected = 2 }; + enum class TextProp : VTInt + { + Foreground = 0, + Background = 1, + Underline = 2 + }; + // Many of these correspond directly to SGR parameters (the GraphicsOptions enum), but // these are distinct (notably 10 and 11, which as SGR parameters would select fonts, // are used here to indicate that the foreground/background colors should be saved). diff --git a/src/terminal/adapter/adaptDispatch.hpp b/src/terminal/adapter/adaptDispatch.hpp index 674cafc4506..d7ed862b415 100644 --- a/src/terminal/adapter/adaptDispatch.hpp +++ b/src/terminal/adapter/adaptDispatch.hpp @@ -1,310 +1,310 @@ -/*++ -Copyright (c) Microsoft Corporation -Licensed under the MIT license. - -Module Name: -- adaptDispatch.hpp - -Abstract: -- This serves as the Windows Console API-specific implementation of the callbacks from our generic Virtual Terminal parser. - -Author(s): -- Michael Niksa (MiNiksa) 30-July-2015 ---*/ - -#pragma once - -#include "termDispatch.hpp" -#include "ITerminalApi.hpp" -#include "FontBuffer.hpp" -#include "MacroBuffer.hpp" -#include "terminalOutput.hpp" -#include "../input/terminalInput.hpp" -#include "../../types/inc/sgrStack.hpp" - -// fwdecl unittest classes -#ifdef UNIT_TESTING -class AdapterTest; -#endif - -namespace Microsoft::Console::VirtualTerminal -{ - class AdaptDispatch : public ITermDispatch - { - using Renderer = Microsoft::Console::Render::Renderer; - using RenderSettings = Microsoft::Console::Render::RenderSettings; - - public: - AdaptDispatch(ITerminalApi& api, Renderer& renderer, RenderSettings& renderSettings, TerminalInput& terminalInput); - - void Print(const wchar_t wchPrintable) override; - void PrintString(const std::wstring_view string) override; - - bool CursorUp(const VTInt distance) override; // CUU - bool CursorDown(const VTInt distance) override; // CUD - bool CursorForward(const VTInt distance) override; // CUF - bool CursorBackward(const VTInt distance) override; // CUB, BS - bool CursorNextLine(const VTInt distance) override; // CNL - bool CursorPrevLine(const VTInt distance) override; // CPL - bool CursorHorizontalPositionAbsolute(const VTInt column) override; // HPA, CHA - bool VerticalLinePositionAbsolute(const VTInt line) override; // VPA - bool HorizontalPositionRelative(const VTInt distance) override; // HPR - bool VerticalPositionRelative(const VTInt distance) override; // VPR - bool CursorPosition(const VTInt line, const VTInt column) override; // CUP, HVP - bool CursorSaveState() override; // DECSC - bool CursorRestoreState() override; // DECRC - bool EraseInDisplay(const DispatchTypes::EraseType eraseType) override; // ED - bool EraseInLine(const DispatchTypes::EraseType eraseType) override; // EL - bool EraseCharacters(const VTInt numChars) override; // ECH - bool SelectiveEraseInDisplay(const DispatchTypes::EraseType eraseType) override; // DECSED - bool SelectiveEraseInLine(const DispatchTypes::EraseType eraseType) override; // DECSEL - bool InsertCharacter(const VTInt count) override; // ICH - bool DeleteCharacter(const VTInt count) override; // DCH - bool ChangeAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECCARA - bool ReverseAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECRARA - bool CopyRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTInt page, const VTInt dstTop, const VTInt dstLeft, const VTInt dstPage) override; // DECCRA - bool FillRectangularArea(const VTParameter ch, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECFRA - bool EraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECERA - bool SelectiveEraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECSERA - bool SelectAttributeChangeExtent(const DispatchTypes::ChangeExtent changeExtent) noexcept override; // DECSACE - bool RequestChecksumRectangularArea(const VTInt id, const VTInt page, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECRQCRA - bool SetGraphicsRendition(const VTParameters options) override; // SGR - bool SetLineRendition(const LineRendition rendition) override; // DECSWL, DECDWL, DECDHL - bool SetCharacterProtectionAttribute(const VTParameters options) override; // DECSCA - bool PushGraphicsRendition(const VTParameters options) override; // XTPUSHSGR - bool PopGraphicsRendition() override; // XTPOPSGR - bool DeviceStatusReport(const DispatchTypes::StatusType statusType, const VTParameter id) override; // DSR - bool DeviceAttributes() override; // DA1 - bool SecondaryDeviceAttributes() override; // DA2 - bool TertiaryDeviceAttributes() override; // DA3 - bool Vt52DeviceAttributes() override; // VT52 Identify - bool RequestTerminalParameters(const DispatchTypes::ReportingPermission permission) override; // DECREQTPARM - bool ScrollUp(const VTInt distance) override; // SU - bool ScrollDown(const VTInt distance) override; // SD - bool InsertLine(const VTInt distance) override; // IL - bool DeleteLine(const VTInt distance) override; // DL - bool InsertColumn(const VTInt distance) override; // DECIC - bool DeleteColumn(const VTInt distance) override; // DECDC - bool SetMode(const DispatchTypes::ModeParams param) override; // SM, DECSET - bool ResetMode(const DispatchTypes::ModeParams param) override; // RM, DECRST - bool RequestMode(const DispatchTypes::ModeParams param) override; // DECRQM - bool SetKeypadMode(const bool applicationMode) override; // DECKPAM, DECKPNM - bool SetAnsiMode(const bool ansiMode) override; // DECANM - bool SetTopBottomScrollingMargins(const VTInt topMargin, - const VTInt bottomMargin) override; // DECSTBM - bool SetLeftRightScrollingMargins(const VTInt leftMargin, - const VTInt rightMargin) override; // DECSLRM - bool WarningBell() override; // BEL - bool CarriageReturn() override; // CR - bool LineFeed(const DispatchTypes::LineFeedType lineFeedType) override; // IND, NEL, LF, FF, VT - bool ReverseLineFeed() override; // RI - bool BackIndex() override; // DECBI - bool ForwardIndex() override; // DECFI - bool SetWindowTitle(const std::wstring_view title) override; // OSCWindowTitle - bool HorizontalTabSet() override; // HTS - bool ForwardTab(const VTInt numTabs) override; // CHT, HT - bool BackwardsTab(const VTInt numTabs) override; // CBT - bool TabClear(const DispatchTypes::TabClearType clearType) override; // TBC - bool DesignateCodingSystem(const VTID codingSystem) override; // DOCS - bool Designate94Charset(const VTInt gsetNumber, const VTID charset) override; // SCS - bool Designate96Charset(const VTInt gsetNumber, const VTID charset) override; // SCS - bool LockingShift(const VTInt gsetNumber) override; // LS0, LS1, LS2, LS3 - bool LockingShiftRight(const VTInt gsetNumber) override; // LS1R, LS2R, LS3R - bool SingleShift(const VTInt gsetNumber) noexcept override; // SS2, SS3 - bool AcceptC1Controls(const bool enabled) override; // DECAC1 - bool SoftReset() override; // DECSTR - bool HardReset() override; // RIS - bool ScreenAlignmentPattern() override; // DECALN - bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) override; // DECSCUSR - bool SetCursorColor(const COLORREF cursorColor) override; - - bool SetClipboard(const std::wstring_view content) override; // OSCSetClipboard - - bool SetColorTableEntry(const size_t tableIndex, - const DWORD color) override; // OSCColorTable - bool SetDefaultForeground(const DWORD color) override; // OSCDefaultForeground - bool SetDefaultBackground(const DWORD color) override; // OSCDefaultBackground - bool AssignColor(const DispatchTypes::ColorItem item, const VTInt fgIndex, const VTInt bgIndex) override; // DECAC - - bool WindowManipulation(const DispatchTypes::WindowManipulationType function, - const VTParameter parameter1, - const VTParameter parameter2) override; // DTTERM_WindowManipulation - - bool AddHyperlink(const std::wstring_view uri, const std::wstring_view params) override; - bool EndHyperlink() override; - - bool DoConEmuAction(const std::wstring_view string) override; - - bool DoITerm2Action(const std::wstring_view string) override; - - bool DoFinalTermAction(const std::wstring_view string) override; - - StringHandler DownloadDRCS(const VTInt fontNumber, - const VTParameter startChar, - const DispatchTypes::DrcsEraseControl eraseControl, - const DispatchTypes::DrcsCellMatrix cellMatrix, - const DispatchTypes::DrcsFontSet fontSet, - const DispatchTypes::DrcsFontUsage fontUsage, - const VTParameter cellHeight, - const DispatchTypes::DrcsCharsetSize charsetSize) override; // DECDLD - - StringHandler DefineMacro(const VTInt macroId, - const DispatchTypes::MacroDeleteControl deleteControl, - const DispatchTypes::MacroEncoding encoding) override; // DECDMAC - bool InvokeMacro(const VTInt macroId) override; // DECINVM - - StringHandler RestoreTerminalState(const DispatchTypes::ReportFormat format) override; // DECRSTS - - StringHandler RequestSetting() override; // DECRQSS - - bool RequestPresentationStateReport(const DispatchTypes::PresentationReportFormat format) override; // DECRQPSR - StringHandler RestorePresentationState(const DispatchTypes::PresentationReportFormat format) override; // DECRSPS - - bool PlaySounds(const VTParameters parameters) override; // DECPS - - private: - enum class Mode - { - InsertReplace, - Origin, - Column, - AllowDECCOLM, - AllowDECSLRM, - EraseColor, - RectangularChangeExtent - }; - enum class ScrollDirection - { - Up, - Down - }; - struct CursorState - { - VTInt Row = 1; - VTInt Column = 1; - bool IsDelayedEOLWrap = false; - bool IsOriginModeRelative = false; - TextAttribute Attributes = {}; - TerminalOutput TermOutput = {}; - bool C1ControlsAccepted = false; - unsigned int CodePage = 0; - }; - struct Offset - { - VTInt Value; - bool IsAbsolute; - // VT origin is at 1,1 so we need to subtract 1 from absolute positions. - static constexpr Offset Absolute(const VTInt value) { return { value - 1, true }; }; - static constexpr Offset Forward(const VTInt value) { return { value, false }; }; - static constexpr Offset Backward(const VTInt value) { return { -value, false }; }; - static constexpr Offset Unchanged() { return Forward(0); }; - }; - struct ChangeOps - { - CharacterAttributes andAttrMask = CharacterAttributes::All; - CharacterAttributes xorAttrMask = CharacterAttributes::Normal; - std::optional foreground; - std::optional background; - }; - - void _WriteToBuffer(const std::wstring_view string); - std::pair _GetVerticalMargins(const til::rect& viewport, const bool absolute) noexcept; - std::pair _GetHorizontalMargins(const til::CoordType bufferWidth) noexcept; - bool _CursorMovePosition(const Offset rowOffset, const Offset colOffset, const bool clampInMargins); - void _ApplyCursorMovementFlags(Cursor& cursor) noexcept; - void _FillRect(TextBuffer& textBuffer, const til::rect& fillRect, const std::wstring_view& fillChar, const TextAttribute& fillAttrs) const; - void _SelectiveEraseRect(TextBuffer& textBuffer, const til::rect& eraseRect); - void _ChangeRectAttributes(TextBuffer& textBuffer, const til::rect& changeRect, const ChangeOps& changeOps); - void _ChangeRectOrStreamAttributes(const til::rect& changeArea, const ChangeOps& changeOps); - til::rect _CalculateRectArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const til::size bufferSize); - bool _EraseScrollback(); - bool _EraseAll(); - TextAttribute _GetEraseAttributes(const TextBuffer& textBuffer) const noexcept; - void _ScrollRectVertically(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); - void _ScrollRectHorizontally(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); - void _InsertDeleteCharacterHelper(const VTInt delta); - void _InsertDeleteLineHelper(const VTInt delta); - void _InsertDeleteColumnHelper(const VTInt delta); - void _ScrollMovement(const VTInt delta); - - void _DoSetTopBottomScrollingMargins(const VTInt topMargin, - const VTInt bottomMargin, - const bool homeCursor = false); - void _DoSetLeftRightScrollingMargins(const VTInt leftMargin, - const VTInt rightMargin, - const bool homeCursor = false); - - void _DoLineFeed(TextBuffer& textBuffer, const bool withReturn, const bool wrapForced); - - void _OperatingStatus() const; - void _CursorPositionReport(const bool extendedReport); - void _MacroSpaceReport() const; - void _MacroChecksumReport(const VTParameter id) const; - - void _SetColumnMode(const bool enable); - void _SetAlternateScreenBufferMode(const bool enable); - bool _PassThroughInputModes(); - bool _ModeParamsHelper(const DispatchTypes::ModeParams param, const bool enable); - - void _ClearSingleTabStop(); - void _ClearAllTabStops() noexcept; - void _ResetTabStops() noexcept; - void _InitTabStopsForWidth(const VTInt width); - - StringHandler _RestoreColorTable(); - - void _ReportSGRSetting() const; - void _ReportDECSTBMSetting(); - void _ReportDECSLRMSetting(); - void _ReportDECSCASetting() const; - void _ReportDECSACESetting() const; - void _ReportDECACSetting(const VTInt itemNumber) const; - - void _ReportCursorInformation(); - StringHandler _RestoreCursorInformation(); - void _ReportTabStops(); - StringHandler _RestoreTabStops(); - - StringHandler _CreateDrcsPassthroughHandler(const DispatchTypes::DrcsCharsetSize charsetSize); - StringHandler _CreatePassthroughHandler(); - - std::vector _tabStopColumns; - bool _initDefaultTabStops = true; - - ITerminalApi& _api; - Renderer& _renderer; - RenderSettings& _renderSettings; - TerminalInput& _terminalInput; - TerminalOutput _termOutput; - std::unique_ptr _fontBuffer; - std::shared_ptr _macroBuffer; - std::optional _initialCodePage; - - // We have two instances of the saved cursor state, because we need - // one for the main buffer (at index 0), and another for the alt buffer - // (at index 1). The _usingAltBuffer property keeps tracks of which - // buffer is active, so can be used as an index into this array to - // obtain the saved state that should be currently active. - std::array _savedCursorState; - bool _usingAltBuffer; - - til::inclusive_rect _scrollMargins; - - til::enumset _modes; - - SgrStack _sgrStack; - - size_t _SetRgbColorsHelper(const VTParameters options, - TextAttribute& attr, - const bool isForeground) noexcept; - size_t _ApplyGraphicsOption(const VTParameters options, - const size_t optionIndex, - TextAttribute& attr) noexcept; - void _ApplyGraphicsOptions(const VTParameters options, - TextAttribute& attr) noexcept; - -#ifdef UNIT_TESTING - friend class AdapterTest; -#endif - }; -} +/*++ +Copyright (c) Microsoft Corporation +Licensed under the MIT license. + +Module Name: +- adaptDispatch.hpp + +Abstract: +- This serves as the Windows Console API-specific implementation of the callbacks from our generic Virtual Terminal parser. + +Author(s): +- Michael Niksa (MiNiksa) 30-July-2015 +--*/ + +#pragma once + +#include "termDispatch.hpp" +#include "ITerminalApi.hpp" +#include "FontBuffer.hpp" +#include "MacroBuffer.hpp" +#include "terminalOutput.hpp" +#include "../input/terminalInput.hpp" +#include "../../types/inc/sgrStack.hpp" + +// fwdecl unittest classes +#ifdef UNIT_TESTING +class AdapterTest; +#endif + +namespace Microsoft::Console::VirtualTerminal +{ + class AdaptDispatch : public ITermDispatch + { + using Renderer = Microsoft::Console::Render::Renderer; + using RenderSettings = Microsoft::Console::Render::RenderSettings; + + public: + AdaptDispatch(ITerminalApi& api, Renderer& renderer, RenderSettings& renderSettings, TerminalInput& terminalInput); + + void Print(const wchar_t wchPrintable) override; + void PrintString(const std::wstring_view string) override; + + bool CursorUp(const VTInt distance) override; // CUU + bool CursorDown(const VTInt distance) override; // CUD + bool CursorForward(const VTInt distance) override; // CUF + bool CursorBackward(const VTInt distance) override; // CUB, BS + bool CursorNextLine(const VTInt distance) override; // CNL + bool CursorPrevLine(const VTInt distance) override; // CPL + bool CursorHorizontalPositionAbsolute(const VTInt column) override; // HPA, CHA + bool VerticalLinePositionAbsolute(const VTInt line) override; // VPA + bool HorizontalPositionRelative(const VTInt distance) override; // HPR + bool VerticalPositionRelative(const VTInt distance) override; // VPR + bool CursorPosition(const VTInt line, const VTInt column) override; // CUP, HVP + bool CursorSaveState() override; // DECSC + bool CursorRestoreState() override; // DECRC + bool EraseInDisplay(const DispatchTypes::EraseType eraseType) override; // ED + bool EraseInLine(const DispatchTypes::EraseType eraseType) override; // EL + bool EraseCharacters(const VTInt numChars) override; // ECH + bool SelectiveEraseInDisplay(const DispatchTypes::EraseType eraseType) override; // DECSED + bool SelectiveEraseInLine(const DispatchTypes::EraseType eraseType) override; // DECSEL + bool InsertCharacter(const VTInt count) override; // ICH + bool DeleteCharacter(const VTInt count) override; // DCH + bool ChangeAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECCARA + bool ReverseAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECRARA + bool CopyRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTInt page, const VTInt dstTop, const VTInt dstLeft, const VTInt dstPage) override; // DECCRA + bool FillRectangularArea(const VTParameter ch, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECFRA + bool EraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECERA + bool SelectiveEraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECSERA + bool SelectAttributeChangeExtent(const DispatchTypes::ChangeExtent changeExtent) noexcept override; // DECSACE + bool RequestChecksumRectangularArea(const VTInt id, const VTInt page, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECRQCRA + bool SetGraphicsRendition(const VTParameters options) override; // SGR + bool SetLineRendition(const LineRendition rendition) override; // DECSWL, DECDWL, DECDHL + bool SetCharacterProtectionAttribute(const VTParameters options) override; // DECSCA + bool PushGraphicsRendition(const VTParameters options) override; // XTPUSHSGR + bool PopGraphicsRendition() override; // XTPOPSGR + bool DeviceStatusReport(const DispatchTypes::StatusType statusType, const VTParameter id) override; // DSR + bool DeviceAttributes() override; // DA1 + bool SecondaryDeviceAttributes() override; // DA2 + bool TertiaryDeviceAttributes() override; // DA3 + bool Vt52DeviceAttributes() override; // VT52 Identify + bool RequestTerminalParameters(const DispatchTypes::ReportingPermission permission) override; // DECREQTPARM + bool ScrollUp(const VTInt distance) override; // SU + bool ScrollDown(const VTInt distance) override; // SD + bool InsertLine(const VTInt distance) override; // IL + bool DeleteLine(const VTInt distance) override; // DL + bool InsertColumn(const VTInt distance) override; // DECIC + bool DeleteColumn(const VTInt distance) override; // DECDC + bool SetMode(const DispatchTypes::ModeParams param) override; // SM, DECSET + bool ResetMode(const DispatchTypes::ModeParams param) override; // RM, DECRST + bool RequestMode(const DispatchTypes::ModeParams param) override; // DECRQM + bool SetKeypadMode(const bool applicationMode) override; // DECKPAM, DECKPNM + bool SetAnsiMode(const bool ansiMode) override; // DECANM + bool SetTopBottomScrollingMargins(const VTInt topMargin, + const VTInt bottomMargin) override; // DECSTBM + bool SetLeftRightScrollingMargins(const VTInt leftMargin, + const VTInt rightMargin) override; // DECSLRM + bool WarningBell() override; // BEL + bool CarriageReturn() override; // CR + bool LineFeed(const DispatchTypes::LineFeedType lineFeedType) override; // IND, NEL, LF, FF, VT + bool ReverseLineFeed() override; // RI + bool BackIndex() override; // DECBI + bool ForwardIndex() override; // DECFI + bool SetWindowTitle(const std::wstring_view title) override; // OSCWindowTitle + bool HorizontalTabSet() override; // HTS + bool ForwardTab(const VTInt numTabs) override; // CHT, HT + bool BackwardsTab(const VTInt numTabs) override; // CBT + bool TabClear(const DispatchTypes::TabClearType clearType) override; // TBC + bool DesignateCodingSystem(const VTID codingSystem) override; // DOCS + bool Designate94Charset(const VTInt gsetNumber, const VTID charset) override; // SCS + bool Designate96Charset(const VTInt gsetNumber, const VTID charset) override; // SCS + bool LockingShift(const VTInt gsetNumber) override; // LS0, LS1, LS2, LS3 + bool LockingShiftRight(const VTInt gsetNumber) override; // LS1R, LS2R, LS3R + bool SingleShift(const VTInt gsetNumber) noexcept override; // SS2, SS3 + bool AcceptC1Controls(const bool enabled) override; // DECAC1 + bool SoftReset() override; // DECSTR + bool HardReset() override; // RIS + bool ScreenAlignmentPattern() override; // DECALN + bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) override; // DECSCUSR + bool SetCursorColor(const COLORREF cursorColor) override; + + bool SetClipboard(const std::wstring_view content) override; // OSCSetClipboard + + bool SetColorTableEntry(const size_t tableIndex, + const DWORD color) override; // OSCColorTable + bool SetDefaultForeground(const DWORD color) override; // OSCDefaultForeground + bool SetDefaultBackground(const DWORD color) override; // OSCDefaultBackground + bool AssignColor(const DispatchTypes::ColorItem item, const VTInt fgIndex, const VTInt bgIndex) override; // DECAC + + bool WindowManipulation(const DispatchTypes::WindowManipulationType function, + const VTParameter parameter1, + const VTParameter parameter2) override; // DTTERM_WindowManipulation + + bool AddHyperlink(const std::wstring_view uri, const std::wstring_view params) override; + bool EndHyperlink() override; + + bool DoConEmuAction(const std::wstring_view string) override; + + bool DoITerm2Action(const std::wstring_view string) override; + + bool DoFinalTermAction(const std::wstring_view string) override; + + StringHandler DownloadDRCS(const VTInt fontNumber, + const VTParameter startChar, + const DispatchTypes::DrcsEraseControl eraseControl, + const DispatchTypes::DrcsCellMatrix cellMatrix, + const DispatchTypes::DrcsFontSet fontSet, + const DispatchTypes::DrcsFontUsage fontUsage, + const VTParameter cellHeight, + const DispatchTypes::DrcsCharsetSize charsetSize) override; // DECDLD + + StringHandler DefineMacro(const VTInt macroId, + const DispatchTypes::MacroDeleteControl deleteControl, + const DispatchTypes::MacroEncoding encoding) override; // DECDMAC + bool InvokeMacro(const VTInt macroId) override; // DECINVM + + StringHandler RestoreTerminalState(const DispatchTypes::ReportFormat format) override; // DECRSTS + + StringHandler RequestSetting() override; // DECRQSS + + bool RequestPresentationStateReport(const DispatchTypes::PresentationReportFormat format) override; // DECRQPSR + StringHandler RestorePresentationState(const DispatchTypes::PresentationReportFormat format) override; // DECRSPS + + bool PlaySounds(const VTParameters parameters) override; // DECPS + + private: + enum class Mode + { + InsertReplace, + Origin, + Column, + AllowDECCOLM, + AllowDECSLRM, + EraseColor, + RectangularChangeExtent + }; + enum class ScrollDirection + { + Up, + Down + }; + struct CursorState + { + VTInt Row = 1; + VTInt Column = 1; + bool IsDelayedEOLWrap = false; + bool IsOriginModeRelative = false; + TextAttribute Attributes = {}; + TerminalOutput TermOutput = {}; + bool C1ControlsAccepted = false; + unsigned int CodePage = 0; + }; + struct Offset + { + VTInt Value; + bool IsAbsolute; + // VT origin is at 1,1 so we need to subtract 1 from absolute positions. + static constexpr Offset Absolute(const VTInt value) { return { value - 1, true }; }; + static constexpr Offset Forward(const VTInt value) { return { value, false }; }; + static constexpr Offset Backward(const VTInt value) { return { -value, false }; }; + static constexpr Offset Unchanged() { return Forward(0); }; + }; + struct ChangeOps + { + CharacterAttributes andAttrMask = CharacterAttributes::All; + CharacterAttributes xorAttrMask = CharacterAttributes::Normal; + std::optional foreground; + std::optional background; + }; + + void _WriteToBuffer(const std::wstring_view string); + std::pair _GetVerticalMargins(const til::rect& viewport, const bool absolute) noexcept; + std::pair _GetHorizontalMargins(const til::CoordType bufferWidth) noexcept; + bool _CursorMovePosition(const Offset rowOffset, const Offset colOffset, const bool clampInMargins); + void _ApplyCursorMovementFlags(Cursor& cursor) noexcept; + void _FillRect(TextBuffer& textBuffer, const til::rect& fillRect, const std::wstring_view& fillChar, const TextAttribute& fillAttrs) const; + void _SelectiveEraseRect(TextBuffer& textBuffer, const til::rect& eraseRect); + void _ChangeRectAttributes(TextBuffer& textBuffer, const til::rect& changeRect, const ChangeOps& changeOps); + void _ChangeRectOrStreamAttributes(const til::rect& changeArea, const ChangeOps& changeOps); + til::rect _CalculateRectArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const til::size bufferSize); + bool _EraseScrollback(); + bool _EraseAll(); + TextAttribute _GetEraseAttributes(const TextBuffer& textBuffer) const noexcept; + void _ScrollRectVertically(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); + void _ScrollRectHorizontally(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); + void _InsertDeleteCharacterHelper(const VTInt delta); + void _InsertDeleteLineHelper(const VTInt delta); + void _InsertDeleteColumnHelper(const VTInt delta); + void _ScrollMovement(const VTInt delta); + + void _DoSetTopBottomScrollingMargins(const VTInt topMargin, + const VTInt bottomMargin, + const bool homeCursor = false); + void _DoSetLeftRightScrollingMargins(const VTInt leftMargin, + const VTInt rightMargin, + const bool homeCursor = false); + + void _DoLineFeed(TextBuffer& textBuffer, const bool withReturn, const bool wrapForced); + + void _OperatingStatus() const; + void _CursorPositionReport(const bool extendedReport); + void _MacroSpaceReport() const; + void _MacroChecksumReport(const VTParameter id) const; + + void _SetColumnMode(const bool enable); + void _SetAlternateScreenBufferMode(const bool enable); + bool _PassThroughInputModes(); + bool _ModeParamsHelper(const DispatchTypes::ModeParams param, const bool enable); + + void _ClearSingleTabStop(); + void _ClearAllTabStops() noexcept; + void _ResetTabStops() noexcept; + void _InitTabStopsForWidth(const VTInt width); + + StringHandler _RestoreColorTable(); + + void _ReportSGRSetting() const; + void _ReportDECSTBMSetting(); + void _ReportDECSLRMSetting(); + void _ReportDECSCASetting() const; + void _ReportDECSACESetting() const; + void _ReportDECACSetting(const VTInt itemNumber) const; + + void _ReportCursorInformation(); + StringHandler _RestoreCursorInformation(); + void _ReportTabStops(); + StringHandler _RestoreTabStops(); + + StringHandler _CreateDrcsPassthroughHandler(const DispatchTypes::DrcsCharsetSize charsetSize); + StringHandler _CreatePassthroughHandler(); + + std::vector _tabStopColumns; + bool _initDefaultTabStops = true; + + ITerminalApi& _api; + Renderer& _renderer; + RenderSettings& _renderSettings; + TerminalInput& _terminalInput; + TerminalOutput _termOutput; + std::unique_ptr _fontBuffer; + std::shared_ptr _macroBuffer; + std::optional _initialCodePage; + + // We have two instances of the saved cursor state, because we need + // one for the main buffer (at index 0), and another for the alt buffer + // (at index 1). The _usingAltBuffer property keeps tracks of which + // buffer is active, so can be used as an index into this array to + // obtain the saved state that should be currently active. + std::array _savedCursorState; + bool _usingAltBuffer; + + til::inclusive_rect _scrollMargins; + + til::enumset _modes; + + SgrStack _sgrStack; + + size_t _SetRgbColorsHelper(const VTParameters options, + TextAttribute& attr, + const DispatchTypes::TextProp propType) noexcept; + size_t _ApplyGraphicsOption(const VTParameters options, + const size_t optionIndex, + TextAttribute& attr) noexcept; + void _ApplyGraphicsOptions(const VTParameters options, + TextAttribute& attr) noexcept; + +#ifdef UNIT_TESTING + friend class AdapterTest; +#endif + }; +} diff --git a/src/terminal/adapter/adaptDispatchGraphics.cpp b/src/terminal/adapter/adaptDispatchGraphics.cpp index 0de71a293ae..ad9d0094d2f 100644 --- a/src/terminal/adapter/adaptDispatchGraphics.cpp +++ b/src/terminal/adapter/adaptDispatchGraphics.cpp @@ -13,20 +13,21 @@ using namespace Microsoft::Console::VirtualTerminal; using namespace Microsoft::Console::VirtualTerminal::DispatchTypes; // Routine Description: -// - Helper to parse extended graphics options, which start with 38 (FG) or 48 (BG) +// - Helper to parse extended graphics options, which start with 38 (FG) or 48 (BG) or 58 (underline) // These options are followed by either a 2 (RGB) or 5 (xterm index) // RGB sequences then take 3 MORE params to designate the R, G, B parts of the color // Xterm index will use the param that follows to use a color from the preset 256 color xterm color table. // Arguments: // - options - An array of options that will be used to generate the RGB color // - attr - The attribute that will be updated with the parsed color. -// - isForeground - Whether or not the parsed color is for the foreground. +// - propType - text property to apply the parsed color on. // Return Value: -// - The number of options consumed, not including the initial 38/48. +// - The number of options consumed, not including the initial 38/48/58. size_t AdaptDispatch::_SetRgbColorsHelper(const VTParameters options, TextAttribute& attr, - const bool isForeground) noexcept + TextProp propType) noexcept { + using enum TextProp; size_t optionsConsumed = 1; const DispatchTypes::GraphicsOptions typeOpt = options.at(0); if (typeOpt == DispatchTypes::GraphicsOptions::RGBColorOrFaint) @@ -39,7 +40,18 @@ size_t AdaptDispatch::_SetRgbColorsHelper(const VTParameters options, if (red <= 255 && green <= 255 && blue <= 255) { const auto rgbColor = RGB(red, green, blue); - attr.SetColor(rgbColor, isForeground); + switch (propType) + { + case Foreground: + attr.SetColor(rgbColor, true); + break; + case Background: + attr.SetColor(rgbColor, false); + break; + case Underline: + attr.SetUnderlineColor(rgbColor); + break; + } } } else if (typeOpt == DispatchTypes::GraphicsOptions::BlinkOrXterm256Index) @@ -49,13 +61,17 @@ size_t AdaptDispatch::_SetRgbColorsHelper(const VTParameters options, if (tableIndex <= 255) { const auto adjustedIndex = gsl::narrow_cast(tableIndex); - if (isForeground) + switch (propType) { + case Foreground: attr.SetIndexedForeground256(adjustedIndex); - } - else - { + break; + case Background: attr.SetIndexedBackground256(adjustedIndex); + break; + case Underline: + attr.SetIndexedUnderlineColor256(adjustedIndex); + break; } } } @@ -80,6 +96,7 @@ size_t AdaptDispatch::_ApplyGraphicsOption(const VTParameters options, case Off: attr.SetDefaultForeground(); attr.SetDefaultBackground(); + attr.SetDefaultUnderlineColor(); attr.SetDefaultRenditionAttributes(); return 1; case ForegroundDefault: @@ -242,9 +259,14 @@ size_t AdaptDispatch::_ApplyGraphicsOption(const VTParameters options, attr.SetIndexedBackground(TextColor::BRIGHT_WHITE); return 1; case ForegroundExtended: - return 1 + _SetRgbColorsHelper(options.subspan(optionIndex + 1), attr, true); + return 1 + _SetRgbColorsHelper(options.subspan(optionIndex + 1), attr, TextProp::Foreground); case BackgroundExtended: - return 1 + _SetRgbColorsHelper(options.subspan(optionIndex + 1), attr, false); + return 1 + _SetRgbColorsHelper(options.subspan(optionIndex + 1), attr, TextProp::Background); + case UnderlineColor: + return 1 + _SetRgbColorsHelper(options.subspan(optionIndex + 1), attr, TextProp::Underline); + case UnderlineColorDefault: + attr.SetDefaultUnderlineColor(); + return 1; default: return 1; } From 99bf720151442e6de475f2f9981105c748ef00e4 Mon Sep 17 00:00:00 2001 From: Tushar Singh Date: Sun, 25 Jun 2023 18:18:33 +0530 Subject: [PATCH 2/3] fix line endings --- src/terminal/adapter/adaptDispatch.hpp | 620 ++++++++++++------------- 1 file changed, 310 insertions(+), 310 deletions(-) diff --git a/src/terminal/adapter/adaptDispatch.hpp b/src/terminal/adapter/adaptDispatch.hpp index d7ed862b415..b72b49caedc 100644 --- a/src/terminal/adapter/adaptDispatch.hpp +++ b/src/terminal/adapter/adaptDispatch.hpp @@ -1,310 +1,310 @@ -/*++ -Copyright (c) Microsoft Corporation -Licensed under the MIT license. - -Module Name: -- adaptDispatch.hpp - -Abstract: -- This serves as the Windows Console API-specific implementation of the callbacks from our generic Virtual Terminal parser. - -Author(s): -- Michael Niksa (MiNiksa) 30-July-2015 ---*/ - -#pragma once - -#include "termDispatch.hpp" -#include "ITerminalApi.hpp" -#include "FontBuffer.hpp" -#include "MacroBuffer.hpp" -#include "terminalOutput.hpp" -#include "../input/terminalInput.hpp" -#include "../../types/inc/sgrStack.hpp" - -// fwdecl unittest classes -#ifdef UNIT_TESTING -class AdapterTest; -#endif - -namespace Microsoft::Console::VirtualTerminal -{ - class AdaptDispatch : public ITermDispatch - { - using Renderer = Microsoft::Console::Render::Renderer; - using RenderSettings = Microsoft::Console::Render::RenderSettings; - - public: - AdaptDispatch(ITerminalApi& api, Renderer& renderer, RenderSettings& renderSettings, TerminalInput& terminalInput); - - void Print(const wchar_t wchPrintable) override; - void PrintString(const std::wstring_view string) override; - - bool CursorUp(const VTInt distance) override; // CUU - bool CursorDown(const VTInt distance) override; // CUD - bool CursorForward(const VTInt distance) override; // CUF - bool CursorBackward(const VTInt distance) override; // CUB, BS - bool CursorNextLine(const VTInt distance) override; // CNL - bool CursorPrevLine(const VTInt distance) override; // CPL - bool CursorHorizontalPositionAbsolute(const VTInt column) override; // HPA, CHA - bool VerticalLinePositionAbsolute(const VTInt line) override; // VPA - bool HorizontalPositionRelative(const VTInt distance) override; // HPR - bool VerticalPositionRelative(const VTInt distance) override; // VPR - bool CursorPosition(const VTInt line, const VTInt column) override; // CUP, HVP - bool CursorSaveState() override; // DECSC - bool CursorRestoreState() override; // DECRC - bool EraseInDisplay(const DispatchTypes::EraseType eraseType) override; // ED - bool EraseInLine(const DispatchTypes::EraseType eraseType) override; // EL - bool EraseCharacters(const VTInt numChars) override; // ECH - bool SelectiveEraseInDisplay(const DispatchTypes::EraseType eraseType) override; // DECSED - bool SelectiveEraseInLine(const DispatchTypes::EraseType eraseType) override; // DECSEL - bool InsertCharacter(const VTInt count) override; // ICH - bool DeleteCharacter(const VTInt count) override; // DCH - bool ChangeAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECCARA - bool ReverseAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECRARA - bool CopyRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTInt page, const VTInt dstTop, const VTInt dstLeft, const VTInt dstPage) override; // DECCRA - bool FillRectangularArea(const VTParameter ch, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECFRA - bool EraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECERA - bool SelectiveEraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECSERA - bool SelectAttributeChangeExtent(const DispatchTypes::ChangeExtent changeExtent) noexcept override; // DECSACE - bool RequestChecksumRectangularArea(const VTInt id, const VTInt page, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECRQCRA - bool SetGraphicsRendition(const VTParameters options) override; // SGR - bool SetLineRendition(const LineRendition rendition) override; // DECSWL, DECDWL, DECDHL - bool SetCharacterProtectionAttribute(const VTParameters options) override; // DECSCA - bool PushGraphicsRendition(const VTParameters options) override; // XTPUSHSGR - bool PopGraphicsRendition() override; // XTPOPSGR - bool DeviceStatusReport(const DispatchTypes::StatusType statusType, const VTParameter id) override; // DSR - bool DeviceAttributes() override; // DA1 - bool SecondaryDeviceAttributes() override; // DA2 - bool TertiaryDeviceAttributes() override; // DA3 - bool Vt52DeviceAttributes() override; // VT52 Identify - bool RequestTerminalParameters(const DispatchTypes::ReportingPermission permission) override; // DECREQTPARM - bool ScrollUp(const VTInt distance) override; // SU - bool ScrollDown(const VTInt distance) override; // SD - bool InsertLine(const VTInt distance) override; // IL - bool DeleteLine(const VTInt distance) override; // DL - bool InsertColumn(const VTInt distance) override; // DECIC - bool DeleteColumn(const VTInt distance) override; // DECDC - bool SetMode(const DispatchTypes::ModeParams param) override; // SM, DECSET - bool ResetMode(const DispatchTypes::ModeParams param) override; // RM, DECRST - bool RequestMode(const DispatchTypes::ModeParams param) override; // DECRQM - bool SetKeypadMode(const bool applicationMode) override; // DECKPAM, DECKPNM - bool SetAnsiMode(const bool ansiMode) override; // DECANM - bool SetTopBottomScrollingMargins(const VTInt topMargin, - const VTInt bottomMargin) override; // DECSTBM - bool SetLeftRightScrollingMargins(const VTInt leftMargin, - const VTInt rightMargin) override; // DECSLRM - bool WarningBell() override; // BEL - bool CarriageReturn() override; // CR - bool LineFeed(const DispatchTypes::LineFeedType lineFeedType) override; // IND, NEL, LF, FF, VT - bool ReverseLineFeed() override; // RI - bool BackIndex() override; // DECBI - bool ForwardIndex() override; // DECFI - bool SetWindowTitle(const std::wstring_view title) override; // OSCWindowTitle - bool HorizontalTabSet() override; // HTS - bool ForwardTab(const VTInt numTabs) override; // CHT, HT - bool BackwardsTab(const VTInt numTabs) override; // CBT - bool TabClear(const DispatchTypes::TabClearType clearType) override; // TBC - bool DesignateCodingSystem(const VTID codingSystem) override; // DOCS - bool Designate94Charset(const VTInt gsetNumber, const VTID charset) override; // SCS - bool Designate96Charset(const VTInt gsetNumber, const VTID charset) override; // SCS - bool LockingShift(const VTInt gsetNumber) override; // LS0, LS1, LS2, LS3 - bool LockingShiftRight(const VTInt gsetNumber) override; // LS1R, LS2R, LS3R - bool SingleShift(const VTInt gsetNumber) noexcept override; // SS2, SS3 - bool AcceptC1Controls(const bool enabled) override; // DECAC1 - bool SoftReset() override; // DECSTR - bool HardReset() override; // RIS - bool ScreenAlignmentPattern() override; // DECALN - bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) override; // DECSCUSR - bool SetCursorColor(const COLORREF cursorColor) override; - - bool SetClipboard(const std::wstring_view content) override; // OSCSetClipboard - - bool SetColorTableEntry(const size_t tableIndex, - const DWORD color) override; // OSCColorTable - bool SetDefaultForeground(const DWORD color) override; // OSCDefaultForeground - bool SetDefaultBackground(const DWORD color) override; // OSCDefaultBackground - bool AssignColor(const DispatchTypes::ColorItem item, const VTInt fgIndex, const VTInt bgIndex) override; // DECAC - - bool WindowManipulation(const DispatchTypes::WindowManipulationType function, - const VTParameter parameter1, - const VTParameter parameter2) override; // DTTERM_WindowManipulation - - bool AddHyperlink(const std::wstring_view uri, const std::wstring_view params) override; - bool EndHyperlink() override; - - bool DoConEmuAction(const std::wstring_view string) override; - - bool DoITerm2Action(const std::wstring_view string) override; - - bool DoFinalTermAction(const std::wstring_view string) override; - - StringHandler DownloadDRCS(const VTInt fontNumber, - const VTParameter startChar, - const DispatchTypes::DrcsEraseControl eraseControl, - const DispatchTypes::DrcsCellMatrix cellMatrix, - const DispatchTypes::DrcsFontSet fontSet, - const DispatchTypes::DrcsFontUsage fontUsage, - const VTParameter cellHeight, - const DispatchTypes::DrcsCharsetSize charsetSize) override; // DECDLD - - StringHandler DefineMacro(const VTInt macroId, - const DispatchTypes::MacroDeleteControl deleteControl, - const DispatchTypes::MacroEncoding encoding) override; // DECDMAC - bool InvokeMacro(const VTInt macroId) override; // DECINVM - - StringHandler RestoreTerminalState(const DispatchTypes::ReportFormat format) override; // DECRSTS - - StringHandler RequestSetting() override; // DECRQSS - - bool RequestPresentationStateReport(const DispatchTypes::PresentationReportFormat format) override; // DECRQPSR - StringHandler RestorePresentationState(const DispatchTypes::PresentationReportFormat format) override; // DECRSPS - - bool PlaySounds(const VTParameters parameters) override; // DECPS - - private: - enum class Mode - { - InsertReplace, - Origin, - Column, - AllowDECCOLM, - AllowDECSLRM, - EraseColor, - RectangularChangeExtent - }; - enum class ScrollDirection - { - Up, - Down - }; - struct CursorState - { - VTInt Row = 1; - VTInt Column = 1; - bool IsDelayedEOLWrap = false; - bool IsOriginModeRelative = false; - TextAttribute Attributes = {}; - TerminalOutput TermOutput = {}; - bool C1ControlsAccepted = false; - unsigned int CodePage = 0; - }; - struct Offset - { - VTInt Value; - bool IsAbsolute; - // VT origin is at 1,1 so we need to subtract 1 from absolute positions. - static constexpr Offset Absolute(const VTInt value) { return { value - 1, true }; }; - static constexpr Offset Forward(const VTInt value) { return { value, false }; }; - static constexpr Offset Backward(const VTInt value) { return { -value, false }; }; - static constexpr Offset Unchanged() { return Forward(0); }; - }; - struct ChangeOps - { - CharacterAttributes andAttrMask = CharacterAttributes::All; - CharacterAttributes xorAttrMask = CharacterAttributes::Normal; - std::optional foreground; - std::optional background; - }; - - void _WriteToBuffer(const std::wstring_view string); - std::pair _GetVerticalMargins(const til::rect& viewport, const bool absolute) noexcept; - std::pair _GetHorizontalMargins(const til::CoordType bufferWidth) noexcept; - bool _CursorMovePosition(const Offset rowOffset, const Offset colOffset, const bool clampInMargins); - void _ApplyCursorMovementFlags(Cursor& cursor) noexcept; - void _FillRect(TextBuffer& textBuffer, const til::rect& fillRect, const std::wstring_view& fillChar, const TextAttribute& fillAttrs) const; - void _SelectiveEraseRect(TextBuffer& textBuffer, const til::rect& eraseRect); - void _ChangeRectAttributes(TextBuffer& textBuffer, const til::rect& changeRect, const ChangeOps& changeOps); - void _ChangeRectOrStreamAttributes(const til::rect& changeArea, const ChangeOps& changeOps); - til::rect _CalculateRectArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const til::size bufferSize); - bool _EraseScrollback(); - bool _EraseAll(); - TextAttribute _GetEraseAttributes(const TextBuffer& textBuffer) const noexcept; - void _ScrollRectVertically(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); - void _ScrollRectHorizontally(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); - void _InsertDeleteCharacterHelper(const VTInt delta); - void _InsertDeleteLineHelper(const VTInt delta); - void _InsertDeleteColumnHelper(const VTInt delta); - void _ScrollMovement(const VTInt delta); - - void _DoSetTopBottomScrollingMargins(const VTInt topMargin, - const VTInt bottomMargin, - const bool homeCursor = false); - void _DoSetLeftRightScrollingMargins(const VTInt leftMargin, - const VTInt rightMargin, - const bool homeCursor = false); - - void _DoLineFeed(TextBuffer& textBuffer, const bool withReturn, const bool wrapForced); - - void _OperatingStatus() const; - void _CursorPositionReport(const bool extendedReport); - void _MacroSpaceReport() const; - void _MacroChecksumReport(const VTParameter id) const; - - void _SetColumnMode(const bool enable); - void _SetAlternateScreenBufferMode(const bool enable); - bool _PassThroughInputModes(); - bool _ModeParamsHelper(const DispatchTypes::ModeParams param, const bool enable); - - void _ClearSingleTabStop(); - void _ClearAllTabStops() noexcept; - void _ResetTabStops() noexcept; - void _InitTabStopsForWidth(const VTInt width); - - StringHandler _RestoreColorTable(); - - void _ReportSGRSetting() const; - void _ReportDECSTBMSetting(); - void _ReportDECSLRMSetting(); - void _ReportDECSCASetting() const; - void _ReportDECSACESetting() const; - void _ReportDECACSetting(const VTInt itemNumber) const; - - void _ReportCursorInformation(); - StringHandler _RestoreCursorInformation(); - void _ReportTabStops(); - StringHandler _RestoreTabStops(); - - StringHandler _CreateDrcsPassthroughHandler(const DispatchTypes::DrcsCharsetSize charsetSize); - StringHandler _CreatePassthroughHandler(); - - std::vector _tabStopColumns; - bool _initDefaultTabStops = true; - - ITerminalApi& _api; - Renderer& _renderer; - RenderSettings& _renderSettings; - TerminalInput& _terminalInput; - TerminalOutput _termOutput; - std::unique_ptr _fontBuffer; - std::shared_ptr _macroBuffer; - std::optional _initialCodePage; - - // We have two instances of the saved cursor state, because we need - // one for the main buffer (at index 0), and another for the alt buffer - // (at index 1). The _usingAltBuffer property keeps tracks of which - // buffer is active, so can be used as an index into this array to - // obtain the saved state that should be currently active. - std::array _savedCursorState; - bool _usingAltBuffer; - - til::inclusive_rect _scrollMargins; - - til::enumset _modes; - - SgrStack _sgrStack; - - size_t _SetRgbColorsHelper(const VTParameters options, - TextAttribute& attr, - const DispatchTypes::TextProp propType) noexcept; - size_t _ApplyGraphicsOption(const VTParameters options, - const size_t optionIndex, - TextAttribute& attr) noexcept; - void _ApplyGraphicsOptions(const VTParameters options, - TextAttribute& attr) noexcept; - -#ifdef UNIT_TESTING - friend class AdapterTest; -#endif - }; -} +/*++ +Copyright (c) Microsoft Corporation +Licensed under the MIT license. + +Module Name: +- adaptDispatch.hpp + +Abstract: +- This serves as the Windows Console API-specific implementation of the callbacks from our generic Virtual Terminal parser. + +Author(s): +- Michael Niksa (MiNiksa) 30-July-2015 +--*/ + +#pragma once + +#include "termDispatch.hpp" +#include "ITerminalApi.hpp" +#include "FontBuffer.hpp" +#include "MacroBuffer.hpp" +#include "terminalOutput.hpp" +#include "../input/terminalInput.hpp" +#include "../../types/inc/sgrStack.hpp" + +// fwdecl unittest classes +#ifdef UNIT_TESTING +class AdapterTest; +#endif + +namespace Microsoft::Console::VirtualTerminal +{ + class AdaptDispatch : public ITermDispatch + { + using Renderer = Microsoft::Console::Render::Renderer; + using RenderSettings = Microsoft::Console::Render::RenderSettings; + + public: + AdaptDispatch(ITerminalApi& api, Renderer& renderer, RenderSettings& renderSettings, TerminalInput& terminalInput); + + void Print(const wchar_t wchPrintable) override; + void PrintString(const std::wstring_view string) override; + + bool CursorUp(const VTInt distance) override; // CUU + bool CursorDown(const VTInt distance) override; // CUD + bool CursorForward(const VTInt distance) override; // CUF + bool CursorBackward(const VTInt distance) override; // CUB, BS + bool CursorNextLine(const VTInt distance) override; // CNL + bool CursorPrevLine(const VTInt distance) override; // CPL + bool CursorHorizontalPositionAbsolute(const VTInt column) override; // HPA, CHA + bool VerticalLinePositionAbsolute(const VTInt line) override; // VPA + bool HorizontalPositionRelative(const VTInt distance) override; // HPR + bool VerticalPositionRelative(const VTInt distance) override; // VPR + bool CursorPosition(const VTInt line, const VTInt column) override; // CUP, HVP + bool CursorSaveState() override; // DECSC + bool CursorRestoreState() override; // DECRC + bool EraseInDisplay(const DispatchTypes::EraseType eraseType) override; // ED + bool EraseInLine(const DispatchTypes::EraseType eraseType) override; // EL + bool EraseCharacters(const VTInt numChars) override; // ECH + bool SelectiveEraseInDisplay(const DispatchTypes::EraseType eraseType) override; // DECSED + bool SelectiveEraseInLine(const DispatchTypes::EraseType eraseType) override; // DECSEL + bool InsertCharacter(const VTInt count) override; // ICH + bool DeleteCharacter(const VTInt count) override; // DCH + bool ChangeAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECCARA + bool ReverseAttributesRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTParameters attrs) override; // DECRARA + bool CopyRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const VTInt page, const VTInt dstTop, const VTInt dstLeft, const VTInt dstPage) override; // DECCRA + bool FillRectangularArea(const VTParameter ch, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECFRA + bool EraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECERA + bool SelectiveEraseRectangularArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECSERA + bool SelectAttributeChangeExtent(const DispatchTypes::ChangeExtent changeExtent) noexcept override; // DECSACE + bool RequestChecksumRectangularArea(const VTInt id, const VTInt page, const VTInt top, const VTInt left, const VTInt bottom, const VTInt right) override; // DECRQCRA + bool SetGraphicsRendition(const VTParameters options) override; // SGR + bool SetLineRendition(const LineRendition rendition) override; // DECSWL, DECDWL, DECDHL + bool SetCharacterProtectionAttribute(const VTParameters options) override; // DECSCA + bool PushGraphicsRendition(const VTParameters options) override; // XTPUSHSGR + bool PopGraphicsRendition() override; // XTPOPSGR + bool DeviceStatusReport(const DispatchTypes::StatusType statusType, const VTParameter id) override; // DSR + bool DeviceAttributes() override; // DA1 + bool SecondaryDeviceAttributes() override; // DA2 + bool TertiaryDeviceAttributes() override; // DA3 + bool Vt52DeviceAttributes() override; // VT52 Identify + bool RequestTerminalParameters(const DispatchTypes::ReportingPermission permission) override; // DECREQTPARM + bool ScrollUp(const VTInt distance) override; // SU + bool ScrollDown(const VTInt distance) override; // SD + bool InsertLine(const VTInt distance) override; // IL + bool DeleteLine(const VTInt distance) override; // DL + bool InsertColumn(const VTInt distance) override; // DECIC + bool DeleteColumn(const VTInt distance) override; // DECDC + bool SetMode(const DispatchTypes::ModeParams param) override; // SM, DECSET + bool ResetMode(const DispatchTypes::ModeParams param) override; // RM, DECRST + bool RequestMode(const DispatchTypes::ModeParams param) override; // DECRQM + bool SetKeypadMode(const bool applicationMode) override; // DECKPAM, DECKPNM + bool SetAnsiMode(const bool ansiMode) override; // DECANM + bool SetTopBottomScrollingMargins(const VTInt topMargin, + const VTInt bottomMargin) override; // DECSTBM + bool SetLeftRightScrollingMargins(const VTInt leftMargin, + const VTInt rightMargin) override; // DECSLRM + bool WarningBell() override; // BEL + bool CarriageReturn() override; // CR + bool LineFeed(const DispatchTypes::LineFeedType lineFeedType) override; // IND, NEL, LF, FF, VT + bool ReverseLineFeed() override; // RI + bool BackIndex() override; // DECBI + bool ForwardIndex() override; // DECFI + bool SetWindowTitle(const std::wstring_view title) override; // OSCWindowTitle + bool HorizontalTabSet() override; // HTS + bool ForwardTab(const VTInt numTabs) override; // CHT, HT + bool BackwardsTab(const VTInt numTabs) override; // CBT + bool TabClear(const DispatchTypes::TabClearType clearType) override; // TBC + bool DesignateCodingSystem(const VTID codingSystem) override; // DOCS + bool Designate94Charset(const VTInt gsetNumber, const VTID charset) override; // SCS + bool Designate96Charset(const VTInt gsetNumber, const VTID charset) override; // SCS + bool LockingShift(const VTInt gsetNumber) override; // LS0, LS1, LS2, LS3 + bool LockingShiftRight(const VTInt gsetNumber) override; // LS1R, LS2R, LS3R + bool SingleShift(const VTInt gsetNumber) noexcept override; // SS2, SS3 + bool AcceptC1Controls(const bool enabled) override; // DECAC1 + bool SoftReset() override; // DECSTR + bool HardReset() override; // RIS + bool ScreenAlignmentPattern() override; // DECALN + bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) override; // DECSCUSR + bool SetCursorColor(const COLORREF cursorColor) override; + + bool SetClipboard(const std::wstring_view content) override; // OSCSetClipboard + + bool SetColorTableEntry(const size_t tableIndex, + const DWORD color) override; // OSCColorTable + bool SetDefaultForeground(const DWORD color) override; // OSCDefaultForeground + bool SetDefaultBackground(const DWORD color) override; // OSCDefaultBackground + bool AssignColor(const DispatchTypes::ColorItem item, const VTInt fgIndex, const VTInt bgIndex) override; // DECAC + + bool WindowManipulation(const DispatchTypes::WindowManipulationType function, + const VTParameter parameter1, + const VTParameter parameter2) override; // DTTERM_WindowManipulation + + bool AddHyperlink(const std::wstring_view uri, const std::wstring_view params) override; + bool EndHyperlink() override; + + bool DoConEmuAction(const std::wstring_view string) override; + + bool DoITerm2Action(const std::wstring_view string) override; + + bool DoFinalTermAction(const std::wstring_view string) override; + + StringHandler DownloadDRCS(const VTInt fontNumber, + const VTParameter startChar, + const DispatchTypes::DrcsEraseControl eraseControl, + const DispatchTypes::DrcsCellMatrix cellMatrix, + const DispatchTypes::DrcsFontSet fontSet, + const DispatchTypes::DrcsFontUsage fontUsage, + const VTParameter cellHeight, + const DispatchTypes::DrcsCharsetSize charsetSize) override; // DECDLD + + StringHandler DefineMacro(const VTInt macroId, + const DispatchTypes::MacroDeleteControl deleteControl, + const DispatchTypes::MacroEncoding encoding) override; // DECDMAC + bool InvokeMacro(const VTInt macroId) override; // DECINVM + + StringHandler RestoreTerminalState(const DispatchTypes::ReportFormat format) override; // DECRSTS + + StringHandler RequestSetting() override; // DECRQSS + + bool RequestPresentationStateReport(const DispatchTypes::PresentationReportFormat format) override; // DECRQPSR + StringHandler RestorePresentationState(const DispatchTypes::PresentationReportFormat format) override; // DECRSPS + + bool PlaySounds(const VTParameters parameters) override; // DECPS + + private: + enum class Mode + { + InsertReplace, + Origin, + Column, + AllowDECCOLM, + AllowDECSLRM, + EraseColor, + RectangularChangeExtent + }; + enum class ScrollDirection + { + Up, + Down + }; + struct CursorState + { + VTInt Row = 1; + VTInt Column = 1; + bool IsDelayedEOLWrap = false; + bool IsOriginModeRelative = false; + TextAttribute Attributes = {}; + TerminalOutput TermOutput = {}; + bool C1ControlsAccepted = false; + unsigned int CodePage = 0; + }; + struct Offset + { + VTInt Value; + bool IsAbsolute; + // VT origin is at 1,1 so we need to subtract 1 from absolute positions. + static constexpr Offset Absolute(const VTInt value) { return { value - 1, true }; }; + static constexpr Offset Forward(const VTInt value) { return { value, false }; }; + static constexpr Offset Backward(const VTInt value) { return { -value, false }; }; + static constexpr Offset Unchanged() { return Forward(0); }; + }; + struct ChangeOps + { + CharacterAttributes andAttrMask = CharacterAttributes::All; + CharacterAttributes xorAttrMask = CharacterAttributes::Normal; + std::optional foreground; + std::optional background; + }; + + void _WriteToBuffer(const std::wstring_view string); + std::pair _GetVerticalMargins(const til::rect& viewport, const bool absolute) noexcept; + std::pair _GetHorizontalMargins(const til::CoordType bufferWidth) noexcept; + bool _CursorMovePosition(const Offset rowOffset, const Offset colOffset, const bool clampInMargins); + void _ApplyCursorMovementFlags(Cursor& cursor) noexcept; + void _FillRect(TextBuffer& textBuffer, const til::rect& fillRect, const std::wstring_view& fillChar, const TextAttribute& fillAttrs) const; + void _SelectiveEraseRect(TextBuffer& textBuffer, const til::rect& eraseRect); + void _ChangeRectAttributes(TextBuffer& textBuffer, const til::rect& changeRect, const ChangeOps& changeOps); + void _ChangeRectOrStreamAttributes(const til::rect& changeArea, const ChangeOps& changeOps); + til::rect _CalculateRectArea(const VTInt top, const VTInt left, const VTInt bottom, const VTInt right, const til::size bufferSize); + bool _EraseScrollback(); + bool _EraseAll(); + TextAttribute _GetEraseAttributes(const TextBuffer& textBuffer) const noexcept; + void _ScrollRectVertically(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); + void _ScrollRectHorizontally(TextBuffer& textBuffer, const til::rect& scrollRect, const VTInt delta); + void _InsertDeleteCharacterHelper(const VTInt delta); + void _InsertDeleteLineHelper(const VTInt delta); + void _InsertDeleteColumnHelper(const VTInt delta); + void _ScrollMovement(const VTInt delta); + + void _DoSetTopBottomScrollingMargins(const VTInt topMargin, + const VTInt bottomMargin, + const bool homeCursor = false); + void _DoSetLeftRightScrollingMargins(const VTInt leftMargin, + const VTInt rightMargin, + const bool homeCursor = false); + + void _DoLineFeed(TextBuffer& textBuffer, const bool withReturn, const bool wrapForced); + + void _OperatingStatus() const; + void _CursorPositionReport(const bool extendedReport); + void _MacroSpaceReport() const; + void _MacroChecksumReport(const VTParameter id) const; + + void _SetColumnMode(const bool enable); + void _SetAlternateScreenBufferMode(const bool enable); + bool _PassThroughInputModes(); + bool _ModeParamsHelper(const DispatchTypes::ModeParams param, const bool enable); + + void _ClearSingleTabStop(); + void _ClearAllTabStops() noexcept; + void _ResetTabStops() noexcept; + void _InitTabStopsForWidth(const VTInt width); + + StringHandler _RestoreColorTable(); + + void _ReportSGRSetting() const; + void _ReportDECSTBMSetting(); + void _ReportDECSLRMSetting(); + void _ReportDECSCASetting() const; + void _ReportDECSACESetting() const; + void _ReportDECACSetting(const VTInt itemNumber) const; + + void _ReportCursorInformation(); + StringHandler _RestoreCursorInformation(); + void _ReportTabStops(); + StringHandler _RestoreTabStops(); + + StringHandler _CreateDrcsPassthroughHandler(const DispatchTypes::DrcsCharsetSize charsetSize); + StringHandler _CreatePassthroughHandler(); + + std::vector _tabStopColumns; + bool _initDefaultTabStops = true; + + ITerminalApi& _api; + Renderer& _renderer; + RenderSettings& _renderSettings; + TerminalInput& _terminalInput; + TerminalOutput _termOutput; + std::unique_ptr _fontBuffer; + std::shared_ptr _macroBuffer; + std::optional _initialCodePage; + + // We have two instances of the saved cursor state, because we need + // one for the main buffer (at index 0), and another for the alt buffer + // (at index 1). The _usingAltBuffer property keeps tracks of which + // buffer is active, so can be used as an index into this array to + // obtain the saved state that should be currently active. + std::array _savedCursorState; + bool _usingAltBuffer; + + til::inclusive_rect _scrollMargins; + + til::enumset _modes; + + SgrStack _sgrStack; + + size_t _SetRgbColorsHelper(const VTParameters options, + TextAttribute& attr, + const DispatchTypes::TextProp propType) noexcept; + size_t _ApplyGraphicsOption(const VTParameters options, + const size_t optionIndex, + TextAttribute& attr) noexcept; + void _ApplyGraphicsOptions(const VTParameters options, + TextAttribute& attr) noexcept; + +#ifdef UNIT_TESTING + friend class AdapterTest; +#endif + }; +} From 4630ac2dae566473a6f5bb24814e19de01cf5d9d Mon Sep 17 00:00:00 2001 From: Tushar Singh Date: Sun, 25 Jun 2023 19:14:56 +0530 Subject: [PATCH 3/3] run format --- src/buffer/out/TextAttribute.cpp | 5 +++-- src/renderer/vt/Xterm256Engine.cpp | 3 +-- src/terminal/adapter/adaptDispatchGraphics.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/buffer/out/TextAttribute.cpp b/src/buffer/out/TextAttribute.cpp index ee694260df2..40741374ea0 100644 --- a/src/buffer/out/TextAttribute.cpp +++ b/src/buffer/out/TextAttribute.cpp @@ -202,11 +202,12 @@ void TextAttribute::SetIndexedBackground(const BYTE bgIndex) noexcept } // Method description: -// - No-op, underlines only support index256 and rgb coloring schemes. +// - No-op, underlines only support index256 and rgb coloring schemes. // Arguments: // - cIndex - index16 based color index. void TextAttribute::SetIndexedUnderlineColor(const BYTE /*cIndex*/) noexcept -{} +{ +} void TextAttribute::SetIndexedForeground256(const BYTE fgIndex) noexcept { diff --git a/src/renderer/vt/Xterm256Engine.cpp b/src/renderer/vt/Xterm256Engine.cpp index 65672666e12..f5e62b1a754 100644 --- a/src/renderer/vt/Xterm256Engine.cpp +++ b/src/renderer/vt/Xterm256Engine.cpp @@ -145,7 +145,7 @@ Xterm256Engine::Xterm256Engine(_In_ wil::unique_hfile hPipe, RETURN_IF_FAILED(_SetReverseVideo(textAttributes.IsReverseVideo())); _lastTextAttributes.SetReverseVideo(textAttributes.IsReverseVideo()); } - + // Update underline color. if (textAttributes.GetUnderlineColor() != _lastTextAttributes.GetUnderlineColor()) { @@ -212,7 +212,6 @@ Xterm256Engine::Xterm256Engine(_In_ wil::unique_hfile hPipe, return _WriteFormatted(FMT_COMPILE("\x1b[58;2;{};{};{}m"), r, g, b); } - [[nodiscard]] HRESULT Xterm256Engine::_UnderlineDefaultColor() noexcept { return _Write("\x1b[59m"); diff --git a/src/terminal/adapter/adaptDispatchGraphics.cpp b/src/terminal/adapter/adaptDispatchGraphics.cpp index ad9d0094d2f..3f490753300 100644 --- a/src/terminal/adapter/adaptDispatchGraphics.cpp +++ b/src/terminal/adapter/adaptDispatchGraphics.cpp @@ -266,7 +266,7 @@ size_t AdaptDispatch::_ApplyGraphicsOption(const VTParameters options, return 1 + _SetRgbColorsHelper(options.subspan(optionIndex + 1), attr, TextProp::Underline); case UnderlineColorDefault: attr.SetDefaultUnderlineColor(); - return 1; + return 1; default: return 1; }