#nullable enable
using System.Collections.Concurrent;
namespace Terminal.Gui.Drivers;
///
/// implementation that uses a fake input source for testing.
/// The and methods are executed
/// on the input thread created by .
///
public class FakeInput : InputImpl, ITestableInput
{
// Queue for storing injected input that will be returned by Peek/Read
private readonly ConcurrentQueue _testInput = new ();
///
/// Creates a new FakeInput.
///
public FakeInput ()
{ }
///
public override bool Peek ()
{
// Will be called on the input thread.
return !_testInput.IsEmpty;
}
///
public override IEnumerable Read ()
{
// Will be called on the input thread.
while (_testInput.TryDequeue (out ConsoleKeyInfo input))
{
yield return input;
}
}
///
public void AddInput (ConsoleKeyInfo input)
{
//Logging.Trace ($"Enqueuing input: {input.Key}");
// Will be called on the main loop thread.
_testInput.Enqueue (input);
}
}