using System;
namespace Spectre.Console
{
///
/// Represents color and style.
///
public sealed class Appearance : IEquatable
{
///
/// Gets the foreground color.
///
public Color Foreground { get; }
///
/// Gets the background color.
///
public Color Background { get; }
///
/// Gets the style.
///
public Styles Style { get; }
///
/// Gets an with the
/// default color and without style.
///
public static Appearance Plain { get; }
static Appearance()
{
Plain = new Appearance();
}
private Appearance()
: this(null, null, null)
{
}
///
/// Initializes a new instance of the class.
///
/// The foreground color.
/// The background color.
/// The style.
public Appearance(Color? foreground = null, Color? background = null, Styles? style = null)
{
Foreground = foreground ?? Color.Default;
Background = background ?? Color.Default;
Style = style ?? Styles.None;
}
///
public override int GetHashCode()
{
unchecked
{
var hash = (int)2166136261;
hash = (hash * 16777619) ^ Foreground.GetHashCode();
hash = (hash * 16777619) ^ Background.GetHashCode();
hash = (hash * 16777619) ^ Style.GetHashCode();
return hash;
}
}
///
public override bool Equals(object obj)
{
return Equals(obj as Appearance);
}
///
public bool Equals(Appearance other)
{
if (other == null)
{
return false;
}
return Foreground.Equals(other.Foreground) &&
Background.Equals(other.Background) &&
Style == other.Style;
}
}
}