mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00

* Renames Spectre.Cli to Spectre.Console.Cli. * Now uses Verify with Spectre.Console.Cli tests. * Removes some duplicate definitions. Closes #168
56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Spectre.Console.Testing
|
|
{
|
|
public sealed class FakeConsoleInput : IAnsiConsoleInput
|
|
{
|
|
private readonly Queue<ConsoleKeyInfo> _input;
|
|
|
|
public FakeConsoleInput()
|
|
{
|
|
_input = new Queue<ConsoleKeyInfo>();
|
|
}
|
|
|
|
public void PushText(string input)
|
|
{
|
|
if (input is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(input));
|
|
}
|
|
|
|
foreach (var character in input)
|
|
{
|
|
PushCharacter(character);
|
|
}
|
|
}
|
|
|
|
public void PushTextWithEnter(string input)
|
|
{
|
|
PushText(input);
|
|
PushKey(ConsoleKey.Enter);
|
|
}
|
|
|
|
public void PushCharacter(char character)
|
|
{
|
|
var control = char.IsUpper(character);
|
|
_input.Enqueue(new ConsoleKeyInfo(character, (ConsoleKey)character, false, false, control));
|
|
}
|
|
|
|
public void PushKey(ConsoleKey key)
|
|
{
|
|
_input.Enqueue(new ConsoleKeyInfo((char)key, key, false, false, false));
|
|
}
|
|
|
|
public ConsoleKeyInfo ReadKey(bool intercept)
|
|
{
|
|
if (_input.Count == 0)
|
|
{
|
|
throw new InvalidOperationException("No input available.");
|
|
}
|
|
|
|
return _input.Dequeue();
|
|
}
|
|
}
|
|
}
|