Application.Driver.cs 2.6 KB

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