Skip to content

Commit

Permalink
Utils and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbilas committed Aug 18, 2024
1 parent d102d42 commit 79c275b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Core.Terminal/ControlBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ public static ControlBuilder ResetScrollMargin(this ControlBuilder @this) =>
public static ControlBuilder ReverseLineFeed(this ControlBuilder @this) =>
@this.Print(ESC).Print(['M']); // this is reverse index (M), not reverse line feed (H), but this is supported much better and does the same thing according to docs

public static AutoSaveRestoreCursorState AutoSaveRestoreCursorState(this ControlBuilder @this) =>
public static AutoSaveRestoreCursorState SaveRestoreCursor(this ControlBuilder @this) =>
new(@this);

public static AutoSaveRestoreCursorState SaveRestoreCursor(this ControlBuilder @this, int y, int x)
{
var saver = @this.SaveRestoreCursor();
@this.MoveCursorTo(y, x);
return saver;
}

// note that this will cause the cursor to move to home position. can't save/restore cursor pos because it is tied
// to cursor state, and restoring state will kill the new constrain mode.
public static ControlBuilder SetCursorConstrainMode(this ControlBuilder @this, CursorConstrainMode mode) => @this
Expand Down
7 changes: 7 additions & 0 deletions src/Core/ArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ namespace OkTools.Core;

public static class ArrayExtensions
{
public static ArraySegment<T> WithOffset<T>(this T[] @this, int offset) =>
new(@this, offset, @this.Length - offset);
public static ArraySegment<T> WithLength<T>(this T[] @this, int length) =>
new(@this, 0, length);
public static ArraySegment<T> Slice<T>(this T[] @this, int offset, int length) =>
new(@this, offset, length);

public static void ShiftLeft<T>(this T[] @this, int count)
{
Array.Copy(@this, count, @this, 0, @this.Length - count);
Expand Down
2 changes: 1 addition & 1 deletion src/Showkeys.Cli/DriveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public async Task<CliExitCode> RunAsync(bool save)
case { Char: 'l', Modifiers: ConsoleModifiers.Control }:
OutControl(cb =>
{
using var _ = cb.AutoSaveRestoreCursorState();
using var _ = cb.SaveRestoreCursor();
for (var line = _scrollTop; line <= _scrollBottom; ++line)
{
cb.MoveCursorTo(line, 0);
Expand Down

0 comments on commit 79c275b

Please sign in to comment.