SixelSupportDetector.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Terminal.Gui;
  7. /// <summary>
  8. /// Uses ANSII escape sequences to detect whether sixel is supported
  9. /// by the terminal.
  10. /// </summary>
  11. public class SixelSupportDetector
  12. {
  13. public SixelSupport Detect ()
  14. {
  15. var darResponse = AnsiEscapeSequenceRequest.ExecuteAnsiRequest (EscSeqUtils.CSI_SendDeviceAttributes);
  16. var result = new SixelSupport ();
  17. result.IsSupported = darResponse.Response.Split (';').Contains ("4");
  18. return result;
  19. }
  20. }
  21. public class SixelSupport
  22. {
  23. /// <summary>
  24. /// Whether the current driver supports sixel graphic format.
  25. /// Defaults to false.
  26. /// </summary>
  27. public bool IsSupported { get; set; }
  28. /// <summary>
  29. /// The number of pixels of sixel that corresponds to each Col (<see cref="Size.Width"/>)
  30. /// and each Row (<see cref="Size.Height"/>. Defaults to 10x20.
  31. /// </summary>
  32. public Size Resolution { get; set; } = new Size (10, 20);
  33. /// <summary>
  34. /// The maximum number of colors that can be included in a sixel image. Defaults
  35. /// to 256.
  36. /// </summary>
  37. public int MaxPaletteColors { get; set; } = 256;
  38. }