Application.Driver.cs 2.4 KB

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