Application.Driver.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. [Obsolete ("The legacy static Application object is going away.")]
  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. [Obsolete ("The legacy static Application object is going away.")]
  15. public static bool Force16Colors
  16. {
  17. get => ApplicationImpl.Instance.Force16Colors;
  18. set => ApplicationImpl.Instance.Force16Colors = value;
  19. }
  20. /// <inheritdoc cref="IApplication.ForceDriver"/>
  21. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  22. [Obsolete ("The legacy static Application object is going away.")]
  23. public static string ForceDriver
  24. {
  25. get => ApplicationImpl.Instance.ForceDriver;
  26. set
  27. {
  28. if (!string.IsNullOrEmpty (ApplicationImpl.Instance.ForceDriver) && value != Driver?.GetName ())
  29. {
  30. // ForceDriver cannot be changed if it has a valid value
  31. return;
  32. }
  33. if (ApplicationImpl.Instance.Initialized && value != Driver?.GetName ())
  34. {
  35. throw new InvalidOperationException ($"The {nameof (ForceDriver)} can only be set before initialized.");
  36. }
  37. ApplicationImpl.Instance.ForceDriver = value;
  38. }
  39. }
  40. /// <inheritdoc cref="IApplication.Sixel"/>
  41. [Obsolete ("The legacy static Application object is going away.")]
  42. public static List<SixelToRender> Sixel => ApplicationImpl.Instance.Sixel;
  43. /// <summary>Gets a list of <see cref="IDriver"/> types and type names that are available.</summary>
  44. /// <returns></returns>
  45. [RequiresUnreferencedCode ("AOT")]
  46. [Obsolete ("The legacy static Application object is going away.")]
  47. public static (List<Type?>, List<string?>) GetDriverTypes ()
  48. {
  49. // use reflection to get the list of drivers
  50. List<Type?> driverTypes = new ();
  51. // Only inspect the IDriver assembly
  52. var asm = typeof (IDriver).Assembly;
  53. foreach (Type? type in asm.GetTypes ())
  54. {
  55. if (typeof (IDriver).IsAssignableFrom (type) && type is { IsAbstract: false, IsClass: true })
  56. {
  57. driverTypes.Add (type);
  58. }
  59. }
  60. List<string?> driverTypeNames = driverTypes
  61. .Where (d => !typeof (IDriver).IsAssignableFrom (d))
  62. .Select (d => d!.Name)
  63. .Union (["dotnet", "windows", "unix", "fake"])
  64. .ToList ()!;
  65. return (driverTypes, driverTypeNames);
  66. }
  67. }