Application.Driver.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. private static bool _force16Colors = false; // Resources/config.json overrides
  13. /// <inheritdoc cref="IApplication.Force16Colors"/>
  14. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  15. [Obsolete ("The legacy static Application object is going away.")]
  16. public static bool Force16Colors
  17. {
  18. get => _force16Colors;
  19. set
  20. {
  21. bool oldValue = _force16Colors;
  22. _force16Colors = value;
  23. Force16ColorsChanged?.Invoke (null, new ValueChangedEventArgs<bool> (oldValue, _force16Colors));
  24. }
  25. }
  26. /// <summary>Raised when <see cref="Force16Colors"/> changes.</summary>
  27. public static event EventHandler<ValueChangedEventArgs<bool>>? Force16ColorsChanged;
  28. private static string _forceDriver = string.Empty; // Resources/config.json overrides
  29. /// <inheritdoc cref="IApplication.ForceDriver"/>
  30. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  31. [Obsolete ("The legacy static Application object is going away.")]
  32. public static string ForceDriver
  33. {
  34. get => _forceDriver;
  35. set
  36. {
  37. string oldValue = _forceDriver;
  38. _forceDriver = value;
  39. ForceDriverChanged?.Invoke (null, new ValueChangedEventArgs<string> (oldValue, _forceDriver));
  40. }
  41. }
  42. /// <summary>Raised when <see cref="ForceDriver"/> changes.</summary>
  43. public static event EventHandler<ValueChangedEventArgs<string>>? ForceDriverChanged;
  44. /// <inheritdoc cref="IApplication.Sixel"/>
  45. [Obsolete ("The legacy static Application object is going away.")]
  46. public static List<SixelToRender> Sixel => ApplicationImpl.Instance.Sixel;
  47. /// <summary>Gets a list of <see cref="IDriver"/> types and type names that are available.</summary>
  48. /// <returns></returns>
  49. [RequiresUnreferencedCode ("AOT")]
  50. [Obsolete ("The legacy static Application object is going away.")]
  51. public static (List<Type?>, List<string?>) GetDriverTypes ()
  52. {
  53. // use reflection to get the list of drivers
  54. List<Type?> driverTypes = new ();
  55. // Only inspect the IDriver assembly
  56. var asm = typeof (IDriver).Assembly;
  57. foreach (Type? type in asm.GetTypes ())
  58. {
  59. if (typeof (IDriver).IsAssignableFrom (type) && type is { IsAbstract: false, IsClass: true })
  60. {
  61. driverTypes.Add (type);
  62. }
  63. }
  64. List<string?> driverTypeNames = driverTypes
  65. .Where (d => !typeof (IDriver).IsAssignableFrom (d))
  66. .Select (d => d!.Name)
  67. .Union (["dotnet", "windows", "unix", "fake"])
  68. .ToList ()!;
  69. return (driverTypes, driverTypeNames);
  70. }
  71. }