|
@@ -15,7 +15,7 @@ namespace Terminal.Gui {
|
|
|
/// Colors that can be used to set the foreground and background colors in console applications.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
- /// The <see cref="Color.Invalid"/> value indicates either no-color has been set or the color is invalid.
|
|
|
+ /// The <see cref="Attribute.HasValidColors"/> value indicates either no-color has been set or the color is invalid.
|
|
|
/// </remarks>
|
|
|
public enum Color {
|
|
|
/// <summary>
|
|
@@ -81,11 +81,7 @@ namespace Terminal.Gui {
|
|
|
/// <summary>
|
|
|
/// The White color.
|
|
|
/// </summary>
|
|
|
- White,
|
|
|
- /// <summary>
|
|
|
- /// Indicates an invalid or un-set color value.
|
|
|
- /// </summary>
|
|
|
- Invalid = -1
|
|
|
+ White
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -177,7 +173,7 @@ namespace Terminal.Gui {
|
|
|
public struct Attribute {
|
|
|
/// <summary>
|
|
|
/// The <see cref="ConsoleDriver"/>-specific color attribute value. If <see cref="Initialized"/> is <see langword="false"/>
|
|
|
- /// the value of this property is invalid (typcially because the Attribute was created before a driver was loaded)
|
|
|
+ /// the value of this property is invalid (typically because the Attribute was created before a driver was loaded)
|
|
|
/// and the attribute should be re-made (see <see cref="Make(Color, Color)"/>) before it is used.
|
|
|
/// </summary>
|
|
|
public int Value { get; }
|
|
@@ -199,8 +195,8 @@ namespace Terminal.Gui {
|
|
|
/// <param name="value">Value.</param>
|
|
|
public Attribute (int value)
|
|
|
{
|
|
|
- Color foreground = Color.Invalid;
|
|
|
- Color background = Color.Invalid;
|
|
|
+ Color foreground = default;
|
|
|
+ Color background = default;
|
|
|
|
|
|
Initialized = false;
|
|
|
if (Application.Driver != null) {
|
|
@@ -280,9 +276,9 @@ namespace Terminal.Gui {
|
|
|
{
|
|
|
if (Application.Driver == null) {
|
|
|
// Create the attribute, but show it's not been initialized
|
|
|
- var a = new Attribute (-1, foreground, background);
|
|
|
- a.Initialized = false;
|
|
|
- return a;
|
|
|
+ return new Attribute (-1, foreground, background) {
|
|
|
+ Initialized = false
|
|
|
+ };
|
|
|
}
|
|
|
return Application.Driver.MakeAttribute (foreground, background);
|
|
|
}
|
|
@@ -299,10 +295,10 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// If <see langword="true"/> the attribute has been initialzed by a <see cref="ConsoleDriver"/> and
|
|
|
+ /// If <see langword="true"/> the attribute has been initialized by a <see cref="ConsoleDriver"/> and
|
|
|
/// thus has <see cref="Value"/> that is valid for that driver. If <see langword="false"/> the <see cref="Foreground"/>
|
|
|
- /// and <see cref="Background"/> colors may have been set (see <see cref="Color.Invalid"/>) but
|
|
|
- /// the attribute has not been mapped to a <see cref="ConsoleDriver"/> specific color value.
|
|
|
+ /// and <see cref="Background"/> colors may have been set '-1' but
|
|
|
+ /// the attribute has not been mapped to a <see cref="ConsoleDriver"/> specific color value.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
/// Attributes that have not been initialized must eventually be initialized before being passed to a driver.
|
|
@@ -310,14 +306,10 @@ namespace Terminal.Gui {
|
|
|
public bool Initialized { get; internal set; }
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Returns <see langword="true"/> if the Atrribute is valid (both foreground and background have valid color values).
|
|
|
+ /// Returns <see langword="true"/> if the Attribute is valid (both foreground and background have valid color values).
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- public bool HasValidColors {
|
|
|
- get {
|
|
|
- return Foreground != Color.Invalid && Background != Color.Invalid;
|
|
|
- }
|
|
|
- }
|
|
|
+ public bool HasValidColors { get => (int)Foreground > -1 && (int)Background > -1; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -329,7 +321,7 @@ namespace Terminal.Gui {
|
|
|
/// See also: <see cref="Colors.ColorSchemes"/>.
|
|
|
/// </remarks>
|
|
|
public class ColorScheme : IEquatable<ColorScheme> {
|
|
|
- Attribute _normal = new Attribute(Color.White, Color.Black);
|
|
|
+ Attribute _normal = new Attribute (Color.White, Color.Black);
|
|
|
Attribute _focus = new Attribute (Color.White, Color.Black);
|
|
|
Attribute _hotNormal = new Attribute (Color.White, Color.Black);
|
|
|
Attribute _hotFocus = new Attribute (Color.White, Color.Black);
|
|
@@ -520,13 +512,13 @@ namespace Terminal.Gui {
|
|
|
/// <summary>
|
|
|
/// Creates a new dictionary of new <see cref="ColorScheme"/> objects.
|
|
|
/// </summary>
|
|
|
- public static Dictionary<string, ColorScheme> Create ()
|
|
|
+ public static Dictionary<string, ColorScheme> Create ()
|
|
|
{
|
|
|
// Use reflection to dynamically create the default set of ColorSchemes from the list defined
|
|
|
// by the class.
|
|
|
return typeof (Colors).GetProperties ()
|
|
|
.Where (p => p.PropertyType == typeof (ColorScheme))
|
|
|
- .Select (p => new KeyValuePair<string, ColorScheme> (p.Name, new ColorScheme()))
|
|
|
+ .Select (p => new KeyValuePair<string, ColorScheme> (p.Name, new ColorScheme ()))
|
|
|
.ToDictionary (t => t.Key, t => t.Value, comparer: new SchemeNameComparerIgnoreCase ());
|
|
|
}
|
|
|
|
|
@@ -881,7 +873,7 @@ namespace Terminal.Gui {
|
|
|
/// The current attribute the driver is using.
|
|
|
/// </summary>
|
|
|
public virtual Attribute CurrentAttribute {
|
|
|
- get => currentAttribute;
|
|
|
+ get => currentAttribute;
|
|
|
set {
|
|
|
if (!value.Initialized && value.HasValidColors && Application.Driver != null) {
|
|
|
CurrentAttribute = Application.Driver.MakeAttribute (value.Foreground, value.Background);
|
|
@@ -1463,13 +1455,13 @@ namespace Terminal.Gui {
|
|
|
public abstract Attribute MakeColor (Color foreground, Color background);
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Ensures all <see cref="Attribute"/>s in <see cref="Colors.ColorSchemes"/> are correclty
|
|
|
- /// initalized by the driver.
|
|
|
+ /// Ensures all <see cref="Attribute"/>s in <see cref="Colors.ColorSchemes"/> are correctly
|
|
|
+ /// initialized by the driver.
|
|
|
/// </summary>
|
|
|
/// <param name="supportsColors">Flag indicating if colors are supported (not used).</param>
|
|
|
public void InitalizeColorSchemes (bool supportsColors = true)
|
|
|
{
|
|
|
- // Ensure all Attributes are initlaized by the driver
|
|
|
+ // Ensure all Attributes are initialized by the driver
|
|
|
foreach (var s in Colors.ColorSchemes) {
|
|
|
s.Value.Initialize ();
|
|
|
}
|
|
@@ -1480,7 +1472,7 @@ namespace Terminal.Gui {
|
|
|
|
|
|
|
|
|
// Define the default color theme only if the user has not defined one.
|
|
|
-
|
|
|
+
|
|
|
Colors.TopLevel.Normal = MakeColor (Color.BrightGreen, Color.Black);
|
|
|
Colors.TopLevel.Focus = MakeColor (Color.White, Color.Cyan);
|
|
|
Colors.TopLevel.HotNormal = MakeColor (Color.Brown, Color.Black);
|