#nullable enable using System.Globalization; using System.Text.Json.Serialization; namespace Terminal.Gui; /// /// Holds the s that define the s that are used by views to render /// themselves. /// public static class Colors { static Colors () { Reset (); } /// Gets a dictionary of defined objects. /// /// /// The dictionary includes the following keys, by default: /// /// /// Built-in Color Scheme Description /// /// /// Base The base color scheme used for most Views. /// /// /// TopLevel /// The application Toplevel color scheme; used for the View. /// /// /// Dialog /// /// The dialog color scheme; used for , , and /// other views dialog-like views. /// /// /// /// Menu /// /// The menu color scheme; used for , , and /// . /// /// /// /// Error /// /// The color scheme for showing errors, such as in /// . /// /// /// /// /// Changing the values of an entry in this dictionary will affect all views that use the scheme. /// /// can be used to override the default values for these schemes and add /// additional schemes. See . /// /// [SerializableConfigurationProperty (Scope = typeof (ThemeScope), OmitClassName = true)] [JsonConverter (typeof (DictionaryJsonConverter))] public static Dictionary ColorSchemes { get; private set; } // Serialization requires this to have a setter (private set;) /// Resets the dictionary to the default values. public static Dictionary Reset () { ColorSchemes ??= new Dictionary ( 5, CultureInfo.InvariantCulture.CompareInfo .GetStringComparer ( CompareOptions.IgnoreCase ) ); ColorSchemes.Clear (); ColorSchemes.Add ("TopLevel", new ColorScheme ()); ColorSchemes.Add ("Base", new ColorScheme ()); ColorSchemes.Add ("Dialog", new ColorScheme ()); ColorSchemes.Add ("Menu", new ColorScheme ()); ColorSchemes.Add ("Error", new ColorScheme ()); return ColorSchemes; } private class SchemeNameComparerIgnoreCase : IEqualityComparer { public bool Equals (string x, string y) { if (x is { } && y is { }) { return string.Equals (x, y, StringComparison.InvariantCultureIgnoreCase); } return false; } public int GetHashCode (string obj) { return obj.ToLowerInvariant ().GetHashCode (); } } }