Fix for accepting

This commit is contained in:
tznind
2024-10-10 10:32:08 +01:00
parent 1c3b0d7605
commit 9990a552d2
5 changed files with 50 additions and 11 deletions

View File

@@ -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

View File

@@ -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
};
}
}

View File

@@ -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 ();
}

View File

@@ -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;
}
}
}*/

View File

@@ -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);