using System.Collections.Concurrent;
namespace Terminal.Gui.Drivers;
///
/// Input processor for , deals in stream
///
public class FakeInputProcessor : InputProcessorImpl
{
///
public FakeInputProcessor (ConcurrentQueue inputBuffer) : base (inputBuffer, new NetKeyConverter ())
{
DriverName = "fake";
}
///
protected override void Process (ConsoleKeyInfo input)
{
Logging.Trace ($"input: {input.KeyChar}");
foreach (Tuple released in Parser.ProcessInput (Tuple.Create (input.KeyChar, input)))
{
Logging.Trace($"released: {released.Item1}");
ProcessAfterParsing (released.Item2);
}
}
///
public override void EnqueueMouseEvent (MouseEventArgs mouseEvent)
{
// FakeDriver uses ConsoleKeyInfo as its input record type, which cannot represent mouse events.
// If Application.Invoke is available (running in Application context), defer to next iteration
// to ensure proper timing - the event is raised after views are laid out.
// Otherwise (unit tests), raise immediately so tests can verify synchronously.
if (Application.MainThreadId is { })
{
// Application is running - use Invoke to defer to next iteration
Application.Invoke (() => RaiseMouseEvent (mouseEvent));
}
else
{
// Not in Application context (unit tests) - raise immediately
RaiseMouseEvent (mouseEvent);
}
}
}