| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System.Collections.Concurrent;
- namespace Terminal.Gui.Drivers;
- /// <summary>
- /// Input processor for <see cref="FakeInput"/>, deals in <see cref="ConsoleKeyInfo"/> stream
- /// </summary>
- public class FakeInputProcessor : InputProcessorImpl<ConsoleKeyInfo>
- {
- /// <inheritdoc/>
- public FakeInputProcessor (ConcurrentQueue<ConsoleKeyInfo> inputBuffer) : base (inputBuffer, new NetKeyConverter ())
- {
- DriverName = "fake";
- }
- /// <inheritdoc/>
- protected override void Process (ConsoleKeyInfo input)
- {
- Logging.Trace ($"input: {input.KeyChar}");
- foreach (Tuple<char, ConsoleKeyInfo> released in Parser.ProcessInput (Tuple.Create (input.KeyChar, input)))
- {
- Logging.Trace($"released: {released.Item1}");
- ProcessAfterParsing (released.Item2);
- }
- }
- /// <inheritdoc />
- 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);
- }
- }
- }
|