using Microsoft.Extensions.Logging; namespace Terminal.Gui; /// /// Console input implementation that uses native dotnet methods e.g. . /// public class NetInput : ConsoleInput, INetInput { private readonly NetWinVTConsole _adjustConsole; /// /// Creates a new instance of the class. Implicitly sends /// console mode settings that enable virtual input (mouse /// reporting etc). /// public NetInput () { Logging.Logger.LogInformation ($"Creating {nameof (NetInput)}"); PlatformID p = Environment.OSVersion.Platform; if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) { try { _adjustConsole = new (); } catch (ApplicationException ex) { // Likely running as a unit test, or in a non-interactive session. Logging.Logger.LogCritical ( ex, "NetWinVTConsole could not be constructed i.e. could not configure terminal modes. May indicate running in non-interactive session e.g. unit testing CI"); } } Console.Out.Write (EscSeqUtils.CSI_EnableMouseEvents); Console.TreatControlCAsInput = true; } /// protected override bool Peek () { return Console.KeyAvailable; } /// protected override IEnumerable Read () { while (Console.KeyAvailable) { yield return Console.ReadKey (true); } } /// public override void Dispose () { base.Dispose (); _adjustConsole?.Cleanup (); Console.Out.Write (EscSeqUtils.CSI_DisableMouseEvents); } }