diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index f6b3950a262..ff6560e2ed0 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -134,6 +134,8 @@ void Terminal::UpdateSettings(ICoreSettings settings) cursorShape); } + _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..6aed9e42b20 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -214,6 +214,7 @@ class Microsoft::Terminal::Core::Terminal final : std::array _colorTable; COLORREF _defaultFg; COLORREF _defaultBg; + CursorType _defaultCursorShape; bool _screenReversed; bool _snapOnInput; diff --git a/src/cascadia/TerminalCore/TerminalApi.cpp b/src/cascadia/TerminalCore/TerminalApi.cpp index 1e27a59702c..78d7fe21d34 100644 --- a/src/cascadia/TerminalCore/TerminalApi.cpp +++ b/src/cascadia/TerminalCore/TerminalApi.cpp @@ -389,8 +389,10 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex switch (cursorStyle) { - case DispatchTypes::CursorStyle::BlinkingBlockDefault: - [[fallthrough]]; + case DispatchTypes::CursorStyle::UserDefault: + finalCursorType = _defaultCursorShape; + shouldBlink = true; + break; case DispatchTypes::CursorStyle::BlinkingBlock: finalCursorType = CursorType::FullBox; shouldBlink = true; @@ -415,9 +417,10 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noex finalCursorType = CursorType::VerticalBar; shouldBlink = false; break; + default: - finalCursorType = CursorType::Legacy; - shouldBlink = false; + // Invalid argument should be ignored. + 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/DispatchTypes.hpp b/src/terminal/adapter/DispatchTypes.hpp index 1454ed279e4..0eccfff2220 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, - BlinkingBlockDefault = 1, + UserDefault = 0, // Implemented as "restore cursor to user default". + BlinkingBlock = 1, SteadyBlock = 2, BlinkingUnderline = 3, SteadyUnderline = 4, diff --git a/src/terminal/adapter/adaptDispatch.cpp b/src/terminal/adapter/adaptDispatch.cpp index d435498c322..78d009a2059 100644 --- a/src/terminal/adapter/adaptDispatch.cpp +++ b/src/terminal/adapter/adaptDispatch.cpp @@ -2160,8 +2160,11 @@ bool AdaptDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) switch (cursorStyle) { + case DispatchTypes::CursorStyle::UserDefault: + _pConApi->GetUserDefaultCursorStyle(actualType); + fEnableBlinking = true; + break; case DispatchTypes::CursorStyle::BlinkingBlock: - case DispatchTypes::CursorStyle::BlinkingBlockDefault: fEnableBlinking = true; actualType = CursorType::FullBox; break; @@ -2187,6 +2190,10 @@ bool AdaptDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) fEnableBlinking = false; actualType = CursorType::VerticalBar; break; + + default: + // Invalid argument should be handled by the connected terminal. + return false; } bool success = _pConApi->SetCursorStyle(actualType); 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, diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 92b295667ab..993dcd8b883 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..."); diff --git a/src/terminal/parser/OutputStateMachineEngine.hpp b/src/terminal/parser/OutputStateMachineEngine.hpp index e6332a076e1..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::BlinkingBlockDefault; + static constexpr DispatchTypes::CursorStyle DefaultCursorStyle = DispatchTypes::CursorStyle::UserDefault; bool _GetCursorStyle(const gsl::span parameters, DispatchTypes::CursorStyle& cursorStyle) const noexcept;