using System.Collections.Concurrent; namespace Terminal.Gui; /// /// Input processor for , deals in stream /// public class NetInputProcessor : InputProcessor { #pragma warning disable CA2211 /// /// Set to true to generate code in (verbose only) for test cases in NetInputProcessorTests. /// /// This makes the task of capturing user/language/terminal specific keyboard issues easier to /// diagnose. By turning this on and searching logs user can send us exactly the input codes that are released /// to input stream. /// /// public static bool GenerateTestCasesForKeyPresses = true; #pragma warning restore CA2211 /// public NetInputProcessor (ConcurrentQueue inputBuffer) : base (inputBuffer, new NetKeyConverter ()) { } /// protected override void Process (ConsoleKeyInfo consoleKeyInfo) { // For building test cases if (GenerateTestCasesForKeyPresses) { Logging.Trace (FormatConsoleKeyInfoForTestCase (consoleKeyInfo)); } foreach (Tuple released in Parser.ProcessInput (Tuple.Create (consoleKeyInfo.KeyChar, consoleKeyInfo))) { ProcessAfterParsing (released.Item2); } } /// protected override void ProcessAfterParsing (ConsoleKeyInfo input) { var key = KeyConverter.ToKey (input); OnKeyDown (key); OnKeyUp (key); } /* For building test cases */ private static string FormatConsoleKeyInfoForTestCase (ConsoleKeyInfo input) { string charLiteral = input.KeyChar == '\0' ? @"'\0'" : $"'{input.KeyChar}'"; var expectedLiteral = "new Rune('todo')"; return $"new ConsoleKeyInfo({charLiteral}, ConsoleKey.{input.Key}, " + $"{input.Modifiers.HasFlag (ConsoleModifiers.Shift).ToString ().ToLower ()}, " + $"{input.Modifiers.HasFlag (ConsoleModifiers.Alt).ToString ().ToLower ()}, " + $"{input.Modifiers.HasFlag (ConsoleModifiers.Control).ToString ().ToLower ()}), {expectedLiteral}"; } }