mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-19 10:12:50 +08:00
151 lines
4.0 KiB
C#
151 lines
4.0 KiB
C#
namespace Spectre.Console;
|
|
|
|
/// <summary>
|
|
/// Contains extension methods for <see cref="IAnsiConsoleCursor"/>.
|
|
/// </summary>
|
|
public static class CursorExtensions
|
|
{
|
|
/// <summary>
|
|
/// Shows the cursor.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
public static void Show(this IAnsiConsoleCursor cursor)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Show(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hides the cursor.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
public static void Hide(this IAnsiConsoleCursor cursor)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Show(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor up.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
public static void MoveUp(this IAnsiConsoleCursor cursor)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Up, 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor up.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
|
public static void MoveUp(this IAnsiConsoleCursor cursor, int steps)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Up, steps);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor down.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
public static void MoveDown(this IAnsiConsoleCursor cursor)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Down, 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor down.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
|
public static void MoveDown(this IAnsiConsoleCursor cursor, int steps)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Down, steps);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor to the left.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
public static void MoveLeft(this IAnsiConsoleCursor cursor)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Left, 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor to the left.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
|
public static void MoveLeft(this IAnsiConsoleCursor cursor, int steps)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Left, steps);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor to the right.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
public static void MoveRight(this IAnsiConsoleCursor cursor)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Right, 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor to the right.
|
|
/// </summary>
|
|
/// <param name="cursor">The cursor.</param>
|
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
|
public static void MoveRight(this IAnsiConsoleCursor cursor, int steps)
|
|
{
|
|
if (cursor is null)
|
|
{
|
|
throw new System.ArgumentNullException(nameof(cursor));
|
|
}
|
|
|
|
cursor.Move(CursorDirection.Right, steps);
|
|
}
|
|
} |