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 (IApplication? app, MouseEventArgs mouseEvent) { // FakeDriver uses ConsoleKeyInfo as its input record type, which cannot represent mouse events. // TODO: Verify this is correct. This didn't check the threadId before. // 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 (app is {} && app.MainThreadId != Thread.CurrentThread.ManagedThreadId) { // Application is running - use Invoke to defer to next iteration app?.Invoke ((_) => RaiseMouseEvent (mouseEvent)); } else { // Not in Application context (unit tests) - raise immediately RaiseMouseEvent (mouseEvent); } } }