From 4552c63a1a1527efbc324f3b874f41a1cac3490c Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Mon, 24 Aug 2020 19:00:36 +0800 Subject: [PATCH 01/13] Init --- src/cascadia/TerminalCore/ITerminalApi.hpp | 1 + src/cascadia/TerminalCore/Terminal.cpp | 4 ++++ src/cascadia/TerminalCore/Terminal.hpp | 4 ++++ src/cascadia/TerminalCore/TerminalApi.cpp | 12 ++++++++++++ src/cascadia/TerminalCore/TerminalDispatch.cpp | 7 +++++++ src/cascadia/TerminalCore/TerminalDispatch.hpp | 1 + src/terminal/adapter/DispatchTypes.hpp | 2 +- src/terminal/adapter/ITermDispatch.hpp | 2 +- src/terminal/adapter/adaptDispatch.cpp | 5 +++++ src/terminal/adapter/adaptDispatch.hpp | 1 + src/terminal/adapter/termDispatch.hpp | 1 + src/terminal/parser/OutputStateMachineEngine.cpp | 12 +++++++++++- src/terminal/parser/OutputStateMachineEngine.hpp | 2 +- 13 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/cascadia/TerminalCore/ITerminalApi.hpp b/src/cascadia/TerminalCore/ITerminalApi.hpp index 98945de1cfe..b19c29185c3 100644 --- a/src/cascadia/TerminalCore/ITerminalApi.hpp +++ b/src/cascadia/TerminalCore/ITerminalApi.hpp @@ -40,6 +40,7 @@ namespace Microsoft::Terminal::Core virtual bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept = 0; virtual bool SetCursorColor(const DWORD color) noexcept = 0; + virtual bool RestoreCursorStyleToUserDefault() noexcept = 0; virtual bool SetDefaultForeground(const DWORD color) noexcept = 0; virtual bool SetDefaultBackground(const DWORD color) noexcept = 0; diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index f6b3950a262..15c6a0ad312 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -134,6 +134,10 @@ void Terminal::UpdateSettings(ICoreSettings settings) cursorShape); } + _defaultCursorHeight = settings.CursorHeight(); + _defaultCursorColor = settings.CursorColor(); + _defaultCursorShape = cursorShape; + for (int i = 0; i < 16; i++) { _colorTable.at(i) = settings.GetColorTableEntry(i); diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index df70bc0184c..af4eb79c2ad 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -94,6 +94,7 @@ class Microsoft::Terminal::Core::Terminal final : bool SetColorTableEntry(const size_t tableIndex, const COLORREF color) noexcept override; bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept override; bool SetCursorColor(const COLORREF color) noexcept override; + bool RestoreCursorStyleToUserDefault() noexcept override; bool SetDefaultForeground(const COLORREF color) noexcept override; bool SetDefaultBackground(const COLORREF color) noexcept override; @@ -214,6 +215,9 @@ class Microsoft::Terminal::Core::Terminal final : std::array _colorTable; COLORREF _defaultFg; COLORREF _defaultBg; + ULONG _defaultCursorHeight; + COLORREF _defaultCursorColor; + CursorType _defaultCursorShape; bool _screenReversed; bool _snapOnInput; diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 1e27a59702c..a13cb90c0d9 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -426,6 +426,18 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex return true; } +bool Terminal::RestoreCursorStyleToUserDefault() noexcept +{ + if (_buffer) + { + _buffer->GetCursor().SetStyle(_defaultCursorHeight, + _defaultCursorColor, + _defaultCursorShape); + } + + return true; +} + // Method Description: // - Updates the default foreground color from a COLORREF, format 0x00BBGGRR. // Arguments: diff --git a/src/cascadia/TerminalCore/TerminalDispatch.cpp b/src/cascadia/TerminalCore/TerminalDispatch.cpp index f119cc266c7..d150f3a23b4 100644 --- a/src/cascadia/TerminalCore/TerminalDispatch.cpp +++ b/src/cascadia/TerminalCore/TerminalDispatch.cpp @@ -153,6 +153,13 @@ try } CATCH_LOG_RETURN_FALSE() +bool TerminalDispatch::RestoreCursorStyleToUserDefault() noexcept +try +{ + return _terminalApi.RestoreCursorStyleToUserDefault(); +} +CATCH_LOG_RETURN_FALSE() + bool TerminalDispatch::SetClipboard(std::wstring_view content) noexcept try { diff --git a/src/cascadia/TerminalCore/TerminalDispatch.hpp b/src/cascadia/TerminalCore/TerminalDispatch.hpp index 4f3dc8e7371..48d98cba4a9 100644 --- a/src/cascadia/TerminalCore/TerminalDispatch.hpp +++ b/src/cascadia/TerminalCore/TerminalDispatch.hpp @@ -36,6 +36,7 @@ class TerminalDispatch : public Microsoft::Console::VirtualTerminal::TermDispatc bool SetColorTableEntry(const size_t tableIndex, const DWORD color) noexcept override; bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept override; bool SetCursorColor(const DWORD color) noexcept override; + bool RestoreCursorStyleToUserDefault() noexcept override; bool SetClipboard(std::wstring_view content) noexcept override; diff --git a/src/terminal/adapter/DispatchTypes.hpp b/src/terminal/adapter/DispatchTypes.hpp index 1454ed279e4..9821592a71e 100644 --- a/src/terminal/adapter/DispatchTypes.hpp +++ b/src/terminal/adapter/DispatchTypes.hpp @@ -216,7 +216,7 @@ namespace Microsoft::Console::VirtualTerminal::DispatchTypes enum class CursorStyle : unsigned int { - BlinkingBlock = 0, + BlinkingBlock = 0, // Implemented as "restore cursor to user default". BlinkingBlockDefault = 1, SteadyBlock = 2, BlinkingUnderline = 3, diff --git a/src/terminal/adapter/ITermDispatch.hpp b/src/terminal/adapter/ITermDispatch.hpp index b90705ac4a9..73efea8edeb 100644 --- a/src/terminal/adapter/ITermDispatch.hpp +++ b/src/terminal/adapter/ITermDispatch.hpp @@ -111,7 +111,7 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch virtual bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) = 0; // DECSCUSR virtual bool SetCursorColor(const COLORREF color) = 0; // OSCSetCursorColor, OSCResetCursorColor - + virtual bool RestoreCursorStyleToUserDefault() = 0; // DECSCUSR "0" virtual bool SetClipboard(std::wstring_view content) = 0; // OSCSetClipboard // DTTERM_WindowManipulation diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index d435498c322..82fb48f5019 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2222,6 +2222,11 @@ bool AdaptDispatch::SetCursorColor(const COLORREF cursorColor) return _pConApi->SetCursorColor(cursorColor); } +bool AdaptDispatch::RestoreCursorStyleToUserDefault() noexcept +{ + return true; +} + // Routine Description: // - OSC Copy to Clipboard // Arguments: diff --git a/src/terminal/adapter/adaptDispatch.hpp b/src/terminal/adapter/adaptDispatch.hpp index 2e5f27a7823..0cc5a077dd2 100644 --- a/src/terminal/adapter/adaptDispatch.hpp +++ b/src/terminal/adapter/adaptDispatch.hpp @@ -107,6 +107,7 @@ namespace Microsoft::Console::VirtualTerminal bool EnableAlternateScroll(const bool enabled) override; // ?1007 bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) override; // DECSCUSR bool SetCursorColor(const COLORREF cursorColor) override; + bool RestoreCursorStyleToUserDefault() noexcept override; // DECSCUSR "0" bool SetClipboard(const std::wstring_view content) noexcept override; // OSCSetClipboard diff --git a/src/terminal/adapter/termDispatch.hpp b/src/terminal/adapter/termDispatch.hpp index 47ecd990784..c3ca0fef170 100644 --- a/src/terminal/adapter/termDispatch.hpp +++ b/src/terminal/adapter/termDispatch.hpp @@ -105,6 +105,7 @@ class Microsoft::Console::VirtualTerminal::TermDispatch : public Microsoft::Cons bool SetCursorStyle(const DispatchTypes::CursorStyle /*cursorStyle*/) noexcept override { return false; } // DECSCUSR bool SetCursorColor(const COLORREF /*color*/) noexcept override { return false; } // OSCSetCursorColor, OSCResetCursorColor + bool RestoreCursorStyleToUserDefault() noexcept override { return false; } // DECSCUSR "0" bool SetClipboard(std::wstring_view /*content*/) noexcept override { return false; } // OscSetClipboard diff --git a/src/terminal/parser/OutputStateMachineEngine.cpp b/src/terminal/parser/OutputStateMachineEngine.cpp index cdecc28bbd8..d796457f964 100644 --- a/src/terminal/parser/OutputStateMachineEngine.cpp +++ b/src/terminal/parser/OutputStateMachineEngine.cpp @@ -662,7 +662,17 @@ bool OutputStateMachineEngine::ActionCsiDispatch(const VTID id, gsl::spanSetCursorStyle(cursorStyle); + if (cursorStyle == DispatchTypes::CursorStyle::BlinkingBlock) + { + // Treat DECSCUSR "0" as "restore cursor to user default". + // See:GH:#1604 + success = _dispatch->RestoreCursorStyleToUserDefault(); + } + else + { + success = _dispatch->SetCursorStyle(cursorStyle); + } + TermTelemetry::Instance().Log(TermTelemetry::Codes::DECSCUSR); break; case CsiActionCodes::DECSTR_SoftReset: diff --git a/src/terminal/parser/OutputStateMachineEngine.hpp b/src/terminal/parser/OutputStateMachineEngine.hpp index e6332a076e1..27fa093985e 100644 --- a/src/terminal/parser/OutputStateMachineEngine.hpp +++ b/src/terminal/parser/OutputStateMachineEngine.hpp @@ -238,7 +238,7 @@ namespace Microsoft::Console::VirtualTerminal bool _GetOscSetColor(const std::wstring_view string, DWORD& rgb) const noexcept; - static constexpr DispatchTypes::CursorStyle DefaultCursorStyle = DispatchTypes::CursorStyle::BlinkingBlockDefault; + static constexpr DispatchTypes::CursorStyle DefaultCursorStyle = DispatchTypes::CursorStyle::BlinkingBlock; bool _GetCursorStyle(const gsl::span parameters, DispatchTypes::CursorStyle& cursorStyle) const noexcept; From d4bf404dcabe90dd09edf2bab62f8028c20fe1a5 Mon Sep 17 00:00:00 2001 From: skyline75489 Date: Mon, 24 Aug 2020 20:11:12 +0800 Subject: [PATCH 02/13] Fix --- src/terminal/adapter/adaptDispatch.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index 82fb48f5019..33b101da14f 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2222,9 +2222,13 @@ bool AdaptDispatch::SetCursorColor(const COLORREF cursorColor) return _pConApi->SetCursorColor(cursorColor); } +// Method Description: +// - Restore the cursor style to user's default setting. +// Return Value: +// True if handled successfully. False otherwise. bool AdaptDispatch::RestoreCursorStyleToUserDefault() noexcept { - return true; + return false; } // Routine Description: From 93aa1d8abe475d819b039d387e7ab390c95ed30a Mon Sep 17 00:00:00 2001 From: skyline75489 Date: Mon, 24 Aug 2020 20:15:03 +0800 Subject: [PATCH 03/13] Style --- src/terminal/adapter/ITermDispatch.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/terminal/adapter/ITermDispatch.hpp b/src/terminal/adapter/ITermDispatch.hpp index 73efea8edeb..dd05288eb8e 100644 --- a/src/terminal/adapter/ITermDispatch.hpp +++ b/src/terminal/adapter/ITermDispatch.hpp @@ -112,6 +112,7 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch virtual bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) = 0; // DECSCUSR virtual bool SetCursorColor(const COLORREF color) = 0; // OSCSetCursorColor, OSCResetCursorColor virtual bool RestoreCursorStyleToUserDefault() = 0; // DECSCUSR "0" + virtual bool SetClipboard(std::wstring_view content) = 0; // OSCSetClipboard // DTTERM_WindowManipulation From 76e6329db8440cb80708335e0938e3c55a9c7dfc Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Tue, 25 Aug 2020 14:32:21 +0800 Subject: [PATCH 04/13] Comment --- src/cascadia/TerminalCore/ITerminalApi.hpp | 1 - src/cascadia/TerminalCore/Terminal.hpp | 1 - src/cascadia/TerminalCore/TerminalApi.cpp | 19 +++++-------------- .../TerminalCore/TerminalDispatch.cpp | 7 ------- .../TerminalCore/TerminalDispatch.hpp | 1 - src/terminal/adapter/DispatchTypes.hpp | 4 ++-- src/terminal/adapter/ITermDispatch.hpp | 1 - src/terminal/adapter/adaptDispatch.cpp | 6 ------ src/terminal/adapter/adaptDispatch.hpp | 1 - src/terminal/adapter/termDispatch.hpp | 1 - .../parser/OutputStateMachineEngine.cpp | 12 +----------- 11 files changed, 8 insertions(+), 46 deletions(-) diff --git a/src/cascadia/TerminalCore/ITerminalApi.hpp b/src/cascadia/TerminalCore/ITerminalApi.hpp index b19c29185c3..98945de1cfe 100644 --- a/src/cascadia/TerminalCore/ITerminalApi.hpp +++ b/src/cascadia/TerminalCore/ITerminalApi.hpp @@ -40,7 +40,6 @@ namespace Microsoft::Terminal::Core virtual bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept = 0; virtual bool SetCursorColor(const DWORD color) noexcept = 0; - virtual bool RestoreCursorStyleToUserDefault() noexcept = 0; virtual bool SetDefaultForeground(const DWORD color) noexcept = 0; virtual bool SetDefaultBackground(const DWORD color) noexcept = 0; diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index af4eb79c2ad..3fa5edc9566 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -94,7 +94,6 @@ class Microsoft::Terminal::Core::Terminal final : bool SetColorTableEntry(const size_t tableIndex, const COLORREF color) noexcept override; bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept override; bool SetCursorColor(const COLORREF color) noexcept override; - bool RestoreCursorStyleToUserDefault() noexcept override; bool SetDefaultForeground(const COLORREF color) noexcept override; bool SetDefaultBackground(const COLORREF color) noexcept override; diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index a13cb90c0d9..80074cb8883 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -389,8 +389,11 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex switch (cursorStyle) { - case DispatchTypes::CursorStyle::BlinkingBlockDefault: - [[fallthrough]]; + case DispatchTypes::CursorStyle::RestoreUserDefault: + _buffer->GetCursor().SetStyle(_defaultCursorHeight, + _defaultCursorColor, + _defaultCursorShape); + return true; case DispatchTypes::CursorStyle::BlinkingBlock: finalCursorType = CursorType::FullBox; shouldBlink = true; @@ -426,18 +429,6 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex return true; } -bool Terminal::RestoreCursorStyleToUserDefault() noexcept -{ - if (_buffer) - { - _buffer->GetCursor().SetStyle(_defaultCursorHeight, - _defaultCursorColor, - _defaultCursorShape); - } - - return true; -} - // Method Description: // - Updates the default foreground color from a COLORREF, format 0x00BBGGRR. // Arguments: diff --git a/src/cascadia/TerminalCore/TerminalDispatch.cpp b/src/cascadia/TerminalCore/TerminalDispatch.cpp index d150f3a23b4..f119cc266c7 100644 --- a/src/cascadia/TerminalCore/TerminalDispatch.cpp +++ b/src/cascadia/TerminalCore/TerminalDispatch.cpp @@ -153,13 +153,6 @@ try } CATCH_LOG_RETURN_FALSE() -bool TerminalDispatch::RestoreCursorStyleToUserDefault() noexcept -try -{ - return _terminalApi.RestoreCursorStyleToUserDefault(); -} -CATCH_LOG_RETURN_FALSE() - bool TerminalDispatch::SetClipboard(std::wstring_view content) noexcept try { diff --git a/src/cascadia/TerminalCore/TerminalDispatch.hpp b/src/cascadia/TerminalCore/TerminalDispatch.hpp index 48d98cba4a9..4f3dc8e7371 100644 --- a/src/cascadia/TerminalCore/TerminalDispatch.hpp +++ b/src/cascadia/TerminalCore/TerminalDispatch.hpp @@ -36,7 +36,6 @@ class TerminalDispatch : public Microsoft::Console::VirtualTerminal::TermDispatc bool SetColorTableEntry(const size_t tableIndex, const DWORD color) noexcept override; bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept override; bool SetCursorColor(const DWORD color) noexcept override; - bool RestoreCursorStyleToUserDefault() noexcept override; bool SetClipboard(std::wstring_view content) noexcept override; diff --git a/src/terminal/adapter/DispatchTypes.hpp b/src/terminal/adapter/DispatchTypes.hpp index 9821592a71e..b8d2af6a4aa 100644 --- a/src/terminal/adapter/DispatchTypes.hpp +++ b/src/terminal/adapter/DispatchTypes.hpp @@ -216,8 +216,8 @@ namespace Microsoft::Console::VirtualTerminal::DispatchTypes enum class CursorStyle : unsigned int { - BlinkingBlock = 0, // Implemented as "restore cursor to user default". - BlinkingBlockDefault = 1, + RestoreUserDefault = 0, // Implemented as "restore cursor to user default". + BlinkingBlock = 1, SteadyBlock = 2, BlinkingUnderline = 3, SteadyUnderline = 4, diff --git a/src/terminal/adapter/ITermDispatch.hpp b/src/terminal/adapter/ITermDispatch.hpp index 73efea8edeb..fd57f71de3d 100644 --- a/src/terminal/adapter/ITermDispatch.hpp +++ b/src/terminal/adapter/ITermDispatch.hpp @@ -111,7 +111,6 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch virtual bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) = 0; // DECSCUSR virtual bool SetCursorColor(const COLORREF color) = 0; // OSCSetCursorColor, OSCResetCursorColor - virtual bool RestoreCursorStyleToUserDefault() = 0; // DECSCUSR "0" virtual bool SetClipboard(std::wstring_view content) = 0; // OSCSetClipboard // DTTERM_WindowManipulation diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index 82fb48f5019..e077a515c86 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2161,7 +2161,6 @@ bool AdaptDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) switch (cursorStyle) { case DispatchTypes::CursorStyle::BlinkingBlock: - case DispatchTypes::CursorStyle::BlinkingBlockDefault: fEnableBlinking = true; actualType = CursorType::FullBox; break; @@ -2222,11 +2221,6 @@ bool AdaptDispatch::SetCursorColor(const COLORREF cursorColor) return _pConApi->SetCursorColor(cursorColor); } -bool AdaptDispatch::RestoreCursorStyleToUserDefault() noexcept -{ - return true; -} - // Routine Description: // - OSC Copy to Clipboard // Arguments: diff --git a/src/terminal/adapter/adaptDispatch.hpp b/src/terminal/adapter/adaptDispatch.hpp index 0cc5a077dd2..2e5f27a7823 100644 --- a/src/terminal/adapter/adaptDispatch.hpp +++ b/src/terminal/adapter/adaptDispatch.hpp @@ -107,7 +107,6 @@ namespace Microsoft::Console::VirtualTerminal bool EnableAlternateScroll(const bool enabled) override; // ?1007 bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) override; // DECSCUSR bool SetCursorColor(const COLORREF cursorColor) override; - bool RestoreCursorStyleToUserDefault() noexcept override; // DECSCUSR "0" bool SetClipboard(const std::wstring_view content) noexcept override; // OSCSetClipboard diff --git a/src/terminal/adapter/termDispatch.hpp b/src/terminal/adapter/termDispatch.hpp index c3ca0fef170..47ecd990784 100644 --- a/src/terminal/adapter/termDispatch.hpp +++ b/src/terminal/adapter/termDispatch.hpp @@ -105,7 +105,6 @@ class Microsoft::Console::VirtualTerminal::TermDispatch : public Microsoft::Cons bool SetCursorStyle(const DispatchTypes::CursorStyle /*cursorStyle*/) noexcept override { return false; } // DECSCUSR bool SetCursorColor(const COLORREF /*color*/) noexcept override { return false; } // OSCSetCursorColor, OSCResetCursorColor - bool RestoreCursorStyleToUserDefault() noexcept override { return false; } // DECSCUSR "0" bool SetClipboard(std::wstring_view /*content*/) noexcept override { return false; } // OscSetClipboard diff --git a/src/terminal/parser/OutputStateMachineEngine.cpp b/src/terminal/parser/OutputStateMachineEngine.cpp index d796457f964..cdecc28bbd8 100644 --- a/src/terminal/parser/OutputStateMachineEngine.cpp +++ b/src/terminal/parser/OutputStateMachineEngine.cpp @@ -662,17 +662,7 @@ bool OutputStateMachineEngine::ActionCsiDispatch(const VTID id, gsl::spanRestoreCursorStyleToUserDefault(); - } - else - { - success = _dispatch->SetCursorStyle(cursorStyle); - } - + success = _dispatch->SetCursorStyle(cursorStyle); TermTelemetry::Instance().Log(TermTelemetry::Codes::DECSCUSR); break; case CsiActionCodes::DECSTR_SoftReset: From 5de7e1ac3074d7d650829ff3b79fdd48a69d9304 Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Tue, 25 Aug 2020 14:40:56 +0800 Subject: [PATCH 05/13] Naming --- src/cascadia/TerminalCore/TerminalApi.cpp | 2 +- src/terminal/adapter/DispatchTypes.hpp | 2 +- src/terminal/parser/OutputStateMachineEngine.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 80074cb8883..c3e8bc48c99 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -389,7 +389,7 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex switch (cursorStyle) { - case DispatchTypes::CursorStyle::RestoreUserDefault: + case DispatchTypes::CursorStyle::UserDefault: _buffer->GetCursor().SetStyle(_defaultCursorHeight, _defaultCursorColor, _defaultCursorShape); diff --git a/src/terminal/adapter/DispatchTypes.hpp b/src/terminal/adapter/DispatchTypes.hpp index b8d2af6a4aa..0eccfff2220 100644 --- a/src/terminal/adapter/DispatchTypes.hpp +++ b/src/terminal/adapter/DispatchTypes.hpp @@ -216,7 +216,7 @@ namespace Microsoft::Console::VirtualTerminal::DispatchTypes enum class CursorStyle : unsigned int { - RestoreUserDefault = 0, // Implemented as "restore cursor to user default". + UserDefault = 0, // Implemented as "restore cursor to user default". BlinkingBlock = 1, SteadyBlock = 2, BlinkingUnderline = 3, diff --git a/src/terminal/parser/OutputStateMachineEngine.hpp b/src/terminal/parser/OutputStateMachineEngine.hpp index 27fa093985e..f37736b26e8 100644 --- a/src/terminal/parser/OutputStateMachineEngine.hpp +++ b/src/terminal/parser/OutputStateMachineEngine.hpp @@ -238,7 +238,7 @@ namespace Microsoft::Console::VirtualTerminal bool _GetOscSetColor(const std::wstring_view string, DWORD& rgb) const noexcept; - static constexpr DispatchTypes::CursorStyle DefaultCursorStyle = DispatchTypes::CursorStyle::BlinkingBlock; + static constexpr DispatchTypes::CursorStyle DefaultCursorStyle = DispatchTypes::CursorStyle::UserDefault; bool _GetCursorStyle(const gsl::span parameters, DispatchTypes::CursorStyle& cursorStyle) const noexcept; From 4c5bdf8951bca3fdefbf07498c472487f1cac5f4 Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Tue, 25 Aug 2020 14:45:04 +0800 Subject: [PATCH 06/13] Oh well --- src/cascadia/TerminalCore/TerminalApi.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index c3e8bc48c99..accfb168150 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -390,9 +390,7 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex switch (cursorStyle) { case DispatchTypes::CursorStyle::UserDefault: - _buffer->GetCursor().SetStyle(_defaultCursorHeight, - _defaultCursorColor, - _defaultCursorShape); + finalCursorType = _defaultCursorShape; return true; case DispatchTypes::CursorStyle::BlinkingBlock: finalCursorType = CursorType::FullBox; From 96dbe121380d929768116f57e6a9a914ca4e8963 Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Tue, 25 Aug 2020 14:49:29 +0800 Subject: [PATCH 07/13] Unused --- src/cascadia/TerminalCore/Terminal.cpp | 2 -- src/cascadia/TerminalCore/Terminal.hpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 15c6a0ad312..ff6560e2ed0 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -134,8 +134,6 @@ void Terminal::UpdateSettings(ICoreSettings settings) cursorShape); } - _defaultCursorHeight = settings.CursorHeight(); - _defaultCursorColor = settings.CursorColor(); _defaultCursorShape = cursorShape; for (int i = 0; i < 16; i++) diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 3fa5edc9566..6aed9e42b20 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -214,8 +214,6 @@ class Microsoft::Terminal::Core::Terminal final : std::array _colorTable; COLORREF _defaultFg; COLORREF _defaultBg; - ULONG _defaultCursorHeight; - COLORREF _defaultCursorColor; CursorType _defaultCursorShape; bool _screenReversed; From 2915aff1b2824be62b20510d05368e9627790ec4 Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Tue, 25 Aug 2020 17:43:02 +0800 Subject: [PATCH 08/13] Should you blink, sir --- src/cascadia/TerminalCore/TerminalApi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index accfb168150..da65e68640a 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -391,6 +391,7 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex { case DispatchTypes::CursorStyle::UserDefault: finalCursorType = _defaultCursorShape; + shouldBlink = true; return true; case DispatchTypes::CursorStyle::BlinkingBlock: finalCursorType = CursorType::FullBox; From e200a32324f054f3b03a32f800667edc9d78c378 Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Fri, 28 Aug 2020 14:58:14 +0800 Subject: [PATCH 09/13] Push --- src/cascadia/TerminalCore/TerminalApi.cpp | 5 ++--- src/host/outputStream.cpp | 13 +++++++++++++ src/host/outputStream.hpp | 1 + src/terminal/adapter/adaptDispatch.cpp | 4 ++++ src/terminal/adapter/conGetSet.hpp | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index da65e68640a..f846c466415 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -392,7 +392,7 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex case DispatchTypes::CursorStyle::UserDefault: finalCursorType = _defaultCursorShape; shouldBlink = true; - return true; + break; case DispatchTypes::CursorStyle::BlinkingBlock: finalCursorType = CursorType::FullBox; shouldBlink = true; @@ -418,8 +418,7 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex shouldBlink = false; break; default: - finalCursorType = CursorType::Legacy; - shouldBlink = false; + return true; } _buffer->GetCursor().SetType(finalCursorType); diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index a4aa4c57de2..c698547ef86 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -513,6 +513,19 @@ bool ConhostInternalGetSet::PrivateEraseAll() return SUCCEEDED(DoSrvPrivateEraseAll(_io.GetActiveOutputBuffer())); } +// Method Description: +// - Retrieves the current user default cursor style. +// Arguments: +// - style - Structure to receive cursor style. +// Return Value: +// - true if successful. false otherwise. +bool ConhostInternalGetSet::GetUserDefaultCursorStyle(CursorType& style) +{ + const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); + style = gci.GetCursorType(); + return true; +} + // Routine Description: // - Connects the SetCursorStyle call directly into our Driver Message servicing call inside Conhost.exe // SetCursorStyle is an internal-only "API" call that the vt commands can execute, diff --git a/src/host/outputStream.hpp b/src/host/outputStream.hpp index a2671396583..0323ae4c5e3 100644 --- a/src/host/outputStream.hpp +++ b/src/host/outputStream.hpp @@ -107,6 +107,7 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal:: bool PrivatePrependConsoleInput(std::deque>& events, size_t& eventsWritten) override; + bool GetUserDefaultCursorStyle(CursorType& style) override; bool SetCursorStyle(CursorType const style) override; bool SetCursorColor(COLORREF const color) override; diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index e077a515c86..121d0f0f9cb 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2160,6 +2160,10 @@ bool AdaptDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) switch (cursorStyle) { + case DispatchTypes::CursorStyle::UserDefault: + _pConApi->GetUserDefaultCursorStyle(actualType); + fEnableBlinking = true; + break; case DispatchTypes::CursorStyle::BlinkingBlock: fEnableBlinking = true; actualType = CursorType::FullBox; diff --git a/src/terminal/adapter/conGetSet.hpp b/src/terminal/adapter/conGetSet.hpp index ddf6c2624e4..555668c3d14 100644 --- a/src/terminal/adapter/conGetSet.hpp +++ b/src/terminal/adapter/conGetSet.hpp @@ -70,6 +70,7 @@ namespace Microsoft::Console::VirtualTerminal virtual bool PrivateEnableAnyEventMouseMode(const bool enabled) = 0; virtual bool PrivateEnableAlternateScroll(const bool enabled) = 0; virtual bool PrivateEraseAll() = 0; + virtual bool GetUserDefaultCursorStyle(CursorType& style) = 0; virtual bool SetCursorStyle(const CursorType style) = 0; virtual bool SetCursorColor(const COLORREF color) = 0; virtual bool PrivatePrependConsoleInput(std::deque>& events, From 3a186addffd2c6821e4797079e8b0705b6a8889f Mon Sep 17 00:00:00 2001 From: skyline75489 Date: Fri, 28 Aug 2020 21:13:45 +0800 Subject: [PATCH 10/13] Fix --- src/terminal/adapter/ut_adapter/adapterTest.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 92b295667ab..cd1ea8ebaaa 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -434,6 +434,12 @@ class TestGetSet final : public ConGetSet return TRUE; } + bool GetUserDefaultCursorStyle(CursorType& style) override + { + style = CursorType::Legacy; + return TRUE; + } + bool SetCursorStyle(const CursorType cursorType) override { Log::Comment(L"SetCursorStyle MOCK called..."); From c4ae1dcb8802507e9c23a9ce5d9ececdabb588f6 Mon Sep 17 00:00:00 2001 From: skyline75489 Date: Sun, 30 Aug 2020 16:57:56 +0800 Subject: [PATCH 11/13] AdaptDispatch --- src/cascadia/TerminalCore/TerminalApi.cpp | 2 ++ src/terminal/adapter/adaptDispatch.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index f846c466415..78d7fe21d34 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -417,7 +417,9 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex finalCursorType = CursorType::VerticalBar; shouldBlink = false; break; + default: + // Invalid argument should be ignored. return true; } diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index 121d0f0f9cb..c3cf6af1604 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2190,6 +2190,10 @@ bool AdaptDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) fEnableBlinking = false; actualType = CursorType::VerticalBar; break; + + default: + // Invalid argument should be ignored. + return true; } bool success = _pConApi->SetCursorStyle(actualType); From c38f9a3d05ebba5122bbfff716dfb1d12ada673f Mon Sep 17 00:00:00 2001 From: skyline75489 Date: Sun, 30 Aug 2020 22:01:05 +0800 Subject: [PATCH 12/13] Resolve comments --- src/terminal/adapter/adaptDispatch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index c3cf6af1604..78d009a2059 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2192,8 +2192,8 @@ bool AdaptDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) break; default: - // Invalid argument should be ignored. - return true; + // Invalid argument should be handled by the connected terminal. + return false; } bool success = _pConApi->SetCursorStyle(actualType); From 88432d36ff28d14fed1f6db3f5dc9e2aec41a18d Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Fri, 4 Sep 2020 13:04:44 -0700 Subject: [PATCH 13/13] Update src/terminal/adapter/ut_adapter/adapterTest.cpp --- src/terminal/adapter/ut_adapter/adapterTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index cd1ea8ebaaa..993dcd8b883 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -437,7 +437,7 @@ class TestGetSet final : public ConGetSet bool GetUserDefaultCursorStyle(CursorType& style) override { style = CursorType::Legacy; - return TRUE; + return true; } bool SetCursorStyle(const CursorType cursorType) override