Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 0 additions & 5 deletions Terminal.Gui/App/ApplicationImpl.Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ private void CreateDriver (string? driverName)

break;

case DriverRegistry.Names.UNIX:
Coordinator = CreateSubcomponents (() => new UnixComponentFactory ());

break;

case DriverRegistry.Names.ANSI:
Coordinator = CreateSubcomponents (() => new AnsiComponentFactory ());

Expand Down
1 change: 1 addition & 0 deletions Terminal.Gui/Configuration/SourceGenerationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Terminal.Gui.Configuration;
[JsonSerializable (typeof (Dictionary<string, Scheme>))]

[JsonSerializable (typeof (TraceCategory))]
[JsonSerializable (typeof (SizeDetectionMode))]

internal partial class SourceGenerationContext : JsonSerializerContext
{ }
25 changes: 16 additions & 9 deletions Terminal.Gui/Drivers/AnsiDriver/AnsiComponentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,41 @@ public class AnsiComponentFactory : ComponentFactoryImpl<char>

private readonly AnsiInput? _input;
private readonly IOutput? _output;
private AnsiSizeMonitor? _createdSizeMonitor;
private readonly ISizeMonitor? _injectedSizeMonitor;

/// <summary>
/// Creates a new ANSIComponentFactory with optional output capture.
/// </summary>
/// <param name="input"></param>
/// <param name="output">Optional fake output to capture what would be written to console.</param>
/// <param name="sizeMonitor">Optional size monitor (if null, will create ANSISizeMonitor)</param>
/// <param name="sizeMonitor">Optional size monitor override (used in tests; if <see langword="null"/>, the monitor is chosen based on <see cref="Driver.SizeDetection"/>).</param>
public AnsiComponentFactory (AnsiInput? input = null, IOutput? output = null, ISizeMonitor? sizeMonitor = null)
{
_input = input;
_output = output;
_createdSizeMonitor = sizeMonitor as AnsiSizeMonitor;
_injectedSizeMonitor = sizeMonitor;
}


/// <inheritdoc/>
public override ISizeMonitor CreateSizeMonitor (IOutput consoleOutput, IOutputBuffer outputBuffer)
{
if (consoleOutput is AnsiOutput output)
// Return injected monitor (e.g. from test harness) if one was provided.
if (_injectedSizeMonitor is { })
{
// Create ANSISizeMonitor - the ANSI request callback will be set up
// by MainLoopCoordinator after the driver is fully constructed
_createdSizeMonitor = new (output, queueAnsiRequest: null);
return _createdSizeMonitor;
return _injectedSizeMonitor;
}

// Fallback for other output types
// When AnsiQuery mode is requested, use the ANSI escape-sequence monitor.
if (Driver.SizeDetection == SizeDetectionMode.AnsiQuery
&& consoleOutput is AnsiOutput ansiOutput)
{
// The ANSI request callback will be set up by MainLoopCoordinator
// after the driver is fully constructed.
return new AnsiSizeMonitor (ansiOutput, queueAnsiRequest: null);
}

// Default: synchronous polling via ioctl / Console API.
return new SizeMonitorImpl (consoleOutput);
}
Comment thread
tig marked this conversation as resolved.

Expand Down
4 changes: 2 additions & 2 deletions Terminal.Gui/Drivers/AnsiHandling/AnsiKeyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Terminal.Gui.Drivers;
/// for escape sequence parsing.
/// </para>
/// <list type="bullet">
/// <item><see cref="UnixInputProcessor"/> - Raw terminal input on Unix/Linux/macOS</item>
/// <item><see cref="AnsiInputProcessor"/> - ANSI-based test driver</item>
///
/// <item><see cref="AnsiInputProcessor"/> - ANSI-based driver for Unix/Linux/macOS and testing</item>
/// </list>
/// <para>
/// The conversion uses <see cref="ConsoleKeyInfo"/> as an intermediary format,
Expand Down
14 changes: 14 additions & 0 deletions Terminal.Gui/Drivers/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public static bool Force16Colors
/// <summary>Raised when <see cref="Force16Colors"/> changes.</summary>
public static event EventHandler<ValueChangedEventArgs<bool>>? Force16ColorsChanged;

// NOTE: SizeDetection is a configuration property (Driver.SizeDetection).
// It controls which strategy the ANSI driver uses to determine the terminal's size.
/// <summary>
/// Controls how the ANSI driver detects the terminal's window size.
/// Defaults to <see cref="SizeDetectionMode.Polling"/>, which uses a synchronous
/// native syscall (<c>ioctl</c> on Unix, Console API on Windows) for immediate,
/// reliable size information. Set to <see cref="SizeDetectionMode.AnsiQuery"/>
/// to use pure-ANSI escape-sequence queries instead (useful when the native API
/// does not reflect the remote terminal size, e.g. over an SSH tunnel).
/// </summary>
/// <seealso cref="SizeDetectionMode"/>
[ConfigurationProperty (Scope = typeof (SettingsScope))]
public static SizeDetectionMode SizeDetection { get; set; } = SizeDetectionMode.Polling;

/// <summary>
/// Determines whether the process is attached to a real terminal (i.e. stdin/stdout
/// are connected to a console device rather than redirected or running inside a test harness). Set the environment
Expand Down
14 changes: 1 addition & 13 deletions Terminal.Gui/Drivers/DriverRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public static class Names
/// <summary>.NET System.Console cross-platform driver name.</summary>
public const string DOTNET = "dotnet";

/// <summary>Unix/Linux/macOS terminal driver name.</summary>
public const string UNIX = "unix";

/// <summary>Pure ANSI escape sequence cross-platform driver name.</summary>
public const string ANSI = "ansi";
}
Expand Down Expand Up @@ -63,15 +60,6 @@ static DriverRegistry ()
() => new NetComponentFactory ()
));

Register (
new (
Names.UNIX,
"Unix/Linux Terminal Driver",
"Optimized Unix/Linux/macOS driver with raw terminal mode",
[PlatformID.Unix, PlatformID.MacOSX],
() => new UnixComponentFactory ()
));

Register (
new (
Names.ANSI,
Expand Down Expand Up @@ -145,7 +133,7 @@ public static DriverDescriptor GetDefaultDriver ()

if (p == PlatformID.Unix)
{
return _registry [Names.UNIX];
return _registry [Names.ANSI];
}

// Fallback to dotnet
Expand Down
1 change: 0 additions & 1 deletion Terminal.Gui/Drivers/Input/IInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace Terminal.Gui.Drivers;
/// <list type="bullet">
/// <item><see cref="WindowsInput"/> - Uses Windows Console API (<c>ReadConsoleInput</c>)</item>
/// <item><see cref="NetInput"/> - Uses .NET <see cref="System.Console"/> API</item>
/// <item><see cref="UnixInput"/> - Uses Unix terminal APIs</item>
/// <item><see cref="AnsiInput"/> - For testing, implements <see cref="ITestableInput{TInputRecord}"/></item>
/// </list>
/// <para>
Expand Down
21 changes: 21 additions & 0 deletions Terminal.Gui/Drivers/SizeDetectionMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Terminal.Gui.Drivers;

/// <summary>
/// Controls how the ANSI driver detects the terminal's window size.
/// </summary>
public enum SizeDetectionMode
{
/// <summary>
/// Uses <c>ioctl(TIOCGWINSZ)</c> on Unix/macOS or the Console API on Windows.
/// Synchronous, immediate, and reliable. This is the default.
/// </summary>
Polling,

/// <summary>
/// Sends a <c>CSI 18t</c> ANSI escape-sequence query and parses the
/// <c>ESC [ 8 ; height ; width t</c> response. Works over SSH or any
/// ANSI-compatible terminal but is asynchronous and throttled to one
/// query per 500 ms.
/// </summary>
AnsiQuery
}
6 changes: 0 additions & 6 deletions Terminal.Gui/Drivers/UnixDriver/IUnixInput.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Terminal.Gui/Drivers/UnixDriver/UnixComponentFactory.cs

This file was deleted.

185 changes: 0 additions & 185 deletions Terminal.Gui/Drivers/UnixDriver/UnixInput.cs

This file was deleted.

Loading
Loading