Application.Driver.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Diagnostics.CodeAnalysis;
  2. namespace Terminal.Gui.App;
  3. public static partial class Application // Driver abstractions
  4. {
  5. /// <inheritdoc cref="IApplication.Driver"/>
  6. public static IDriver? Driver
  7. {
  8. get => ApplicationImpl.Instance.Driver;
  9. internal set => ApplicationImpl.Instance.Driver = value;
  10. }
  11. /// <inheritdoc cref="IApplication.Force16Colors"/>
  12. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  13. public static bool Force16Colors
  14. {
  15. get => ApplicationImpl.Instance.Force16Colors;
  16. set => ApplicationImpl.Instance.Force16Colors = value;
  17. }
  18. /// <inheritdoc cref="IApplication.ForceDriver"/>
  19. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  20. public static string ForceDriver
  21. {
  22. get => ApplicationImpl.Instance.ForceDriver;
  23. set => ApplicationImpl.Instance.ForceDriver = value;
  24. }
  25. /// <inheritdoc cref="IApplication.Sixel"/>
  26. public static List<SixelToRender> Sixel => ApplicationImpl.Instance.Sixel;
  27. /// <summary>Gets a list of <see cref="IDriver"/> types and type names that are available.</summary>
  28. /// <returns></returns>
  29. [RequiresUnreferencedCode ("AOT")]
  30. public static (List<Type?>, List<string?>) GetDriverTypes ()
  31. {
  32. // use reflection to get the list of drivers
  33. List<Type?> driverTypes = new ();
  34. // Only inspect the IDriver assembly
  35. var asm = typeof (IDriver).Assembly;
  36. foreach (Type? type in asm.GetTypes ())
  37. {
  38. if (typeof (IDriver).IsAssignableFrom (type) && type is { IsAbstract: false, IsClass: true })
  39. {
  40. driverTypes.Add (type);
  41. }
  42. }
  43. List<string?> driverTypeNames = driverTypes
  44. .Where (d => !typeof (IDriver).IsAssignableFrom (d))
  45. .Select (d => d!.Name)
  46. .Union (["dotnet", "windows", "unix", "fake"])
  47. .ToList ()!;
  48. return (driverTypes, driverTypeNames);
  49. }
  50. }