mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Fixes #4139. Application.Run<T> isn't initializing properly by setting the Application.ForceDriver property * Trying fix unit tests * Only to force again CI tests because I haven't errors locally * This should pass, unless RunningUnitTests is set to false somewhere * Fix Unix unit tests and failures via ReSharper * Changes suggested by @tig * Prevent empty string * Centralize all the entry logic in the InternalInit method * Change GetDriverTypes to return a tuple
76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Terminal.Gui.Drivers;
|
|
|
|
/// <summary>
|
|
/// Console input implementation that uses native dotnet methods e.g. <see cref="System.Console"/>.
|
|
/// </summary>
|
|
public class NetInput : ConsoleInput<ConsoleKeyInfo>, INetInput
|
|
{
|
|
private readonly NetWinVTConsole _adjustConsole;
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of the class. Implicitly sends
|
|
/// console mode settings that enable virtual input (mouse
|
|
/// reporting etc).
|
|
/// </summary>
|
|
public NetInput ()
|
|
{
|
|
Logging.Logger.LogInformation ($"Creating {nameof (NetInput)}");
|
|
|
|
if (ConsoleDriver.RunningUnitTests)
|
|
{
|
|
return;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override bool Peek ()
|
|
{
|
|
if (ConsoleDriver.RunningUnitTests)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Console.KeyAvailable;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override IEnumerable<ConsoleKeyInfo> Read ()
|
|
{
|
|
while (Console.KeyAvailable)
|
|
{
|
|
yield return Console.ReadKey (true);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override void Dispose ()
|
|
{
|
|
base.Dispose ();
|
|
_adjustConsole?.Cleanup ();
|
|
|
|
Console.Out.Write (EscSeqUtils.CSI_DisableMouseEvents);
|
|
}
|
|
}
|