#nullable enable using System.Numerics; using System.Text.Json.Serialization; namespace Terminal.Gui; /// Defines a standard set of s for common visible elements in a . /// /// /// ColorScheme objects are immutable. Once constructed, the properties cannot be changed. To change a /// ColorScheme, create a new one with the desired values, using the /// constructor. /// /// [JsonConverter (typeof (ColorSchemeJsonConverter))] public record ColorScheme : IEqualityOperators { private readonly Attribute _disabled; private readonly Attribute _focus; private readonly Attribute _hotFocus; private readonly Attribute _hotNormal; private readonly Attribute _normal; /// Creates a new instance set to the default colors (see ). public ColorScheme () : this (Attribute.Default) { } /// Creates a new instance, initialized with the values from . /// The scheme to initialize the new instance with. public ColorScheme (ColorScheme? scheme) { ArgumentNullException.ThrowIfNull (scheme); _normal = scheme.Normal; _focus = scheme.Focus; _hotNormal = scheme.HotNormal; _disabled = scheme.Disabled; _hotFocus = scheme.HotFocus; } /// Creates a new instance, initialized with the values from . /// The attribute to initialize the new instance with. public ColorScheme (Attribute attribute) { _normal = attribute; _focus = attribute; _hotNormal = attribute; _disabled = attribute; _hotFocus = attribute; } /// Creates a new instance, initialized with the values provided. public ColorScheme ( Attribute normal, Attribute focus, Attribute hotNormal, Attribute disabled, Attribute hotFocus) { _normal = normal; _focus = focus; _hotNormal = hotNormal; _disabled = disabled; _hotFocus = hotFocus; } /// The default foreground and background color for text when the view is disabled. public Attribute Disabled { get => _disabled; init => _disabled = value; } /// The foreground and background color for text when the view has the focus. public Attribute Focus { get => _focus; init => _focus = value; } /// The foreground and background color for text in a focused view that indicates a . public Attribute HotFocus { get => _hotFocus; init => _hotFocus = value; } /// The foreground and background color for text in a non-focused view that indicates a . public Attribute HotNormal { get => _hotNormal; init => _hotNormal = value; } /// The foreground and background color for text when the view is not focused, hot, or disabled. public Attribute Normal { get => _normal; init => _normal = value; } /// Compares two objects for equality. /// /// true if the two objects are equal public virtual bool Equals (ColorScheme? other) { return other is { } && EqualityComparer.Default.Equals (_normal, other._normal) && EqualityComparer.Default.Equals (_focus, other._focus) && EqualityComparer.Default.Equals (_hotNormal, other._hotNormal) && EqualityComparer.Default.Equals (_hotFocus, other._hotFocus) && EqualityComparer.Default.Equals (_disabled, other._disabled); } /// Returns a hashcode for this instance. /// hashcode for this instance public override int GetHashCode () { return HashCode.Combine (_normal, _focus, _hotNormal, _hotFocus, _disabled); } /// public override string ToString () { return $"Normal: {Normal}; Focus: {Focus}; HotNormal: {HotNormal}; HotFocus: {HotFocus}; Disabled: {Disabled}"; } }