From 23cd8889a526f20f7e4a6e96e87f6d9712a085e8 Mon Sep 17 00:00:00 2001 From: tznind Date: Thu, 3 Oct 2024 19:47:01 +0100 Subject: [PATCH] Do not output sixel if driver does not support it Allow overriding driver sixel support in Images scenario --- Terminal.Gui/ConsoleDrivers/NetDriver.cs | 11 +++++++---- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 9 ++++++--- UICatalog/Scenarios/Images.cs | 7 +++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index e2a9ff9d8..b5729406c 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -1024,12 +1024,15 @@ internal class NetDriver : ConsoleDriver Console.Write (output); } - foreach (var s in Application.Sixel) + if (ConsoleDriver.SupportsSixel) { - if (!string.IsNullOrWhiteSpace (s.SixelData)) + foreach (var s in Application.Sixel) { - SetCursorPosition (s.ScreenPosition.X, s.ScreenPosition.Y); - Console.Write (s.SixelData); + if (!string.IsNullOrWhiteSpace (s.SixelData)) + { + SetCursorPosition (s.ScreenPosition.X, s.ScreenPosition.Y); + Console.Write (s.SixelData); + } } } } diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index c476ae95e..aff9a57c8 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -127,11 +127,14 @@ internal class WindowsConsole _lastWrite = s; - foreach (var sixel in Application.Sixel) + if (ConsoleDriver.SupportsSixel) { - SetCursorPosition (new Coord ((short)sixel.ScreenPosition.X, (short)sixel.ScreenPosition.Y)); - WriteConsole (_screenBuffer, sixel.SixelData, (uint)sixel.SixelData.Length, out uint _, nint.Zero); + foreach (var sixel in Application.Sixel) + { + SetCursorPosition (new Coord ((short)sixel.ScreenPosition.X, (short)sixel.ScreenPosition.Y)); + WriteConsole (_screenBuffer, sixel.SixelData, (uint)sixel.SixelData.Length, out uint _, nint.Zero); + } } } diff --git a/UICatalog/Scenarios/Images.cs b/UICatalog/Scenarios/Images.cs index 3b275cb56..16c350c24 100644 --- a/UICatalog/Scenarios/Images.cs +++ b/UICatalog/Scenarios/Images.cs @@ -62,10 +62,13 @@ public class Images : Scenario Y = 1, CheckedState = ConsoleDriver.SupportsSixel ? CheckState.Checked : CheckState.UnChecked, - CanFocus = false, - Enabled = false, Text = "Supports Sixel" }; + + cbSupportsSixel.CheckedStateChanging += (s, e) => + { + ConsoleDriver.SupportsSixel = e.NewValue == CheckState.Checked; + }; _win.Add (cbSupportsSixel); var cbUseTrueColor = new CheckBox