ColorScheme.Colors.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #nullable enable
  2. using System.Text.Json.Serialization;
  3. namespace Terminal.Gui;
  4. /// <summary>
  5. /// Holds the <see cref="ColorScheme"/>s that define the <see cref="Attribute"/>s that are used by views to render
  6. /// themselves.
  7. /// </summary>
  8. public static class Colors
  9. {
  10. static Colors ()
  11. {
  12. ColorSchemes = new (5, StringComparer.InvariantCultureIgnoreCase);
  13. Reset ();
  14. }
  15. /// <summary>Gets a dictionary of defined <see cref="ColorScheme"/> objects.</summary>
  16. /// <remarks>
  17. /// <para>
  18. /// The <see cref="ColorSchemes"/> dictionary includes the following keys, by default:
  19. /// <list type="table">
  20. /// <listheader>
  21. /// <term>Built-in Color Scheme</term> <description>Description</description>
  22. /// </listheader>
  23. /// <item>
  24. /// <term>Base</term> <description>The base color scheme used for most Views.</description>
  25. /// </item>
  26. /// <item>
  27. /// <term>TopLevel</term>
  28. /// <description>The application Toplevel color scheme; used for the <see cref="Toplevel"/> View.</description>
  29. /// </item>
  30. /// <item>
  31. /// <term>Dialog</term>
  32. /// <description>
  33. /// The dialog color scheme; used for <see cref="Dialog"/>, <see cref="MessageBox"/>, and
  34. /// other views dialog-like views.
  35. /// </description>
  36. /// </item>
  37. /// <item>
  38. /// <term>Menu</term>
  39. /// <description>
  40. /// The menu color scheme; used for <see cref="MenuBar"/>, <see cref="ContextMenu"/>, and
  41. /// <see cref="StatusBar"/>.
  42. /// </description>
  43. /// </item>
  44. /// <item>
  45. /// <term>Error</term>
  46. /// <description>
  47. /// The color scheme for showing errors, such as in
  48. /// <see cref="MessageBox.ErrorQuery(string, string, string[])"/>.
  49. /// </description>
  50. /// </item>
  51. /// </list>
  52. /// </para>
  53. /// <para>Changing the values of an entry in this dictionary will affect all views that use the scheme.</para>
  54. /// <para>
  55. /// <see cref="ConfigurationManager"/> can be used to override the default values for these schemes and add
  56. /// additional schemes. See <see cref="ConfigurationManager.Themes"/>.
  57. /// </para>
  58. /// </remarks>
  59. [SerializableConfigurationProperty (Scope = typeof (ThemeScope), OmitClassName = true)]
  60. [JsonConverter (typeof (DictionaryJsonConverter<ColorScheme>))]
  61. public static Dictionary<string, ColorScheme> ColorSchemes { get; private set; }
  62. /// <summary>Resets the <see cref="ColorSchemes"/> dictionary to the default values.</summary>
  63. public static Dictionary<string, ColorScheme> Reset ()
  64. {
  65. ColorSchemes.Clear ();
  66. ColorSchemes.Add ("TopLevel", new ());
  67. ColorSchemes.Add ("Base", new ());
  68. ColorSchemes.Add ("Dialog", new ());
  69. ColorSchemes.Add ("Menu", new ());
  70. ColorSchemes.Add ("Error", new ());
  71. return ColorSchemes;
  72. }
  73. }