Determine whether sixel is supported by issuing a Device Attributes Request

This commit is contained in:
tznind
2024-09-29 10:37:14 +01:00
parent 18f185d7fb
commit db0fc41d54
4 changed files with 29 additions and 2 deletions

View File

@@ -484,6 +484,9 @@ public abstract class ConsoleDriver
/// <summary>Gets whether the <see cref="ConsoleDriver"/> supports TrueColor output.</summary>
public virtual bool SupportsTrueColor => true;
// TODO: make not static TODO: gets set in mouse logic in net driver :/
public static bool SupportsSixel { get; set; }
// TODO: This makes ConsoleDriver dependent on Application, which is not ideal. This should be moved to Application.
// BUGBUG: Application.Force16Colors should be bool? so if SupportsTrueColor and Application.Force16Colors == false, this doesn't override
/// <summary>

View File

@@ -47,6 +47,10 @@ public static class EscSeqUtils
/// </summary>
public const string CSI = "\u001B[";
public const string CSI_Device_Attributes_Request = CSI + "c";
public const string CSI_Device_Attributes_Request_Terminator = "c";
/// <summary>
/// ESC [ ? 1047 h - Activate xterm alternative buffer (no backscroll)
/// </summary>

View File

@@ -632,6 +632,9 @@ internal class NetEvents : IDisposable
break;
}
break;
case EscSeqUtils.CSI_Device_Attributes_Request_Terminator:
ConsoleDriver.SupportsSixel = values.Any (v => v == "4");
break;
default:
EnqueueRequestResponseEvent (c1Control, code, values, terminating);
@@ -1135,9 +1138,13 @@ internal class NetDriver : ConsoleDriver
_mainLoopDriver = new NetMainLoop (this);
_mainLoopDriver.ProcessInput = ProcessInput;
_mainLoopDriver._netEvents.EscSeqRequests.Add ("c");
// Determine if sixel is supported
Console.Out.Write (EscSeqUtils.CSI_Device_Attributes_Request);
return new MainLoop (_mainLoopDriver);
}
private void ProcessInput (InputResult inputEvent)
{
switch (inputEvent.EventType)
@@ -1338,6 +1345,7 @@ internal class NetDriver : ConsoleDriver
}
private CursorVisibility? _cachedCursorVisibility;
private static bool _supportsSixel;
public override void UpdateCursor ()
{

View File

@@ -53,6 +53,18 @@ public class Images : Scenario
};
win.Add (cbSupportsTrueColor);
var cbSupportsSixel = new CheckBox
{
X = Pos.Right (lblDriverName) + 2,
Y = 1,
CheckedState = ConsoleDriver.SupportsSixel
? CheckState.Checked : CheckState.UnChecked,
CanFocus = false,
Enabled = false,
Text = "Supports Sixel"
};
win.Add (cbSupportsSixel);
var cbUseTrueColor = new CheckBox
{
X = Pos.Right (cbSupportsTrueColor) + 2,
@@ -69,7 +81,7 @@ public class Images : Scenario
var tv = new TabView
{
Y = Pos.Bottom (lblDriverName), Width = Dim.Fill (), Height = Dim.Fill ()
Y = Pos.Bottom (cbSupportsSixel), Width = Dim.Fill (), Height = Dim.Fill ()
};
tv.AddTab (tabBasic, true);