Skip to content

Commit

Permalink
added ability to pick the cursor style when using cursor brush.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Dec 17, 2024
1 parent aaf951a commit 4b97ba4
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 177 deletions.
12 changes: 12 additions & 0 deletions src/Consolonia.Core/Drawing/CursorStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Consolonia.Core.Drawing
{
public enum CursorStyle
{
BlinkingBar,
SteadyBar,
BlinkingBlock,
SteadyBlock,
BlinkingUnderline,
SteadyUnderline,

Check notice on line 10 in src/Consolonia.Core/Drawing/CursorStyle.cs

View workflow job for this annotation

GitHub Actions / build

"[ArrangeTrailingCommaInMultilineLists] Remove trailing comma to conform to code style" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/CursorStyle.cs(10,24)
}
}
354 changes: 178 additions & 176 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public class MoveConsoleCaretToPositionBrush : IImmutableBrush
public double Opacity => 1;
public ITransform Transform => null;
public RelativePoint TransformOrigin => RelativePoint.TopLeft;

/// <summary>
/// style of curosr
/// </summary>
public CursorStyle Style { get; set; } = CursorStyle.BlinkingBar;

Check notice on line 16 in src/Consolonia.Core/Drawing/MoveConsoleCaretToPositionBrush.cs

View workflow job for this annotation

GitHub Actions / build

"[AutoPropertyCanBeMadeGetOnly.Global] Auto-property can be made get-only" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/MoveConsoleCaretToPositionBrush.cs(16,41)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public PixelBuffer(ushort width, ushort height)
public ushort Width { get; }
public ushort Height { get; }

public CursorStyle CursorStyle { get; set; } = CursorStyle.BlinkingBar;

// ReSharper disable once UnusedMember.Global
[JsonIgnore]
public Pixel this[int i]
Expand Down
14 changes: 14 additions & 0 deletions src/Consolonia.Core/Drawing/RenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Avalonia.Platform;
using Consolonia.Core.Drawing.PixelBufferImplementation;
using Consolonia.Core.Infrastructure;
using Consolonia.Core.Text;
using Newtonsoft.Json.Linq;

Check warning on line 14 in src/Consolonia.Core/Drawing/RenderTarget.cs

View workflow job for this annotation

GitHub Actions / build

"[RedundantUsingDirective] Using directive is not required by the code and can be safely removed" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/RenderTarget.cs(14,1)

namespace Consolonia.Core.Drawing
{
Expand Down Expand Up @@ -141,11 +143,23 @@ private void RenderToDevice()
if (caretPosition != null)
{
_console.SetCaretPosition((PixelBufferCoordinate)caretPosition);
_console.WriteText(pixelBuffer.CursorStyle switch
{
CursorStyle.BlinkingBar => Esc.BlinkingBarCursor,
CursorStyle.SteadyBar => Esc.SteadyBarCursor,
CursorStyle.BlinkingBlock => Esc.BlinkingBlockCursor,
CursorStyle.SteadyBlock => Esc.SteadyBlockCursor,
CursorStyle.BlinkingUnderline => Esc.BlinkingUnderlineCursor,
CursorStyle.SteadyUnderline => Esc.SteadyUnderlineCursor,
_ => throw new ArgumentOutOfRangeException()
});
_console.WriteText(Esc.ShowCursor);
_console.CaretVisible = true;
}
else
{
_console.CaretVisible = false;
_console.WriteText(Esc.HideCursor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public bool CaretVisible
set
{
if (_caretVisible == value) return;

Check warning on line 41 in src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs

View workflow job for this annotation

GitHub Actions / build

"[RedundantCheckBeforeAssignment] Redundant check before assignment" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs(41,21)
WriteText(value ? Esc.ShowCursor : Esc.HideCursor);
_caretVisible = value;
}
#pragma warning restore CA1303 // Do not pass literals as localized parameters
Expand Down
8 changes: 8 additions & 0 deletions src/Consolonia.Core/Text/Esc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ internal static class Esc
public const string HideCursor = "\u001b[?25l";
public const string ShowCursor = "\u001b[?25h";

// cursor shape
public const string BlinkingBlockCursor = "\u001b[1 q";
public const string SteadyBlockCursor = "\u001b[2 q";
public const string BlinkingUnderlineCursor = "\u001b[3 q";
public const string SteadyUnderlineCursor = "\u001b[4 q";
public const string BlinkingBarCursor = "\u001b[5 q";
public const string SteadyBarCursor = "\u001b[6 q";

// move cursor
public static string MoveCursorUp(int n)
{
Expand Down

0 comments on commit 4b97ba4

Please sign in to comment.