Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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: 1 addition & 1 deletion Examples/UICatalog/UICatalogRunnable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void OnIsModalChanged (bool newIsModal)

_disableMouseCb?.Value = App.Mouse.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked;

_shVersion?.Title = $"{RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}, {App?.Driver?.GetVersionInfo ()}";
_shVersion?.Title = $"{RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}, {App?.Driver?.GetName ()}";
Comment thread
tig marked this conversation as resolved.
Outdated

if (string.IsNullOrEmpty ((string?)Result))
{
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/App/MainLoop/MainLoopCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void BuildDriverIfPossible (IApplication? app)
KittyKeyboardProtocolDetector kittyKeyboardDetector = new (_driver);
kittyKeyboardDetector.Detect (result =>
{
_driver.SetKittyKeyboardProtocol (result);
_driver.SetKittyKeyboardCapabilities (result);
Trace.Lifecycle (app?.MainThreadId?.ToString (),
"KittyKeyboard",
$"Probe complete: Supported={result.IsSupported}, SupportedFlags={result.SupportedFlags}, EnabledFlags={result.EnabledFlags}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Terminal.Gui.Drivers;

/// <summary>
/// Describes the kitty keyboard protocol state discovered from the active terminal.
/// Describes the kitty keyboard protocol capabilities discovered from the active terminal.
/// </summary>
public class KittyKeyboardProtocolResult
public class KittyKeyboardCapabilities
{
/// <summary>
/// Gets or sets whether the active terminal responded to the kitty keyboard protocol query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public KittyKeyboardProtocolDetector (IDriver? driver)
/// Detects kitty keyboard protocol support asynchronously through the ANSI request scheduler.
/// </summary>
/// <param name="resultCallback">Called when detection completes.</param>
public void Detect (Action<KittyKeyboardProtocolResult> resultCallback)
public void Detect (Action<KittyKeyboardCapabilities> resultCallback)
{
ArgumentNullException.ThrowIfNull (resultCallback);

if (_driver is { IsLegacyConsole: true })
{
Trace.Lifecycle (nameof (KittyKeyboardProtocolDetector), "Detect", "Skipping kitty keyboard probe for legacy console");
resultCallback (new KittyKeyboardProtocolResult ());
resultCallback (new KittyKeyboardCapabilities ());

return;
}
Expand All @@ -43,7 +43,7 @@ public void Detect (Action<KittyKeyboardProtocolResult> resultCallback)
QueueRequest (EscSeqUtils.CSI_QueryKittyKeyboardFlags,
response =>
{
KittyKeyboardProtocolResult result = ParseResponse (response);
KittyKeyboardCapabilities result = ParseResponse (response);
result.EnabledFlags = result.IsSupported ? EscSeqUtils.KittyKeyboardRequestedFlags : KittyKeyboardFlags.None;

Trace.Lifecycle (nameof (KittyKeyboardProtocolDetector),
Expand All @@ -62,7 +62,7 @@ public void Detect (Action<KittyKeyboardProtocolResult> resultCallback)
() =>
{
Trace.Lifecycle (nameof (KittyKeyboardProtocolDetector), "Detect", "Kitty keyboard probe abandoned");
resultCallback (new KittyKeyboardProtocolResult ());
resultCallback (new KittyKeyboardCapabilities ());
});
}

Expand All @@ -80,20 +80,20 @@ private void QueueRequest (AnsiEscapeSequence req, Action<string> responseCallba
_driver?.QueueAnsiRequest (request);
}

internal static KittyKeyboardProtocolResult ParseResponse (string? response)
internal static KittyKeyboardCapabilities ParseResponse (string? response)
{
if (string.IsNullOrWhiteSpace (response))
{
return new KittyKeyboardProtocolResult ();
return new KittyKeyboardCapabilities ();
}

Match match = Regex.Match (response, @"(?:\x1B)?\[\?(\d+)u$");

if (!match.Success || !int.TryParse (match.Groups [1].Value, out int supportedFlags))
{
return new KittyKeyboardProtocolResult ();
return new KittyKeyboardCapabilities ();
}

return new KittyKeyboardProtocolResult { IsSupported = true, SupportedFlags = (KittyKeyboardFlags)supportedFlags };
return new KittyKeyboardCapabilities { IsSupported = true, SupportedFlags = (KittyKeyboardFlags)supportedFlags };
}
}
23 changes: 8 additions & 15 deletions Terminal.Gui/Drivers/DriverImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ public void Refresh ()
/// <inheritdoc/>
public string? GetName () => _componentFactory.GetDriverName ();

/// <inheritdoc/>
public virtual string GetVersionInfo ()
{
string? driverName = GetName ();

return $"{driverName} driver";
}

/// <inheritdoc/>
public void Suspend ()
{
Expand Down Expand Up @@ -364,24 +356,25 @@ public Attribute SetAttribute (Attribute newAttribute)

#region Input Events

/// <summary>
/// Gets the detected kitty keyboard protocol state for the current driver instance.
/// </summary>
internal KittyKeyboardProtocolResult KittyKeyboardProtocol { get; private set; } = new ();
/// <inheritdoc/>
public KittyKeyboardCapabilities? KittyKeyboardCapabilities { get; private set; }

/// <summary>
/// Stores the latest kitty keyboard protocol detection result.
/// </summary>
/// <param name="result">The detected kitty keyboard protocol result.</param>
internal void SetKittyKeyboardProtocol (KittyKeyboardProtocolResult result) => KittyKeyboardProtocol = result;
/// <param name="capabilities">The detected kitty keyboard capabilities.</param>
internal void SetKittyKeyboardCapabilities (KittyKeyboardCapabilities capabilities) => KittyKeyboardCapabilities = capabilities;

/// <summary>
/// Stores the kitty keyboard flags currently enabled on the terminal.
/// </summary>
/// <param name="enabledFlags">The kitty keyboard flags currently enabled.</param>
internal void SetKittyKeyboardEnabledFlags (KittyKeyboardFlags enabledFlags)
{
KittyKeyboardProtocol.EnabledFlags = enabledFlags;
if (KittyKeyboardCapabilities is not null)
{
KittyKeyboardCapabilities.EnabledFlags = enabledFlags;
}
}

/// <summary>Event fired when a key is pressed down.</summary>
Expand Down
10 changes: 6 additions & 4 deletions Terminal.Gui/Drivers/IDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public interface IDriver : IDisposable
/// </summary>
string? GetName ();

/// <summary>Returns the name of the driver and relevant library version information.</summary>
/// <returns></returns>
string GetVersionInfo ();

/// <summary>Suspends the application (e.g. on Linux via SIGTSTP) and upon resume, resets the console driver.</summary>
/// <remarks>This is only implemented in UnixDriver.</remarks>
void Suspend ();
Expand Down Expand Up @@ -356,6 +352,12 @@ public interface IDriver : IDisposable

#region Input Events

/// <summary>
/// Gets the terminal kitty keyboard protocol capabilities detected at startup.
/// <see langword="null"/> if the terminal was not queried or does not support the protocol.
Comment thread
tig marked this conversation as resolved.
Outdated
/// </summary>
KittyKeyboardCapabilities? KittyKeyboardCapabilities { get; }

Comment thread
tig marked this conversation as resolved.
/// <summary>Event fired when a key is pressed down.</summary>
event EventHandler<Key>? KeyDown;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ public async Task StartInputTaskAsync_DetectsKittyKeyboard_WhenTerminalResponds
loop.InputProcessor.ProcessQueue ();

var driver = Assert.IsType<DriverImpl> (appMock.Object.Driver);
Assert.True (driver.KittyKeyboardProtocol.IsSupported);
Assert.Equal ((KittyKeyboardFlags)31, driver.KittyKeyboardProtocol.SupportedFlags);
Assert.True (driver.KittyKeyboardCapabilities?.IsSupported);
Assert.Equal ((KittyKeyboardFlags)31, driver.KittyKeyboardCapabilities?.SupportedFlags);

// In degraded mode (no real terminal), enable/disable are no-ops,
// but detection still succeeds via injected response.
Assert.Equal (KittyKeyboardFlags.None, driver.KittyKeyboardProtocol.EnabledFlags);
Assert.Equal (KittyKeyboardFlags.None, driver.KittyKeyboardCapabilities?.EnabledFlags);

Comment thread
tig marked this conversation as resolved.
Outdated
coordinator.Stop ();
}
Expand All @@ -267,7 +267,7 @@ public async Task StartInputTaskAsync_DoesNotEnableKittyKeyboard_ForLegacyConsol
await coordinator.StartInputTaskAsync (appMock.Object);

var driver = Assert.IsType<DriverImpl> (appMock.Object.Driver);
Assert.False (driver.KittyKeyboardProtocol.IsSupported);
Assert.False (driver.KittyKeyboardCapabilities?.IsSupported);

Assert.DoesNotContain (EscSeqUtils.CSI_EnableKittyKeyboardFlags (EscSeqUtils.KittyKeyboardRequestedFlags),
output.GetLastOutput (),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Detect_QueuesKittyQuery_AndReturnsSupportedResult_WhenTerminalRespon

KittyKeyboardProtocolDetector detector = new (driverMock.Object);

KittyKeyboardProtocolResult? result = null;
KittyKeyboardCapabilities? result = null;

detector.Detect (r => result = r);

Expand All @@ -43,7 +43,7 @@ public void Detect_ReturnsUnsupportedResult_WhenTerminalDoesNotRespond ()

KittyKeyboardProtocolDetector detector = new (driverMock.Object);

KittyKeyboardProtocolResult? result = null;
KittyKeyboardCapabilities? result = null;

detector.Detect (r => result = r);

Expand All @@ -61,7 +61,7 @@ public void Detect_SkipsLegacyConsole ()

KittyKeyboardProtocolDetector detector = new (driverMock.Object);

KittyKeyboardProtocolResult? result = null;
KittyKeyboardCapabilities? result = null;

detector.Detect (r => result = r);

Expand All @@ -78,7 +78,7 @@ public void Detect_SkipsLegacyConsole ()
[InlineData ("", false, 0)]
public void ParseResponse_ReturnsExpectedResult (string response, bool isSupported, int supportedFlags)
{
KittyKeyboardProtocolResult result = KittyKeyboardProtocolDetector.ParseResponse (response);
KittyKeyboardCapabilities result = KittyKeyboardProtocolDetector.ParseResponse (response);

Assert.Equal (isSupported, result.IsSupported);
Assert.Equal ((KittyKeyboardFlags)supportedFlags, result.SupportedFlags);
Expand Down
Loading