Skip to content

Commit

Permalink
Add doubleUnderscore cursor style (microsoft#7827)
Browse files Browse the repository at this point in the history
Adds a new cursor type "doubleUnderscore". Tested manually.

Closes microsoft#6786
  • Loading branch information
rhorber authored and mpela81 committed Jan 28, 2021
1 parent 2134182 commit 92752bd
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 12 deletions.
3 changes: 2 additions & 1 deletion doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,10 @@
},
"cursorShape": {
"default": "bar",
"description": "Sets the shape of the cursor. Possible values:\n -\"bar\" ( ┃, default )\n -\"emptyBox\" ( ▯ )\n -\"filledBox\" ( █ )\n -\"underscore\" ( ▁ )\n -\"vintage\" ( ▃ )",
"description": "Sets the shape of the cursor. Possible values:\n -\"bar\" ( ┃, default )\n -\"doubleUnderscore\" ( ‗ )\n -\"emptyBox\" ( ▯ )\n -\"filledBox\" ( █ )\n -\"underscore\" ( ▁ )\n -\"vintage\" ( ▃ )",
"enum": [
"bar",
"doubleUnderscore",
"emptyBox",
"filledBox",
"underscore",
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/ICoreSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Terminal.TerminalControl
Vintage,
Bar,
Underscore,
DoubleUnderscore,
FilledBox,
EmptyBox
};
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ void Terminal::UpdateSettings(ICoreSettings settings)
case CursorStyle::Vintage:
cursorShape = CursorType::Legacy;
break;
case CursorStyle::DoubleUnderscore:
cursorShape = CursorType::DoubleUnderscore;
break;
default:
case CursorStyle::Bar:
cursorShape = CursorType::VerticalBar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@
<value>Vintage ( ▃ )</value>
<comment>{Locked="▃"}</comment>
</data>
<data name="Profile_CursorShapeDoubleUnderscore.Content" xml:space="preserve">
<value>Double Underscore ( ‗ )</value>
<comment>{Locked="‗"}</comment>
</data>
<data name="Profile_FontFace.Header" xml:space="preserve">
<value>Font face</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ Module Name:

JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::TerminalControl::CursorStyle)
{
static constexpr std::array<pair_type, 5> mappings = {
static constexpr std::array<pair_type, 6> mappings = {
pair_type{ "bar", ValueType::Bar },
pair_type{ "vintage", ValueType::Vintage },
pair_type{ "underscore", ValueType::Underscore },
pair_type{ "doubleUnderscore", ValueType::DoubleUnderscore },
pair_type{ "filledBox", ValueType::FilledBox },
pair_type{ "emptyBox", ValueType::EmptyBox }
};
Expand Down
3 changes: 2 additions & 1 deletion src/inc/conattrs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ enum class CursorType : unsigned int
VerticalBar = 0x1, // A single vertical line, '|'
Underscore = 0x2, // a single horizontal underscore, smaller that the min height legacy cursor.
EmptyBox = 0x3, // Just the outline of a full box
FullBox = 0x4 // a full box, similar to legacy with height=100%
FullBox = 0x4, // a full box, similar to legacy with height=100%
DoubleUnderscore = 0x5 // a double horizontal underscore
};

// Valid COLORREFs are of the pattern 0x00bbggrr. -1 works as an invalid color,
Expand Down
29 changes: 20 additions & 9 deletions src/renderer/dx/CustomTextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ try
}

CursorPaintType paintType = CursorPaintType::Fill;
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> brush{ drawingContext.foregroundBrush };

if (options.fUseColor)
{
// Make sure to make the cursor opaque
RETURN_IF_FAILED(d2dContext->CreateSolidColorBrush(til::color{ OPACITY_OPAQUE | options.cursorColor },
&brush));
}

switch (options.cursorType)
{
Expand All @@ -318,6 +326,18 @@ try
rect.top = rect.bottom - 1;
break;
}
case CursorType::DoubleUnderscore:
{
// Use rect for lower line.
rect.top = rect.bottom - 1;

// Draw upper line directly.
D2D1_RECT_F upperLine = rect;
upperLine.top -= 2;
upperLine.bottom -= 2;
d2dContext->FillRectangle(upperLine, brush.Get());
break;
}
case CursorType::EmptyBox:
{
paintType = CursorPaintType::Outline;
Expand All @@ -331,15 +351,6 @@ try
return E_NOTIMPL;
}

Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> brush{ drawingContext.foregroundBrush };

if (options.fUseColor)
{
// Make sure to make the cursor opaque
RETURN_IF_FAILED(d2dContext->CreateSolidColorBrush(til::color{ OPACITY_OPAQUE | options.cursorColor },
&brush));
}

switch (paintType)
{
case CursorPaintType::Fill:
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/gdi/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,19 @@ using namespace Microsoft::Console::Render;
cursorInvertRects.push_back(rcInvert);
break;

case CursorType::DoubleUnderscore:
{
RECT top, bottom;
top = bottom = rcBoundaries;
RETURN_IF_FAILED(LongAdd(bottom.bottom, -1, &bottom.top));
RETURN_IF_FAILED(LongAdd(top.bottom, -3, &top.top));
RETURN_IF_FAILED(LongAdd(top.top, 1, &top.bottom));

cursorInvertRects.push_back(top);
cursorInvertRects.push_back(bottom);
}
break;

case CursorType::EmptyBox:
{
RECT top, left, right, bottom;
Expand Down

0 comments on commit 92752bd

Please sign in to comment.