#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
{
/// 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; init; }
/// The foreground and background color for text when the view has the focus.
public Attribute Focus { get; init; }
/// The foreground and background color for text in a focused view that indicates a .
public Attribute HotFocus { get; init; }
/// The foreground and background color for text in a non-focused view that indicates a .
public Attribute HotNormal { get; init; }
/// The foreground and background color for text when the view is not focused, hot, or disabled.
public Attribute Normal { get; init; }
///
/// Gets a new with the same values as this instance, but with the foreground and background
/// colors adjusted to be more visible.
///
///
public ColorScheme GetHighlightColorScheme ()
{
return this with
{
Normal = new (Normal.Foreground.GetHighlightColor (), Normal.Background),
HotNormal = new (HotNormal.Foreground.GetHighlightColor (), HotNormal.Background),
Focus = new (Focus.Foreground.GetHighlightColor (), Focus.Background),
HotFocus = new (HotFocus.Foreground.GetHighlightColor (), HotFocus.Background)
};
}
/// 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}"; }
}