Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DECSCUSR "0" to restore cursor to user default #7379

Merged
15 commits merged into from
Sep 4, 2020
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/ITerminalApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -214,6 +215,9 @@ class Microsoft::Terminal::Core::Terminal final :
std::array<COLORREF, XTERM_COLOR_TABLE_SIZE> _colorTable;
COLORREF _defaultFg;
COLORREF _defaultBg;
ULONG _defaultCursorHeight;
COLORREF _defaultCursorColor;
CursorType _defaultCursorShape;
bool _screenReversed;

bool _snapOnInput;
Expand Down
12 changes: 12 additions & 0 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
skyline75489 marked this conversation as resolved.
Show resolved Hide resolved

return true;
}

// Method Description:
// - Updates the default foreground color from a COLORREF, format 0x00BBGGRR.
// Arguments:
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalCore/TerminalDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/TerminalDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/terminal/adapter/DispatchTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
skyline75489 marked this conversation as resolved.
Show resolved Hide resolved
SteadyBlock = 2,
BlinkingUnderline = 3,
Expand Down
1 change: 1 addition & 0 deletions src/terminal/adapter/ITermDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +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

Expand Down
9 changes: 9 additions & 0 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,15 @@ 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 false;
}
skyline75489 marked this conversation as resolved.
Show resolved Hide resolved

// Routine Description:
// - OSC Copy to Clipboard
// Arguments:
Expand Down
1 change: 1 addition & 0 deletions src/terminal/adapter/adaptDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/terminal/adapter/termDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion src/terminal/parser/OutputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,17 @@ bool OutputStateMachineEngine::ActionCsiDispatch(const VTID id, gsl::span<const
TermTelemetry::Instance().Log(TermTelemetry::Codes::REP);
break;
case CsiActionCodes::DECSCUSR_SetCursorStyle:
success = _dispatch->SetCursorStyle(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);
}

skyline75489 marked this conversation as resolved.
Show resolved Hide resolved
TermTelemetry::Instance().Log(TermTelemetry::Codes::DECSCUSR);
break;
case CsiActionCodes::DECSTR_SoftReset:
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/parser/OutputStateMachineEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
skyline75489 marked this conversation as resolved.
Show resolved Hide resolved
bool _GetCursorStyle(const gsl::span<const size_t> parameters,
DispatchTypes::CursorStyle& cursorStyle) const noexcept;

Expand Down