mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Cleanup
This commit is contained in:
@@ -99,10 +99,8 @@ public partial class ConsoleReader : StreamReader
|
||||
|
||||
public partial class ConsoleReader
|
||||
{
|
||||
internal static ConsoleReader Create(IConsole console, Stream? stream) => new(
|
||||
internal static ConsoleReader Create(IConsole console, Stream stream) => new(
|
||||
console,
|
||||
stream is not null
|
||||
? Stream.Synchronized(stream)
|
||||
: Stream.Null
|
||||
Stream.Synchronized(stream)
|
||||
);
|
||||
}
|
||||
@@ -272,10 +272,8 @@ public partial class ConsoleWriter : StreamWriter
|
||||
|
||||
public partial class ConsoleWriter
|
||||
{
|
||||
internal static ConsoleWriter Create(IConsole console, Stream? stream) => new(
|
||||
internal static ConsoleWriter Create(IConsole console, Stream stream) => new(
|
||||
console,
|
||||
stream is not null
|
||||
? Stream.Synchronized(stream)
|
||||
: Stream.Null
|
||||
Stream.Synchronized(stream)
|
||||
) {AutoFlush = true};
|
||||
}
|
||||
@@ -59,14 +59,33 @@ public class FakeConsole : IConsole, IDisposable
|
||||
/// </summary>
|
||||
public FakeConsole(Stream? input = null, Stream? output = null, Stream? error = null)
|
||||
{
|
||||
Input = ConsoleReader.Create(this, input);
|
||||
Output = ConsoleWriter.Create(this, output);
|
||||
Error = ConsoleWriter.Create(this, error);
|
||||
Input = ConsoleReader.Create(this, input ?? Stream.Null);
|
||||
Output = ConsoleWriter.Create(this, output ?? Stream.Null);
|
||||
Error = ConsoleWriter.Create(this, error ?? Stream.Null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ConsoleKeyInfo ReadKey(bool intercept = false) =>
|
||||
_keys.TryDequeue(out var key)
|
||||
? key
|
||||
: throw new InvalidOperationException(
|
||||
"Cannot read key because there are no key presses enqueued. " +
|
||||
$"Use the `{nameof(EnqueueKey)}(...)` method to simulate a key press."
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues a simulated key press, which can then be read by calling <see cref="ReadKey"/>.
|
||||
/// </summary>
|
||||
public void EnqueueKey(ConsoleKeyInfo key) => _keys.Enqueue(key);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CancellationToken RegisterCancellationHandler() => _cancellationTokenSource.Token;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sends a cancellation signal to the currently executing command.
|
||||
/// </summary>
|
||||
@@ -87,25 +106,6 @@ public class FakeConsole : IConsole, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ConsoleKeyInfo ReadKey(bool intercept = false) =>
|
||||
_keys.TryDequeue(out var key)
|
||||
? key
|
||||
: throw new InvalidOperationException(
|
||||
"Cannot read key because there are no key presses enqueued. " +
|
||||
$"Use the `{nameof(EnqueueKey)}(...)` method to simulate a key press."
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues a simulated key press, which can then be read by calling <see cref="ReadKey"/>.
|
||||
/// </summary>
|
||||
public void EnqueueKey(ConsoleKeyInfo key) => _keys.Enqueue(key);
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose() => _cancellationTokenSource.Dispose();
|
||||
}
|
||||
@@ -64,6 +64,16 @@ public interface IConsole
|
||||
/// </summary>
|
||||
int CursorTop { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Obtains the next character or function key pressed by the user.
|
||||
/// </summary>
|
||||
ConsoleKeyInfo ReadKey(bool intercept = false);
|
||||
|
||||
/// <summary>
|
||||
/// Clears the console buffer and corresponding console window of display information.
|
||||
/// </summary>
|
||||
void Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a handler for the interrupt signal (Ctrl+C) on the console and returns
|
||||
/// a token representing the cancellation request.
|
||||
@@ -82,16 +92,6 @@ public interface IConsole
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
CancellationToken RegisterCancellationHandler();
|
||||
|
||||
/// <summary>
|
||||
/// Clears the console buffer and corresponding console window of display information.
|
||||
/// </summary>
|
||||
void Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Obtains the next character or function key pressed by the user.
|
||||
/// </summary>
|
||||
ConsoleKeyInfo ReadKey(bool intercept = false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -41,6 +41,20 @@ public class SystemConsole : IConsole, IDisposable
|
||||
get => Console.BackgroundColor;
|
||||
set => Console.BackgroundColor = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int CursorLeft
|
||||
{
|
||||
get => Console.CursorLeft;
|
||||
set => Console.CursorLeft = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int CursorTop
|
||||
{
|
||||
get => Console.CursorTop;
|
||||
set => Console.CursorTop = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="SystemConsole"/>.
|
||||
@@ -56,19 +70,11 @@ public class SystemConsole : IConsole, IDisposable
|
||||
public void ResetColor() => Console.ResetColor();
|
||||
|
||||
/// <inheritdoc />
|
||||
public int CursorLeft
|
||||
{
|
||||
get => Console.CursorLeft;
|
||||
set => Console.CursorLeft = value;
|
||||
}
|
||||
|
||||
public ConsoleKeyInfo ReadKey(bool intercept = false) => Console.ReadKey(intercept);
|
||||
|
||||
/// <inheritdoc />
|
||||
public int CursorTop
|
||||
{
|
||||
get => Console.CursorTop;
|
||||
set => Console.CursorTop = value;
|
||||
}
|
||||
|
||||
public void Clear() => Console.Clear();
|
||||
|
||||
/// <inheritdoc />
|
||||
public CancellationToken RegisterCancellationHandler()
|
||||
{
|
||||
@@ -89,13 +95,7 @@ public class SystemConsole : IConsole, IDisposable
|
||||
|
||||
return (_cancellationTokenSource = cts).Token;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear() => Console.Clear();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ConsoleKeyInfo ReadKey(bool intercept = false) => Console.ReadKey(intercept);
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user