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
|
public partial class ConsoleReader
|
||||||
{
|
{
|
||||||
internal static ConsoleReader Create(IConsole console, Stream? stream) => new(
|
internal static ConsoleReader Create(IConsole console, Stream stream) => new(
|
||||||
console,
|
console,
|
||||||
stream is not null
|
Stream.Synchronized(stream)
|
||||||
? Stream.Synchronized(stream)
|
|
||||||
: Stream.Null
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -272,10 +272,8 @@ public partial class ConsoleWriter : StreamWriter
|
|||||||
|
|
||||||
public partial class ConsoleWriter
|
public partial class ConsoleWriter
|
||||||
{
|
{
|
||||||
internal static ConsoleWriter Create(IConsole console, Stream? stream) => new(
|
internal static ConsoleWriter Create(IConsole console, Stream stream) => new(
|
||||||
console,
|
console,
|
||||||
stream is not null
|
Stream.Synchronized(stream)
|
||||||
? Stream.Synchronized(stream)
|
|
||||||
: Stream.Null
|
|
||||||
) {AutoFlush = true};
|
) {AutoFlush = true};
|
||||||
}
|
}
|
||||||
@@ -59,14 +59,33 @@ public class FakeConsole : IConsole, IDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public FakeConsole(Stream? input = null, Stream? output = null, Stream? error = null)
|
public FakeConsole(Stream? input = null, Stream? output = null, Stream? error = null)
|
||||||
{
|
{
|
||||||
Input = ConsoleReader.Create(this, input);
|
Input = ConsoleReader.Create(this, input ?? Stream.Null);
|
||||||
Output = ConsoleWriter.Create(this, output);
|
Output = ConsoleWriter.Create(this, output ?? Stream.Null);
|
||||||
Error = ConsoleWriter.Create(this, error);
|
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 />
|
/// <inheritdoc />
|
||||||
public CancellationToken RegisterCancellationHandler() => _cancellationTokenSource.Token;
|
public CancellationToken RegisterCancellationHandler() => _cancellationTokenSource.Token;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a cancellation signal to the currently executing command.
|
/// Sends a cancellation signal to the currently executing command.
|
||||||
/// </summary>
|
/// </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 />
|
/// <inheritdoc />
|
||||||
public virtual void Dispose() => _cancellationTokenSource.Dispose();
|
public virtual void Dispose() => _cancellationTokenSource.Dispose();
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,16 @@ public interface IConsole
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
int CursorTop { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Registers a handler for the interrupt signal (Ctrl+C) on the console and returns
|
/// Registers a handler for the interrupt signal (Ctrl+C) on the console and returns
|
||||||
/// a token representing the cancellation request.
|
/// a token representing the cancellation request.
|
||||||
@@ -82,16 +92,6 @@ public interface IConsole
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
CancellationToken RegisterCancellationHandler();
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -41,6 +41,20 @@ public class SystemConsole : IConsole, IDisposable
|
|||||||
get => Console.BackgroundColor;
|
get => Console.BackgroundColor;
|
||||||
set => Console.BackgroundColor = value;
|
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>
|
/// <summary>
|
||||||
/// Initializes an instance of <see cref="SystemConsole"/>.
|
/// Initializes an instance of <see cref="SystemConsole"/>.
|
||||||
@@ -56,19 +70,11 @@ public class SystemConsole : IConsole, IDisposable
|
|||||||
public void ResetColor() => Console.ResetColor();
|
public void ResetColor() => Console.ResetColor();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int CursorLeft
|
public ConsoleKeyInfo ReadKey(bool intercept = false) => Console.ReadKey(intercept);
|
||||||
{
|
|
||||||
get => Console.CursorLeft;
|
|
||||||
set => Console.CursorLeft = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int CursorTop
|
public void Clear() => Console.Clear();
|
||||||
{
|
|
||||||
get => Console.CursorTop;
|
|
||||||
set => Console.CursorTop = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public CancellationToken RegisterCancellationHandler()
|
public CancellationToken RegisterCancellationHandler()
|
||||||
{
|
{
|
||||||
@@ -89,13 +95,7 @@ public class SystemConsole : IConsole, IDisposable
|
|||||||
|
|
||||||
return (_cancellationTokenSource = cts).Token;
|
return (_cancellationTokenSource = cts).Token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Clear() => Console.Clear();
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public ConsoleKeyInfo ReadKey(bool intercept = false) => Console.ReadKey(intercept);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user