Browse Source

Change to using ansi escape sequences in new standalone class

tznind 10 months ago
parent
commit
ccb974b66f
2 changed files with 51 additions and 0 deletions
  1. 45 0
      Terminal.Gui/Drawing/SixelSupportDetector.cs
  2. 6 0
      UICatalog/Scenarios/Images.cs

+ 45 - 0
Terminal.Gui/Drawing/SixelSupportDetector.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Terminal.Gui;
+
+/// <summary>
+/// Uses ANSII escape sequences to detect whether sixel is supported
+/// by the terminal.
+/// </summary>
+public class SixelSupportDetector
+{
+    public SixelSupport Detect ()
+    {
+        var darResponse = AnsiEscapeSequenceRequest.ExecuteAnsiRequest (EscSeqUtils.CSI_SendDeviceAttributes);
+        var result = new SixelSupport ();
+        result.IsSupported = darResponse.Response.Contains ('4');
+
+        return result;
+    }
+}
+
+
+public class SixelSupport
+{
+    /// <summary>
+    /// Whether the current driver supports sixel graphic format.
+    /// Defaults to false.
+    /// </summary>
+    public bool IsSupported { get; set; }
+
+    /// <summary>
+    /// The number of pixels of sixel that corresponds to each Col (<see cref="Size.Width"/>)
+    /// and each Row (<see cref="Size.Height"/>.  Defaults to 10x20.
+    /// </summary>
+    public Size Resolution { get; set; } = new Size (10, 20);
+
+    /// <summary>
+    /// The maximum number of colors that can be included in a sixel image. Defaults
+    /// to 256.
+    /// </summary>
+    public int MaxPaletteColors { get; set; } = 256;
+}

+ 6 - 0
UICatalog/Scenarios/Images.cs

@@ -61,9 +61,15 @@ public class Images : Scenario
     private RadioGroup _rgDistanceAlgorithm;
     private NumericUpDown _popularityThreshold;
     private SixelToRender _sixelImage;
+    private SixelSupport _sixelSupport;
 
     public override void Main ()
     {
+        var sixelSupportDetector = new SixelSupportDetector ();
+        _sixelSupport = sixelSupportDetector.Detect ();
+
+        ConsoleDriver.SupportsSixel = _sixelSupport.IsSupported;
+
         Application.Init ();
         _win = new() { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" };