Application.Driver.cs 2.1 KB

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