Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
timeout-minutes: 15
env:
DisableRealDriverIO: "1"

steps:
- name: Checkout code
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/stress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
os: [ ubuntu-latest ]

timeout-minutes: 70 # Allow some buffer time beyond the 1-hour test duration
env:
DisableRealDriverIO: "1"
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -58,6 +60,8 @@ jobs:
os: [ ubuntu-latest, windows-latest, macos-latest ]

timeout-minutes: 90
env:
DisableRealDriverIO: "1"
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
os: [ ubuntu-latest, windows-latest, macos-latest ]

timeout-minutes: 15
env:
DisableRealDriverIO: "1"
steps:

- name: Checkout code
Expand Down Expand Up @@ -76,6 +78,8 @@ jobs:
os: [ ubuntu-latest, windows-latest, macos-latest ]

timeout-minutes: 60
env:
DisableRealDriverIO: "1"
steps:

- name: Checkout code
Expand Down
20 changes: 14 additions & 6 deletions Terminal.Gui/Drivers/AnsiDriver/AnsiInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public AnsiInput ()
try
{
// Check if we have a real console first
if (!AnsiTerminalHelper.IsAttachedToTerminal (out bool inputAttached, out bool outputAttached))
if (!IsAttachedToTerminal)
{
Trace.Lifecycle (nameof (AnsiInput), "Init", $"Console redirected (Output: {outputAttached}, Input: {inputAttached}). Running in degraded mode.");
Trace.Lifecycle (nameof (AnsiInput), "Init", "Console is not attached to a terminal. Running in degraded mode.");

return;
}
Expand All @@ -105,7 +105,9 @@ public AnsiInput ()
_windowsVTInput.Dispose ();
_windowsVTInput = null;

Trace.Lifecycle (nameof (AnsiInput), "Init", "Failed to enable Windows VT Input mode. Terminal input will not work. Running in degraded mode.");
Trace.Lifecycle (nameof (AnsiInput),
"Init",
"Failed to enable Windows VT Input mode. Terminal input will not work. Running in degraded mode.");

return;
}
Expand All @@ -121,7 +123,9 @@ public AnsiInput ()

if (!_unixRawMode.TryEnable ())
{
Trace.Lifecycle (nameof (AnsiInput), "Init", "Failed to enable Unix raw input mode. Terminal input will not work. Running in degraded mode.");
Trace.Lifecycle (nameof (AnsiInput),
"Init",
"Failed to enable Unix raw input mode. Terminal input will not work. Running in degraded mode.");
_pollMap = null;
_unixRawMode?.Dispose ();
_unixRawMode = null;
Expand All @@ -132,7 +136,9 @@ public AnsiInput ()
}
catch (DllNotFoundException ex)
{
Trace.Lifecycle (nameof (AnsiInput), "Init", $"Failed to enable Unix raw input mode. libc not available: {ex.Message}. Running in degraded mode.");
Trace.Lifecycle (nameof (AnsiInput),
"Init",
$"Failed to enable Unix raw input mode. libc not available: {ex.Message}. Running in degraded mode.");
}
}
else
Expand All @@ -147,7 +153,9 @@ public AnsiInput ()
}
catch (Exception ex)
{
Trace.Lifecycle (nameof (AnsiInput), "Init", $"Failed to initialize terminal: {ex.GetType ().Name}: {ex.Message}. Running in degraded mode. Stack trace: {ex.StackTrace}");
Trace.Lifecycle (nameof (AnsiInput),
"Init",
$"Failed to initialize terminal: {ex.GetType ().Name}: {ex.Message}. Running in degraded mode. Stack trace: {ex.StackTrace}");
_platform = AnsiPlatform.Degraded;
}
}
Expand Down
26 changes: 15 additions & 11 deletions Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public AnsiOutput ()
try
{
// Check if we have a real console first
if (!AnsiTerminalHelper.IsAttachedToTerminal (out bool inputAttached, out bool outputAttached))
if (!IsAttachedToTerminal)
{
Trace.Lifecycle (nameof (AnsiOutput), "Init", $"Console redirected (Output: {outputAttached}, Input: {inputAttached}). Running in degraded mode.");
Trace.Lifecycle (nameof (AnsiOutput), "Init", "No real terminal attached. Running in degraded mode.");

return;
}
Expand All @@ -78,7 +78,9 @@ public AnsiOutput ()
_windowsVTOutput.Dispose ();
_windowsVTOutput = null;

Trace.Lifecycle (nameof (AnsiOutput), "Init", "Failed to enable Windows VT Input mode. Terminal input will not work. Running in degraded mode.");
Trace.Lifecycle (nameof (AnsiOutput),
"Init",
"Failed to enable Windows VT Input mode. Terminal input will not work. Running in degraded mode.");

return;
}
Expand Down Expand Up @@ -178,14 +180,16 @@ protected override void Write (StringBuilder output)
/// <inheritdoc/>
public void Write (ReadOnlySpan<char> text)
{
StringBuilder capturedOutput = new ();
capturedOutput.Append (text);
base.Write (capturedOutput);

try
{
switch (_platform)
{
case AnsiPlatform.WindowsVT:
StringBuilder sb = new ();
sb.Append (text);
_windowsVTOutput!.Write (sb);
_windowsVTOutput!.Write (capturedOutput);

break;

Expand Down Expand Up @@ -310,13 +314,13 @@ public void HandleSizeQueryResponse (string? response)
/// <inheritdoc/>
public void Dispose ()
{
if (_platform == AnsiPlatform.Degraded)
{
return;
}

try
{
if (_platform == AnsiPlatform.Degraded)
{
return;
}

// Restore terminal state: disable mouse, restore buffer, show cursor
// TODO: Move Input related CSI sequences to AnsiInput
Write (EscSeqUtils.CSI_DisableMouseEvents);
Expand Down
30 changes: 0 additions & 30 deletions Terminal.Gui/Drivers/AnsiDriver/AnsiTerminalHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,6 @@ namespace Terminal.Gui.Drivers;

internal static class AnsiTerminalHelper
{
public static bool IsAttachedToTerminal (out bool inputAttached, out bool outputAttached)
{
inputAttached = outputAttached = false;

if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows))
{
const int STD_INPUT_HANDLE = -10;
const int STD_OUTPUT_HANDLE = -11;
nint inH = GetStdHandle (STD_INPUT_HANDLE);
nint outH = GetStdHandle (STD_OUTPUT_HANDLE);

inputAttached = inH != nint.Zero && GetConsoleMode (inH, out _);
outputAttached = outH != nint.Zero && GetConsoleMode (outH, out _);

return inputAttached && outputAttached;
}
const int STDIN_FILENO = 0;
const int STDOUT_FILENO = 1;
inputAttached = isatty (STDIN_FILENO) == 1;
outputAttached = isatty (STDOUT_FILENO) == 1;

return inputAttached && outputAttached;
}

public static void FlushNative (AnsiPlatform platform)
{
try
Expand Down Expand Up @@ -85,9 +61,6 @@ private static void FlushWindows ()
}

// Unix
[DllImport ("libc", SetLastError = true)]
private static extern int isatty (int fd);

[DllImport ("libc", SetLastError = true)]
private static extern int tcdrain (int fd);

Expand All @@ -98,9 +71,6 @@ private static void FlushWindows ()
[DllImport ("kernel32.dll", SetLastError = true)]
private static extern nint GetStdHandle (int nStdHandle);

[DllImport ("kernel32.dll")]
private static extern bool GetConsoleMode (nint hConsoleHandle, out uint lpMode);

[DllImport ("kernel32.dll", SetLastError = true)]
[return: MarshalAs (UnmanagedType.Bool)]
private static extern bool FlushFileBuffers (nint hFile);
Expand Down
20 changes: 14 additions & 6 deletions Terminal.Gui/Drivers/DotNetDriver/NetInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#nullable disable
using Terminal.Gui.Tracing;

namespace Terminal.Gui.Drivers;

/// <summary>
Expand All @@ -11,19 +13,25 @@ public class NetInput : InputImpl<ConsoleKeyInfo>, ITestableInput<ConsoleKeyInfo
/// <summary>
/// Creates a new instance of the class. Implicitly sends
/// console mode settings that enable virtual input (mouse
/// reporting etc).
/// reporting etc.).
/// </summary>
public NetInput ()
{
//Logging.Information ($"Creating {nameof (NetInput)}");
// Check if we have a real console first
if (!IsAttachedToTerminal)
{
Trace.Lifecycle (nameof (NetInput), "Init", "Console is not attached to a terminal. Running in degraded mode.");

return;
}

PlatformID p = Environment.OSVersion.Platform;

if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
if (p is PlatformID.Win32NT or PlatformID.Win32S or PlatformID.Win32Windows)
{
try
{
_adjustConsole = new ();
_adjustConsole = new NetWinVTConsole ();
}
catch (ApplicationException ex)
{
Expand Down Expand Up @@ -84,8 +92,8 @@ public override void Dispose ()
}
}

/// <inheritdoc />
public void InjectInput (ConsoleKeyInfo input) { throw new NotImplementedException (); }
/// <inheritdoc/>
public void InjectInput (ConsoleKeyInfo input) => throw new NotImplementedException ();

/// <inheritdoc/>
public override bool Peek ()
Expand Down
Loading
Loading