Răsfoiți Sursa

Fix for accepting

tznind 9 luni în urmă
părinte
comite
9990a552d2

+ 3 - 0
Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs

@@ -1356,6 +1356,8 @@ public static class EscSeqUtils
     /// </summary>
     public const string CSI_ReportDeviceAttributes_Terminator = "c";
 
+    /*
+     TODO: depends on https://github.com/gui-cs/Terminal.Gui/pull/3768
     /// <summary>
     ///     CSI 16 t - Request sixel resolution (width and height in pixels)
     /// </summary>
@@ -1365,6 +1367,7 @@ public static class EscSeqUtils
     ///     CSI 14 t - Request window size in pixels (width x height)
     /// </summary>
     public static readonly AnsiEscapeSequenceRequest CSI_RequestWindowSizeInPixels = new () { Request = CSI + "14t", Terminator = "t" };
+    */
 
     /// <summary>
     ///     CSI 1 8 t  | yes | yes |  yes  | report window size in chars

+ 20 - 0
Terminal.Gui/Drawing/AssumeSupportDetector.cs

@@ -0,0 +1,20 @@
+namespace Terminal.Gui;
+
+/// <summary>
+/// Implementation of <see cref="ISixelSupportDetector"/> that assumes best
+/// case scenario (full support including transparency with 10x20 resolution).
+/// </summary>
+public class AssumeSupportDetector : ISixelSupportDetector
+{
+    /// <inheritdoc />
+    public SixelSupportResult Detect ()
+    {
+        return new SixelSupportResult
+        {
+            IsSupported = true,
+            MaxPaletteColors = 256,
+            Resolution = new Size (10, 20),
+            SupportsTransparency = true
+        };
+    }
+}

+ 15 - 0
Terminal.Gui/Drawing/ISixelSupportDetector.cs

@@ -0,0 +1,15 @@
+namespace Terminal.Gui;
+
+/// <summary>
+/// Interface for detecting sixel support. Either through
+/// ansi requests to terminal or config file etc.
+/// </summary>
+public interface ISixelSupportDetector
+{
+    /// <summary>
+    /// Gets the supported sixel state e.g. by sending Ansi escape sequences
+    /// or from a config file etc.
+    /// </summary>
+    /// <returns>Description of sixel support.</returns>
+    public SixelSupportResult Detect ();
+}

+ 3 - 3
Terminal.Gui/Drawing/SixelSupportDetector.cs

@@ -1,12 +1,12 @@
 using System.Text.RegularExpressions;
 
 namespace Terminal.Gui;
-
+/* TODO : Depends on https://github.com/gui-cs/Terminal.Gui/pull/3768
 /// <summary>
 ///     Uses Ansi escape sequences to detect whether sixel is supported
 ///     by the terminal.
 /// </summary>
-public class SixelSupportDetector
+public class SixelSupportDetector : ISixelSupportDetector
 {
     /// <summary>
     /// Sends Ansi escape sequences to the console to determine whether
@@ -130,4 +130,4 @@ public class SixelSupportDetector
 
         return false;
     }
-}
+}*/

+ 9 - 8
UICatalog/Scenarios/Images.cs

@@ -65,7 +65,8 @@ public class Images : Scenario
 
     public override void Main ()
     {
-        var sixelSupportDetector = new SixelSupportDetector ();
+        // TODO: Change to the one that uses Ansi Requests later
+        var sixelSupportDetector = new AssumeSupportDetector ();
         _sixelSupportResult = sixelSupportDetector.Detect ();
 
         ConsoleDriver.SupportsSixel = _sixelSupportResult.IsSupported;
@@ -143,7 +144,7 @@ public class Images : Scenario
 
         SetupSixelSupported (cbSupportsSixel.CheckedState == CheckState.Checked);
 
-        btnOpenImage.Accept += OpenImage;
+        btnOpenImage.Accepting += OpenImage;
 
         _win.Add (_tabView);
         Application.Run (_win);
@@ -157,7 +158,7 @@ public class Images : Scenario
         _tabView.SetNeedsDisplay ();
     }
 
-    private void BtnStartFireOnAccept (object sender, HandledEventArgs e)
+    private void BtnStartFireOnAccept (object sender, CommandEventArgs e)
     {
         if (_fire != null)
         {
@@ -233,7 +234,7 @@ public class Images : Scenario
         Application.Sixel.Clear ();
     }
 
-    private void OpenImage (object sender, HandledEventArgs e)
+    private void OpenImage (object sender, CommandEventArgs e)
     {
         var ofd = new OpenDialog { Title = "Open Image", AllowsMultipleSelection = false };
         Application.Run (ofd);
@@ -334,7 +335,7 @@ public class Images : Scenario
             Y = 0,
             Text = "Output Sixel", Width = Dim.Auto ()
         };
-        btnSixel.Accept += OutputSixelButtonClick;
+        btnSixel.Accepting += OutputSixelButtonClick;
         _sixelSupported.Add (btnSixel);
 
         var btnStartFire = new Button
@@ -343,7 +344,7 @@ public class Images : Scenario
             Y = Pos.Bottom (btnSixel),
             Text = "Start Fire"
         };
-        btnStartFire.Accept += BtnStartFireOnAccept;
+        btnStartFire.Accepting += BtnStartFireOnAccept;
         _sixelSupported.Add (btnStartFire);
 
 
@@ -462,7 +463,7 @@ public class Images : Scenario
         }
     }
 
-    private void OutputSixelButtonClick (object sender, HandledEventArgs e)
+    private void OutputSixelButtonClick (object sender, CommandEventArgs e)
     {
         if (_imageView.FullResImage == null)
         {
@@ -555,7 +556,7 @@ public class Images : Scenario
             Text = "Ok"
         };
 
-        btn.Accept += (s, e) => Application.RequestStop ();
+        btn.Accepting += (s, e) => Application.RequestStop ();
         dlg.Add (pv);
         dlg.AddButton (btn);
         Application.Run (dlg);