diff --git a/Terminal.Gui/Drawing/Color.cs b/Terminal.Gui/Drawing/Color.cs
index 0798cd42e..c343727f6 100644
--- a/Terminal.Gui/Drawing/Color.cs
+++ b/Terminal.Gui/Drawing/Color.cs
@@ -219,16 +219,6 @@ namespace Terminal.Gui {
///
private static Color FromColorName (ColorNames consoleColor) => _colorNames.FirstOrDefault (x => x.Value == consoleColor).Key;
- ///
- /// Converts a legacy index to a 24-bit .
- ///
- /// The index into the enum to convert.
- ///
- private static Color FromColorName (int colorNameId)
- {
- return FromColorName ((ColorNames)colorNameId);
- }
-
// Iterates through the entries in the _colorNames dictionary, calculates the
// Euclidean distance between the input color and each dictionary color in RGB space,
// and keeps track of the closest entry found so far. The function returns a KeyValuePair
@@ -258,7 +248,7 @@ namespace Terminal.Gui {
return Math.Sqrt (deltaR * deltaR + deltaG * deltaG + deltaB * deltaB);
}
-
+
///
/// Gets or sets the using a legacy 16-color value.
///
@@ -266,9 +256,7 @@ namespace Terminal.Gui {
/// Get returns the closest 24-bit color value. Set sets the RGB value using a hard-coded map.
///
public ColorNames ColorName {
- get {
- return FindClosestColor (this.Value);
- }
+ get => FindClosestColor (this.Value);
set {
var c = FromColorName (value);
@@ -347,7 +335,7 @@ namespace Terminal.Gui {
///
public const ColorNames White = ColorNames.White;
#endregion
-
+
///
/// Converts the provided text to a new instance.
///
@@ -468,37 +456,67 @@ namespace Terminal.Gui {
}
- ///
+ ///
+ /// Equality operator for two objects..
+ ///
+ ///
+ ///
+ ///
public static bool operator == (Color left, Color right)
{
return left.Equals (right);
}
- ///
+ ///
+ /// Inequality operator for two objects.
+ ///
+ ///
+ ///
+ ///
public static bool operator != (Color left, Color right)
{
return !left.Equals (right);
}
- ///
+ ///
+ /// Equality operator for and objects.
+ ///
+ ///
+ ///
+ ///
public static bool operator == (ColorNames left, Color right)
{
return left == right.ColorName;
}
- ///
+ ///
+ /// Inequality operator for and objects.
+ ///
+ ///
+ ///
+ ///
public static bool operator != (ColorNames left, Color right)
{
return left != right.ColorName;
}
- ///
+ ///
+ /// Equality operator for and objects.
+ ///
+ ///
+ ///
+ ///
public static bool operator == (Color left, ColorNames right)
{
return left.ColorName == right;
}
- ///
+ ///
+ /// Inequality operator for and objects.
+ ///
+ ///
+ ///
+ ///
public static bool operator != (Color left, ColorNames right)
{
return left.ColorName != right;
@@ -598,39 +616,7 @@ namespace Terminal.Gui {
/// Initializes a new instance with platform specific color value.
///
/// Value.
- internal Attribute (int platformColor)
- {
- ColorNames foreground = Default.Foreground.ColorName;
- ColorNames background = Default.Background.ColorName;
-
- Initialized = false;
- if (Application.Driver != null) {
- Application.Driver.GetColors (platformColor, out foreground, out background);
- Initialized = true;
- }
- Value = platformColor;
- Foreground = (Color)foreground;
- Background = (Color)background;
- }
-
- ///
- /// Initializes a new instance with a value.
- ///
- /// Value.
- internal Attribute (ColorNames colorName)
- {
- ColorNames foreground = colorName;
- ColorNames background = colorName;
-
- Initialized = false;
- if (Application.Driver != null) {
- Application.Driver.GetColors ((int)colorName, out foreground, out background);
- Initialized = true;
- }
- Value = ((Color)colorName).Value;
- Foreground = (Color)foreground;
- Background = (Color)background;
- }
+ internal Attribute (int platformColor) : this (platformColor, Default.Foreground, Default.Background) { }
///
/// Initializes a new instance of the struct.
@@ -652,13 +638,7 @@ namespace Terminal.Gui {
/// platform-dependent color value.
/// Foreground
/// Background
- internal Attribute (int platformColor, ColorNames foreground, ColorNames background)
- {
- Foreground = (Color)foreground;
- Background = (Color)background;
- Value = platformColor;
- Initialized = true;
- }
+ internal Attribute (int platformColor, ColorNames foreground, ColorNames background) : this (platformColor, (Color)foreground, (Color)background) { }
///
/// Initializes a new instance of the struct.
@@ -670,56 +650,46 @@ namespace Terminal.Gui {
Foreground = foreground;
Background = background;
- var make = Make (foreground, background);
+ if (Application.Driver == null) {
+ // Create the attribute, but show it's not been initialized
+ Initialized = false;
+ Value = -1;
+ return;
+ }
+
+ var make = Application.Driver.MakeAttribute (foreground, background);
Initialized = make.Initialized;
Value = make.Value;
}
+ ///
+ /// Initializes a new instance with a value. Both and
+ /// will be set to the specified color.
+ ///
+ /// Value.
+ internal Attribute (ColorNames colorName) : this (colorName, colorName) { }
+
///
/// Initializes a new instance of the struct.
///
- /// Foreground
- /// Background
- public Attribute (ColorNames foreground, ColorNames background)
- {
- Foreground = new Color (foreground);
- Background = new Color (background);
-
- var make = Make (foreground, background);
- Initialized = make.Initialized;
- Value = make.Value;
- }
+ /// Foreground
+ /// Background
+ public Attribute (ColorNames foregroundName, ColorNames backgroundName) : this (new Color (foregroundName), new Color (backgroundName)) { }
///
/// Initializes a new instance of the struct.
///
- /// Foreground
+ /// Foreground
/// Background
- public Attribute (ColorNames foreground, Color background)
- {
- Foreground = new Color (foreground);
- Background = background;
-
- var make = Make (foreground, background);
- Initialized = make.Initialized;
- Value = make.Value;
- }
+ public Attribute (ColorNames foregroundName, Color background) : this (new Color (foregroundName), background) { }
///
/// Initializes a new instance of the struct.
///
/// Foreground
- /// Background
- public Attribute (Color foreground, ColorNames background)
- {
- Foreground = foreground;
- Background = new Color (background);
-
- var make = Make (foreground, background);
- Initialized = make.Initialized;
- Value = make.Value;
- }
+ /// Background
+ public Attribute (Color foreground, ColorNames backgroundName) : this (foreground, new Color (backgroundName)) { }
///
/// Initializes a new instance of the struct
@@ -762,99 +732,6 @@ namespace Terminal.Gui {
///
public override int GetHashCode () => HashCode.Combine (Value, Foreground, Background);
- ///
- /// Creates an from the specified foreground and background colors.
- ///
- ///
- /// If a has not been loaded (Application.Driver == null) this
- /// method will return an attribute with set to .
- ///
- /// The new attribute.
- /// Foreground color to use.
- /// Background color to use.
- public static Attribute Make (Color foreground, Color background)
- {
- if (Application.Driver == null) {
- // Create the attribute, but show it's not been initialized
- return new Attribute () {
- Initialized = false,
- Foreground = foreground,
- Background = background
- };
- }
- return Application.Driver.MakeAttribute (foreground, background);
- }
-
-
- ///
- /// Creates an from the specified foreground and background colors.
- ///
- ///
- /// If a has not been loaded (Application.Driver == null) this
- /// method will return an attribute with set to .
- ///
- /// The new attribute.
- /// Foreground color to use.
- /// Background color to use.
- public static Attribute Make (ColorNames foreground, ColorNames background)
- {
- if (Application.Driver == null) {
- // Create the attribute, but show it's not been initialized
- return new Attribute () {
- Initialized = false,
- Foreground = new Color (foreground),
- Background = new Color (background)
- };
- }
- return Application.Driver.MakeAttribute (foreground, background);
- }
-
- ///
- /// Creates an from the specified foreground and background colors.
- ///
- ///
- /// If a has not been loaded (Application.Driver == null) this
- /// method will return an attribute with set to .
- ///
- /// The new attribute.
- /// Foreground color to use.
- /// Background color to use.
- public static Attribute Make (ColorNames foreground, Color background)
- {
- if (Application.Driver == null) {
- // Create the attribute, but show it's not been initialized
- return new Attribute () {
- Initialized = false,
- Foreground = new Color (foreground),
- Background = background
- };
- }
- return Application.Driver.MakeAttribute (new Color (foreground), background);
- }
-
- ///
- /// Creates an from the specified foreground and background colors.
- ///
- ///
- /// If a has not been loaded (Application.Driver == null) this
- /// method will return an attribute with set to .
- ///
- /// The new attribute.
- /// Foreground color to use.
- /// Background color to use.
- public static Attribute Make (Color foreground, ColorNames background)
- {
- if (Application.Driver == null) {
- // Create the attribute, but show it's not been initialized
- return new Attribute () {
- Initialized = false,
- Foreground = foreground,
- Background = new Color (background)
- };
- }
- return Application.Driver.MakeAttribute (foreground, new Color (background));
- }
-
///
/// Gets the current from the driver.
///
diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs
index 5f6dfd9c5..195a9d9f9 100644
--- a/Terminal.Gui/Views/FileDialog.cs
+++ b/Terminal.Gui/Views/FileDialog.cs
@@ -663,7 +663,7 @@ namespace Terminal.Gui {
tbPath.Caption = Style.PathCaption;
tbFind.Caption = Style.SearchCaption;
- tbPath.Autocomplete.ColorScheme.Normal = Attribute.Make (Color.Black, tbPath.ColorScheme.Normal.Background);
+ tbPath.Autocomplete.ColorScheme.Normal = new Attribute (Color.Black, tbPath.ColorScheme.Normal.Background);
_treeRoots = Style.TreeRootGetter ();
Style.IconProvider.IsOpenGetter = treeView.IsExpanded;
diff --git a/Terminal.sln.DotSettings b/Terminal.sln.DotSettings
index 88ef43749..388ebb2da 100644
--- a/Terminal.sln.DotSettings
+++ b/Terminal.sln.DotSettings
@@ -128,4 +128,5 @@
True
True
True
+ True
True
diff --git a/UnitTests/Configuration/JsonConverterTests.cs b/UnitTests/Configuration/JsonConverterTests.cs
index a80c64e86..2b2796d52 100644
--- a/UnitTests/Configuration/JsonConverterTests.cs
+++ b/UnitTests/Configuration/JsonConverterTests.cs
@@ -232,11 +232,11 @@ namespace Terminal.Gui.ConfigurationTests {
{
// Arrange
var expectedColorScheme = new ColorScheme {
- Normal = Attribute.Make (Color.White, Color.Blue),
- Focus = Attribute.Make (Color.Black, Color.Gray),
- HotNormal = Attribute.Make (Color.BrightCyan, Color.Blue),
- HotFocus = Attribute.Make (Color.BrightBlue, Color.Gray),
- Disabled = Attribute.Make (Color.DarkGray, Color.Blue)
+ Normal = new Attribute (Color.White, Color.Blue),
+ Focus = new Attribute (Color.Black, Color.Gray),
+ HotNormal = new Attribute (Color.BrightCyan, Color.Blue),
+ HotFocus = new Attribute (Color.BrightBlue, Color.Gray),
+ Disabled = new Attribute (Color.DarkGray, Color.Blue)
};
var serializedColorScheme = JsonSerializer.Serialize (expectedColorScheme, ConfigurationManagerTests._jsonOptions);
diff --git a/UnitTests/Drawing/AttributeTests.cs b/UnitTests/Drawing/AttributeTests.cs
index 7ee4900c7..51f46e150 100644
--- a/UnitTests/Drawing/AttributeTests.cs
+++ b/UnitTests/Drawing/AttributeTests.cs
@@ -30,7 +30,7 @@ public class AttributeTests {
var attribute = new Attribute (42);
// Assert
- Assert.False (attribute.Initialized);
+ Assert.True (attribute.Initialized);
Assert.Equal (42, attribute.Value);
Assert.Equal ((Color)Color.White, attribute.Foreground);
Assert.Equal ((Color)Color.Black, attribute.Background);
@@ -138,7 +138,7 @@ public class AttributeTests {
var backgroundColor = new Color (255, 255, 255);
// Act
- var attribute = Attribute.Make (foregroundColor, backgroundColor);
+ var attribute = new Attribute (foregroundColor, backgroundColor);
// Assert
Assert.Equal (foregroundColor, attribute.Foreground);
@@ -153,7 +153,7 @@ public class AttributeTests {
var backgroundColorName = ColorNames.Black;
// Act
- var attribute = Attribute.Make (foregroundColorName, backgroundColorName);
+ var attribute = new Attribute (foregroundColorName, backgroundColorName);
// Assert
Assert.Equal ((Color)foregroundColorName, attribute.Foreground);
@@ -168,7 +168,7 @@ public class AttributeTests {
var backgroundColor = new Color (128, 128, 128);
// Act
- var attribute = Attribute.Make (foregroundColorName, backgroundColor);
+ var attribute = new Attribute (foregroundColorName, backgroundColor);
// Assert
Assert.Equal ((Color)foregroundColorName, attribute.Foreground);
@@ -183,7 +183,7 @@ public class AttributeTests {
var backgroundColorName = ColorNames.White;
// Act
- var attribute = Attribute.Make (foregroundColor, backgroundColorName);
+ var attribute = new Attribute (foregroundColor, backgroundColorName);
// Assert
Assert.Equal (foregroundColor, attribute.Foreground);
@@ -228,7 +228,7 @@ public class AttributeTests {
var bg = new Color ();
bg = (Color)Color.Blue;
- var a = Attribute.Make (fg, bg);
+ var a = new Attribute (fg, bg);
Assert.False (a.Initialized);
}
@@ -246,7 +246,7 @@ public class AttributeTests {
var bg = new Color ();
bg = (Color)Color.Blue;
- var attr = Attribute.Make (fg, bg);
+ var attr = new Attribute (fg, bg);
Assert.True (attr.Initialized);
Assert.Equal (fg, attr.Foreground);
Assert.Equal (bg, attr.Background);
@@ -265,7 +265,7 @@ public class AttributeTests {
var bg = new Color ();
bg = (Color)Color.Blue;
- var attr = Attribute.Make (fg, bg);
+ var attr = new Attribute (fg, bg);
Assert.False (attr.Initialized);
Assert.Equal (fg, attr.Foreground);
Assert.Equal (bg, attr.Background);
diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs
index f5f8f3b76..ffbee081a 100644
--- a/UnitTests/Views/TableViewTests.cs
+++ b/UnitTests/Views/TableViewTests.cs
@@ -904,10 +904,10 @@ namespace Terminal.Gui.ViewsTests {
tv.Bounds = new Rect (0, 0, 5, 4);
var rowHighlight = new ColorScheme () {
- Normal = Attribute.Make (Color.BrightCyan, Color.DarkGray),
- HotNormal = Attribute.Make (Color.Green, Color.Blue),
- HotFocus = Attribute.Make (Color.BrightYellow, Color.White),
- Focus = Attribute.Make (Color.Cyan, Color.Magenta),
+ Normal = new Attribute (Color.BrightCyan, Color.DarkGray),
+ HotNormal = new Attribute (Color.Green, Color.Blue),
+ HotFocus = new Attribute (Color.BrightYellow, Color.White),
+ Focus = new Attribute (Color.Cyan, Color.Magenta),
};
// when B is 2 use the custom highlight colour for the row
@@ -995,10 +995,10 @@ namespace Terminal.Gui.ViewsTests {
// when B is 2 use the custom highlight colour
var cellHighlight = new ColorScheme () {
- Normal = Attribute.Make (Color.BrightCyan, Color.DarkGray),
- HotNormal = Attribute.Make (Color.Green, Color.Blue),
- HotFocus = Attribute.Make (Color.BrightYellow, Color.White),
- Focus = Attribute.Make (Color.Cyan, Color.Magenta),
+ Normal = new Attribute (Color.BrightCyan, Color.DarkGray),
+ HotNormal = new Attribute (Color.Green, Color.Blue),
+ HotFocus = new Attribute (Color.BrightYellow, Color.White),
+ Focus = new Attribute (Color.Cyan, Color.Magenta),
};
bStyle.ColorGetter = (a) => Convert.ToInt32 (a.CellValue) == 2 ? cellHighlight : null;