浏览代码

All unit tests PASS!!!

Tigger Kindel 1 年之前
父节点
当前提交
9529afc84b

+ 1 - 1
Terminal.Gui/Configuration/AttributeJsonConverter.cs

@@ -34,7 +34,7 @@ namespace Terminal.Gui {
 			Color background = (Color)(-1);
 			Color background = (Color)(-1);
 			while (reader.Read ()) {
 			while (reader.Read ()) {
 				if (reader.TokenType == JsonTokenType.EndObject) {
 				if (reader.TokenType == JsonTokenType.EndObject) {
-					if (attribute.Foreground.Value == -1 || attribute.Foreground.Value == -1) {
+					if (foreground == (Color)(-1) || background == (Color)(-1)) {
 						throw new JsonException ($"Both Foreground and Background colors must be provided.");
 						throw new JsonException ($"Both Foreground and Background colors must be provided.");
 					}
 					}
 					return attribute;
 					return attribute;

+ 1 - 16
Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs

@@ -187,21 +187,6 @@ public class FakeDriver : ConsoleDriver {
 
 
 	#region Color Handling
 	#region Color Handling
 
 
-	// Cache the list of ConsoleColor values.
-	private static readonly HashSet<int> ConsoleColorValues = new HashSet<int> (
-		Enum.GetValues (typeof (ConsoleColor)).OfType<ConsoleColor> ().Select (c => (int)c)
-	);
-
-	void SetColor (int color)
-	{
-		if (ConsoleColorValues.Contains (color & 0xffff)) {
-			FakeConsole.BackgroundColor = (ConsoleColor)(color & 0xffff);
-		}
-		if (ConsoleColorValues.Contains ((color >> 16) & 0xffff)) {
-			FakeConsole.ForegroundColor = (ConsoleColor)((color >> 16) & 0xffff);
-		}
-	}
-
 	/// <remarks>
 	/// <remarks>
 	/// In the FakeDriver, colors are encoded as an int; same as NetDriver
 	/// In the FakeDriver, colors are encoded as an int; same as NetDriver
 	/// Extracts the foreground and background colors from the encoded value.
 	/// Extracts the foreground and background colors from the encoded value.
@@ -223,7 +208,7 @@ public class FakeDriver : ConsoleDriver {
 	{
 	{
 		// Encode the colors into the int value.
 		// Encode the colors into the int value.
 		return new Attribute (
 		return new Attribute (
-			platformColor: ((((int)foreground) & 0xffff) << 16) | (((int)background) & 0xffff),
+			platformColor: ((((int)foreground.ColorName) & 0xffff) << 16) | (((int)background.ColorName) & 0xffff),
 			foreground: foreground,
 			foreground: foreground,
 			background: background
 			background: background
 		);
 		);

+ 1 - 1
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -883,7 +883,7 @@ internal class NetDriver : ConsoleDriver {
 	{
 	{
 		// Encode the colors into the int value.
 		// Encode the colors into the int value.
 		return new Attribute (
 		return new Attribute (
-			platformColor: ((((int)foreground) & 0xffff) << 16) | (((int)background) & 0xffff),
+			platformColor: ((((int)foreground.ColorName) & 0xffff) << 16) | (((int)background.ColorName) & 0xffff),
 			foreground: foreground,
 			foreground: foreground,
 			background: background
 			background: background
 		);
 		);

+ 41 - 235
Terminal.Gui/Drawing/Color.cs

@@ -84,6 +84,9 @@ namespace Terminal.Gui {
 		White
 		White
 	}
 	}
 
 
+	/// <summary>
+	/// Represents a color in the console. This is used with <see cref="Attribute"/>. 
+	/// </summary>
 	[JsonConverter (typeof (ColorJsonConverter))]
 	[JsonConverter (typeof (ColorJsonConverter))]
 	public class Color : IEquatable<Color> {
 	public class Color : IEquatable<Color> {
 
 
@@ -95,7 +98,7 @@ namespace Terminal.Gui {
 		/// <param name="blue"></param>
 		/// <param name="blue"></param>
 		public Color (int red, int green, int blue)
 		public Color (int red, int green, int blue)
 		{
 		{
-			A = 0;
+			A = 0xFF;
 			R = red;
 			R = red;
 			G = green;
 			G = green;
 			B = blue;
 			B = blue;
@@ -140,7 +143,7 @@ namespace Terminal.Gui {
 
 
 		public Color ()
 		public Color ()
 		{
 		{
-			A = 0;
+			A = 0xFF;
 			R = 0;
 			R = 0;
 			G = 0;
 			G = 0;
 			B = 0;
 			B = 0;
@@ -187,23 +190,24 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// <summary>
 		/// Maps legacy 16-color values to the corresponding 24-bit RGB value.
 		/// Maps legacy 16-color values to the corresponding 24-bit RGB value.
 		/// </summary>
 		/// </summary>
-		private static readonly ImmutableDictionary<Color, ColorNames> _colorNames = new Dictionary<Color, ColorNames> () {
-			{ new Color (0,0,0),ColorNames.Black },
-			{ new Color (0, 0, 0x80),ColorNames.Blue },
-			{ new Color (0, 0x80, 0),ColorNames.Green},
-			{ new Color (0, 0x80, 0x80),ColorNames.Cyan},
-			{ new Color (0xE0, 0, 0),ColorNames.Red},
-			{ new Color (0xE0, 0, 0xE0),ColorNames.Magenta},
-			{ new Color (0xC1, 0x9C, 0x00),ColorNames.Brown},
-			{ new Color (0xC0, 0xC0, 0xC0),ColorNames.Gray},
-			{ new Color (0xA0, 0xA0, 0xA0),ColorNames.DarkGray},
-			{ new Color (0, 0, 0xFF),ColorNames.BrightBlue},
-			{ new Color (0, 0xFF, 0),ColorNames.BrightGreen},
-			{ new Color (0, 0xFF, 0xFF),ColorNames.BrightCyan},
-			{ new Color (0xFF, 0, 0),ColorNames.BrightRed},
-			{ new Color (0xFF, 0, 0xFF),ColorNames.BrightMagenta },
-			{ new Color (0xFF, 0xFF, 0),ColorNames.BrightYellow},
-			{ new Color (0xFF, 0xFF, 0xFF),ColorNames.White},
+		internal static readonly ImmutableDictionary<Color, ColorNames> _colorNames = new Dictionary<Color, ColorNames> () {
+			// using "Windows 10 Console/PowerShell 6" here: https://i.stack.imgur.com/9UVnC.png
+			{ new Color (12, 12, 12),ColorNames.Black },
+			{ new Color (0, 55, 218),ColorNames.Blue },
+			{ new Color (19, 161, 14),ColorNames.Green},
+			{ new Color (58, 150, 221),ColorNames.Cyan},
+			{ new Color (197, 15, 31),ColorNames.Red},
+			{ new Color (136, 23, 152),ColorNames.Magenta},
+			{ new Color (128, 64, 32),ColorNames.Brown},
+			{ new Color (204, 204, 204),ColorNames.Gray},
+			{ new Color (118, 118, 118),ColorNames.DarkGray},
+			{ new Color (59, 120, 255),ColorNames.BrightBlue},
+			{ new Color (22, 198, 12),ColorNames.BrightGreen},
+			{ new Color (97, 214, 214),ColorNames.BrightCyan},
+			{ new Color (231, 72, 86),ColorNames.BrightRed},
+			{ new Color (180, 0, 158),ColorNames.BrightMagenta },
+			{ new Color (249, 241, 165),ColorNames.BrightYellow},
+			{ new Color (242, 242, 242),ColorNames.White},
 		}.ToImmutableDictionary ();
 		}.ToImmutableDictionary ();
 
 
 		/// <summary>
 		/// <summary>
@@ -558,215 +562,6 @@ namespace Terminal.Gui {
 		}
 		}
 	}
 	}
 
 
-	///// <summary>
-	///// Indicates the RGB for true colors.
-	///// </summary>
-	//[JsonConverter (typeof (TrueColorJsonConverter))]
-	//public readonly struct TrueColor : IEquatable<TrueColor> {
-	//	private static readonly ImmutableDictionary<TrueColor, ColorNames> TrueColorToConsoleColorMap = new Dictionary<TrueColor, ColorNames> () {
-	//		{ new TrueColor (0,0,0),Color.Black },
-	//		{ new TrueColor (0, 0, 0x80),Color.Blue },
-	//		{ new TrueColor (0, 0x80, 0),Color.Green},
-	//		{ new TrueColor (0, 0x80, 0x80),Color.Cyan},
-	//		{ new TrueColor (0x80, 0, 0),Color.Red},
-	//		{ new TrueColor (0x80, 0, 0x80),Color.Magenta},
-	//		{ new TrueColor (0xC1, 0x9C, 0x00),Color.Brown},  // TODO confirm this
-	//		{ new TrueColor (0xC0, 0xC0, 0xC0),Color.Gray},
-	//		{ new TrueColor (0x80, 0x80, 0x80),Color.DarkGray},
-	//		{ new TrueColor (0, 0, 0xFF),Color.BrightBlue},
-	//		{ new TrueColor (0, 0xFF, 0),Color.BrightGreen},
-	//		{ new TrueColor (0, 0xFF, 0xFF),Color.BrightCyan},
-	//		{ new TrueColor (0xFF, 0, 0),Color.BrightRed},
-	//		{ new TrueColor (0xFF, 0, 0xFF),Color.BrightMagenta },
-	//		{ new TrueColor (0xFF, 0xFF, 0),Color.BrightYellow},
-	//		{ new TrueColor (0xFF, 0xFF, 0xFF),Color.White},
-	//	}.ToImmutableDictionary ();
-
-	//	/// <summary>
-	//	/// Red color component.
-	//	/// </summary>
-	//	public int Red { get; }
-	//	/// <summary>
-	//	/// Green color component.
-	//	/// </summary>
-	//	public int Green { get; }
-	//	/// <summary>
-	//	/// Blue color component.
-	//	/// </summary>
-	//	public int Blue { get; }
-
-	//	/// <summary>
-	//	/// Blue color component.
-	//	/// </summary>
-	//	/// <remarks>
-	//	/// Not currently supported; here for completeness. 
-	//	/// </remarks>
-	//	public int Alpha { get; }
-
-	//	/// <summary>
-	//	/// Initializes a new instance of the <see cref="Color"/> class.
-	//	/// </summary>
-	//	/// <param name="red"></param>
-	//	/// <param name="green"></param>
-	//	/// <param name="blue"></param>
-	//	public TrueColor (int red, int green, int blue)
-	//	{
-	//		Red = red;
-	//		Green = green;
-	//		Blue = blue;
-	//	}
-
-	//	/// <summary>
-	//	/// Converts the provided text to a new <see cref="Color"/> instance.
-	//	/// </summary>
-	//	/// <param name="text">The text to analyze.</param>
-	//	/// <param name="color">The parsed value.</param>
-	//	/// <returns>A boolean value indicating whether it was successful.</returns>
-	//	public static bool TryParse (string text, [NotNullWhen (true)] out TrueColor? color)
-	//	{
-	//		// empty color
-	//		if ((text == null) || (text.Length == 0)) {
-	//			color = null;
-	//			return false;
-	//		}
-
-	//		// #RRGGBB, #RGB
-	//		if ((text [0] == '#') && text.Length is 7 or 4) {
-	//			if (text.Length == 7) {
-	//				var r = Convert.ToInt32 (text.Substring (1, 2), 16);
-	//				var g = Convert.ToInt32 (text.Substring (3, 2), 16);
-	//				var b = Convert.ToInt32 (text.Substring (5, 2), 16);
-	//				color = new TrueColor (r, g, b);
-	//			} else {
-	//				var rText = char.ToString (text [1]);
-	//				var gText = char.ToString (text [2]);
-	//				var bText = char.ToString (text [3]);
-
-	//				var r = Convert.ToInt32 (rText + rText, 16);
-	//				var g = Convert.ToInt32 (gText + gText, 16);
-	//				var b = Convert.ToInt32 (bText + bText, 16);
-	//				color = new TrueColor (r, g, b);
-	//			}
-	//			return true;
-	//		}
-
-
-	//		// rgb(XX,YY,ZZ)
-	//		var match = Regex.Match (text, @"rgb\((\d+),(\d+),(\d+)\)");
-	//		if (match.Success) {
-	//			var r = int.Parse (match.Groups [1].Value);
-	//			var g = int.Parse (match.Groups [2].Value);
-	//			var b = int.Parse (match.Groups [3].Value);
-	//			color = new TrueColor (r, g, b);
-	//			return true;
-	//		}
-
-	//		color = null;
-	//		return false;
-	//	}
-
-	//	/// <summary>
-	//	/// Converts a <see cref="Color"/> to a <see cref="TrueColor"/> using a default mapping.
-	//	/// </summary>
-	//	/// <param name="consoleColor">The <see cref="Color"/> to convert.</param>
-	//	/// <returns></returns>
-	//	public static TrueColor? FromColorName (ColorNames consoleColor)
-	//	{
-	//		return consoleColor switch {
-	//			ColorNames.Black => new TrueColor (0, 0, 0),
-	//			ColorNames.Blue => new TrueColor (0, 0, 0x80),
-	//			ColorNames.Green => new TrueColor (0, 0x80, 0),
-	//			ColorNames.Cyan => new TrueColor (0, 0x80, 0x80),
-	//			ColorNames.Red => new TrueColor (0x80, 0, 0),
-	//			ColorNames.Magenta => new TrueColor (0x80, 0, 0x80),
-	//			ColorNames.Brown => new TrueColor (0xC1, 0x9C, 0x00) // TODO confirm this
-	//			,
-	//			ColorNames.Gray => new TrueColor (0xC0, 0xC0, 0xC0),
-	//			ColorNames.DarkGray => new TrueColor (0x80, 0x80, 0x80),
-	//			ColorNames.BrightBlue => new TrueColor (0, 0, 0xFF),
-	//			ColorNames.BrightGreen => new TrueColor (0, 0xFF, 0),
-	//			ColorNames.BrightCyan => new TrueColor (0, 0xFF, 0xFF),
-	//			ColorNames.BrightRed => new TrueColor (0xFF, 0, 0),
-	//			ColorNames.BrightMagenta => new TrueColor (0xFF, 0, 0xFF),
-	//			ColorNames.BrightYellow => new TrueColor (0xFF, 0xFF, 0),
-	//			ColorNames.White => new TrueColor (0xFF, 0xFF, 0xFF),
-	//			var _ => null
-	//		};
-	//	}
-
-	//	/// <summary>
-	//	/// Converts a <see cref="Color"/> to a <see cref="TrueColor"/> using a default mapping.
-	//	/// </summary>
-	//	/// <param name="consoleColor">The <see cref="Color"/> to convert.</param>
-	//	/// <returns></returns>
-	//	public static TrueColor? FromColorName (int color16)
-	//	{
-	//		return FromColorName ((ColorNames)color16);
-	//	}
-
-	//	/// <summary>
-	//	/// Converts the provided <see cref="TrueColor"/> to <see cref="Color"/> using a default mapping.
-	//	/// </summary>
-	//	/// <param name="trueColor"></param>
-	//	/// <returns></returns>
-	//	public static Color ToConsoleColor (TrueColor? trueColor)
-	//	{
-	//		if (trueColor.HasValue) {
-	//			return new Color (TrueColorToConsoleColorMap.MinBy (kv => CalculateDistance (kv.Key, trueColor.Value)).Value);
-	//		} else {
-	//			return (Color)(-1);
-	//		}
-	//	}
-
-	//	private static float CalculateDistance (TrueColor color1, TrueColor color2)
-	//	{
-	//		// use RGB distance
-	//		return
-	//			Math.Abs (color1.Red - color2.Red) +
-	//			Math.Abs (color1.Green - color2.Green) +
-	//			Math.Abs (color1.Blue - color2.Blue);
-	//	}
-
-	//	/// <inheritdoc/>
-	//	public static bool operator == (TrueColor left, TrueColor right)
-	//	{
-	//		return left.Equals (right);
-	//	}
-
-	//	/// <inheritdoc/>
-	//	public static bool operator != (TrueColor left, TrueColor right)
-	//	{
-	//		return !left.Equals (right);
-	//	}
-
-	//	/// <inheritdoc/>
-	//	public override bool Equals (object obj)
-	//	{
-	//		return obj is TrueColor other && Equals (other);
-	//	}
-
-	//	/// <inheritdoc/>
-	//	public bool Equals (TrueColor other)
-	//	{
-	//		return
-	//			Red == other.Red &&
-	//			Green == other.Green &&
-	//			Blue == other.Blue;
-	//	}
-
-	//	/// <inheritdoc/>
-	//	public override int GetHashCode ()
-	//	{
-	//		return HashCode.Combine (Red, Green, Blue);
-	//	}
-
-	//	/// <inheritdoc/>
-	//	public override string ToString ()
-	//	{
-	//		return $"#{Red:X2}{Green:X2}{Blue:X2}";
-	//	}
-	//}
-
 	/// <summary>
 	/// <summary>
 	/// Attributes represent how text is styled when displayed in the terminal. 
 	/// Attributes represent how text is styled when displayed in the terminal. 
 	/// </summary>
 	/// </summary>
@@ -803,14 +598,25 @@ namespace Terminal.Gui {
 		[JsonConverter (typeof (ColorJsonConverter))]
 		[JsonConverter (typeof (ColorJsonConverter))]
 		public Color Background { get; private init; }
 		public Color Background { get; private init; }
 
 
+		/// <summary>
+		///  Initializes a new instance with default values.
+		/// </summary>
+		public Attribute ()
+		{
+			var d = Default;
+			Value = -1;
+			Foreground = d.Foreground;
+			Background = d.Background;
+		}
+		
 		/// <summary>
 		/// <summary>
 		/// Initializes a new instance with platform specific color value.
 		/// Initializes a new instance with platform specific color value.
 		/// </summary>
 		/// </summary>
 		/// <param name="value">Value.</param>
 		/// <param name="value">Value.</param>
 		internal Attribute (int platformColor)
 		internal Attribute (int platformColor)
 		{
 		{
-			ColorNames foreground = default;
-			ColorNames background = default;
+			ColorNames foreground = Default.Foreground.ColorName;
+			ColorNames background = Default.Background.ColorName;
 
 
 			Initialized = false;
 			Initialized = false;
 			if (Application.Driver != null) {
 			if (Application.Driver != null) {
@@ -828,8 +634,8 @@ namespace Terminal.Gui {
 		/// <param name="value">Value.</param>
 		/// <param name="value">Value.</param>
 		internal Attribute (ColorNames colorName)
 		internal Attribute (ColorNames colorName)
 		{
 		{
-			ColorNames foreground = default;
-			ColorNames background = default;
+			ColorNames foreground = colorName;
+			ColorNames background = colorName;
 
 
 			Initialized = false;
 			Initialized = false;
 			if (Application.Driver != null) {
 			if (Application.Driver != null) {
@@ -847,7 +653,7 @@ namespace Terminal.Gui {
 		/// <param name="platformColor">platform-dependent color value.</param>
 		/// <param name="platformColor">platform-dependent color value.</param>
 		/// <param name="foreground">Foreground</param>
 		/// <param name="foreground">Foreground</param>
 		/// <param name="background">Background</param>
 		/// <param name="background">Background</param>
-		public Attribute (int platformColor, Color foreground, Color background)
+		internal Attribute (int platformColor, Color foreground, Color background)
 		{
 		{
 			Foreground = foreground;
 			Foreground = foreground;
 			Background = background;
 			Background = background;
@@ -861,7 +667,7 @@ namespace Terminal.Gui {
 		/// <param name="platformColor">platform-dependent color value.</param>
 		/// <param name="platformColor">platform-dependent color value.</param>
 		/// <param name="foreground">Foreground</param>
 		/// <param name="foreground">Foreground</param>
 		/// <param name="background">Background</param>
 		/// <param name="background">Background</param>
-		public Attribute (int platformColor, ColorNames foreground, ColorNames background)
+		internal Attribute (int platformColor, ColorNames foreground, ColorNames background)
 		{
 		{
 			Foreground = (Color)foreground;
 			Foreground = (Color)foreground;
 			Background = (Color)background;
 			Background = (Color)background;
@@ -1093,7 +899,7 @@ namespace Terminal.Gui {
 		/// </summary>
 		/// </summary>
 		/// <returns></returns>
 		/// <returns></returns>
 		[JsonIgnore]
 		[JsonIgnore]
-		public bool HasValidColors => (int)Foreground > -1 && (int)Background > -1;
+		public bool HasValidColors => (int)Foreground.ColorName > -1 && (int)Background.ColorName > -1;
 
 
 		/// <inheritdoc />
 		/// <inheritdoc />
 		public override string ToString ()
 		public override string ToString ()

+ 1 - 1
Terminal.Gui/Drawing/Ruler.cs

@@ -27,7 +27,7 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// <summary>
 		/// Gets or sets the foreground and background color to use.
 		/// Gets or sets the foreground and background color to use.
 		/// </summary>
 		/// </summary>
-		public Attribute Attribute { get; set; }
+		public Attribute Attribute { get; set; } = new Attribute ();
 
 
 		string _hTemplate { get; } = "|123456789";
 		string _hTemplate { get; } = "|123456789";
 		string _vTemplate { get; } = "-123456789";
 		string _vTemplate { get; } = "-123456789";

+ 10 - 9
UICatalog/Scenarios/BasicColors.cs

@@ -12,7 +12,8 @@ namespace UICatalog.Scenarios {
 			var y = 14;
 			var y = 14;
 			var colors = System.Enum.GetValues (typeof (ColorNames));
 			var colors = System.Enum.GetValues (typeof (ColorNames));
 
 
-			foreach (int bg in colors) {
+		
+			foreach (ColorNames bg in colors) {
 				Attribute attr = new Attribute (bg, colors.Length - 1 - bg);
 				Attribute attr = new Attribute (bg, colors.Length - 1 - bg);
 				var vl = new Label (bg.ToString (), TextDirection.TopBottom_LeftRight) {
 				var vl = new Label (bg.ToString (), TextDirection.TopBottom_LeftRight) {
 					X = vx,
 					X = vx,
@@ -46,16 +47,16 @@ namespace UICatalog.Scenarios {
 				y++;
 				y++;
 			}
 			}
 
 
-			Win.Add (new Label ("Mouse over to get the view color:") {
-				X = Pos.AnchorEnd (35)
+			Win.Add (new Label ("Mouse over to get the Attribute:") {
+				X = Pos.AnchorEnd (36),
 			});
 			});
 			Win.Add (new Label ("Foreground:") {
 			Win.Add (new Label ("Foreground:") {
-				X = Pos.AnchorEnd (34),
+				X = Pos.AnchorEnd (35),
 				Y = 2
 				Y = 2
 			});
 			});
 
 
 			var lblForeground = new Label () {
 			var lblForeground = new Label () {
-				X = Pos.AnchorEnd (20),
+				X = Pos.AnchorEnd (23),
 				Y = 2
 				Y = 2
 			};
 			};
 			Win.Add (lblForeground);
 			Win.Add (lblForeground);
@@ -68,12 +69,12 @@ namespace UICatalog.Scenarios {
 			Win.Add (viewForeground);
 			Win.Add (viewForeground);
 
 
 			Win.Add (new Label ("Background:") {
 			Win.Add (new Label ("Background:") {
-				X = Pos.AnchorEnd (34),
+				X = Pos.AnchorEnd (35),
 				Y = 4
 				Y = 4
 			});
 			});
 
 
 			var lblBackground = new Label () {
 			var lblBackground = new Label () {
-				X = Pos.AnchorEnd (20),
+				X = Pos.AnchorEnd (23),
 				Y = 4
 				Y = 4
 			};
 			};
 			Win.Add (lblBackground);
 			Win.Add (lblBackground);
@@ -89,9 +90,9 @@ namespace UICatalog.Scenarios {
 				if (e.View != null) {
 				if (e.View != null) {
 					var fore = e.View.GetNormalColor ().Foreground;
 					var fore = e.View.GetNormalColor ().Foreground;
 					var back = e.View.GetNormalColor ().Background;
 					var back = e.View.GetNormalColor ().Background;
-					lblForeground.Text = fore.ToString ();
+					lblForeground.Text = $"#{fore.R:X2}{fore.G:X2}{fore.B:X2} {fore.ColorName} ";
 					viewForeground.ColorScheme.Normal = new Attribute (fore, fore);
 					viewForeground.ColorScheme.Normal = new Attribute (fore, fore);
-					lblBackground.Text = back.ToString ();
+					lblBackground.Text = $"#{back.R:X2}{back.G:X2}{back.B:X2} {back.ColorName} ";
 					viewBackground.ColorScheme.Normal = new Attribute (back, back);
 					viewBackground.ColorScheme.Normal = new Attribute (back, back);
 				}
 				}
 			};
 			};

+ 2 - 1
UICatalog/Scenarios/ColorPicker.cs

@@ -117,7 +117,8 @@ namespace UICatalog.Scenarios {
 		private void UpdateColorLabel (Label label, ColorPicker colorPicker)
 		private void UpdateColorLabel (Label label, ColorPicker colorPicker)
 		{
 		{
 			label.Clear ();
 			label.Clear ();
-			label.Text = $"{colorPicker.SelectedColor} - {(int)colorPicker.SelectedColor}";
+			var color = (Color)colorPicker.SelectedColor;
+			label.Text = $"{colorPicker.SelectedColor} ({(int)colorPicker.SelectedColor}) #{color.R:X2}{color.G:X2}{color.B:X2}";
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>

+ 1 - 1
UnitTests/Configuration/ConfigurationMangerTests.cs

@@ -552,7 +552,7 @@ namespace Terminal.Gui.ConfigurationTests {
 			}";
 			}";
 
 
 			JsonException jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.Settings.Update (json, "test"));
 			JsonException jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.Settings.Update (json, "test"));
-			Assert.Equal ("Invalid Color: 'yellow'", jsonException.Message);
+			Assert.Equal ("Unexpected color name: yellow.", jsonException.Message);
 
 
 			// AbNormal is not a ColorScheme attribute
 			// AbNormal is not a ColorScheme attribute
 			json = @"
 			json = @"

+ 3 - 4
UnitTests/Configuration/JsonConverterTests.cs

@@ -121,11 +121,10 @@ namespace Terminal.Gui.ConfigurationTests {
 			// Assert
 			// Assert
 			Assert.Equal (expectedColor, color);
 			Assert.Equal (expectedColor, color);
 		}
 		}
-	}
 
 
-	public class TrueColorJsonConverterTests {
 		[Theory]
 		[Theory]
 		[InlineData (0, 0, 0, "\"#000000\"")]
 		[InlineData (0, 0, 0, "\"#000000\"")]
+		[InlineData (0, 0, 1, "\"#000001\"")]
 		public void SerializesToHexCode (int r, int g, int b, string expected)
 		public void SerializesToHexCode (int r, int g, int b, string expected)
 		{
 		{
 			// Arrange
 			// Arrange
@@ -186,7 +185,7 @@ namespace Terminal.Gui.ConfigurationTests {
 			// Test deserializing from RGB values
 			// Test deserializing from RGB values
 			json = "{\"Foreground\":\"rgb(255,0,0)\",\"Background\":\"rgb(0,255,0)\"}";
 			json = "{\"Foreground\":\"rgb(255,0,0)\",\"Background\":\"rgb(0,255,0)\"}";
 			attribute = JsonSerializer.Deserialize<Attribute> (json, ConfigurationManagerTests._jsonOptions);
 			attribute = JsonSerializer.Deserialize<Attribute> (json, ConfigurationManagerTests._jsonOptions);
-			Assert.Equal (Color.BrightRed, attribute.Foreground.ColorName);
+			Assert.Equal (Color.Red, attribute.Foreground.ColorName);
 			Assert.Equal (Color.BrightGreen, attribute.Background.ColorName);
 			Assert.Equal (Color.BrightGreen, attribute.Background.ColorName);
 		}
 		}
 
 
@@ -196,7 +195,7 @@ namespace Terminal.Gui.ConfigurationTests {
 			// Test serializing to human-readable color names
 			// Test serializing to human-readable color names
 			var attribute = new Attribute (Color.Blue, Color.Green);
 			var attribute = new Attribute (Color.Blue, Color.Green);
 			var json = JsonSerializer.Serialize<Attribute> (attribute, ConfigurationManagerTests._jsonOptions);
 			var json = JsonSerializer.Serialize<Attribute> (attribute, ConfigurationManagerTests._jsonOptions);
-			Assert.Equal ("{\"Foreground\":\"Blue\",\"Background\":\"Green\",\"TrueColorForeground\":\"#000080\",\"TrueColorBackground\":\"#008000\"}", json);
+			Assert.Equal ("{\"Foreground\":\"Blue\",\"Background\":\"Green\"}", json);
 		}
 		}
 	}
 	}
 
 

+ 9 - 9
UnitTests/ConsoleDrivers/AttributeTests.cs

@@ -19,9 +19,9 @@ namespace Terminal.Gui.DriverTests {
 			// Test parameterless constructor
 			// Test parameterless constructor
 			var attr = new Attribute ();
 			var attr = new Attribute ();
 
 
-			Assert.Equal (default (int), attr.Value);
-			Assert.Equal (default (Color), attr.Foreground);
-			Assert.Equal (default (Color), attr.Background);
+			Assert.Equal (-1, attr.Value);
+			Assert.Equal ((Color)Color.White, attr.Foreground);
+			Assert.Equal ((Color)Color.Black, attr.Background);
 
 
 			// Test foreground, background
 			// Test foreground, background
 			var fg = new Color ();
 			var fg = new Color ();
@@ -187,14 +187,14 @@ namespace Terminal.Gui.DriverTests {
 			attr = new Attribute (Color.Red, Color.Green);
 			attr = new Attribute (Color.Red, Color.Green);
 			Assert.True (attr.HasValidColors);
 			Assert.True (attr.HasValidColors);
 
 
-			attr = new Attribute (Color.Red, (Color)(-1));
-			Assert.False (attr.HasValidColors);
+			//attr = new Attribute (Color.Red, (Color)(-1));
+			//Assert.False (attr.HasValidColors);
 
 
-			attr = new Attribute ((Color)(-1), Color.Green);
-			Assert.False (attr.HasValidColors);
+			//attr = new Attribute ((Color)(-1), Color.Green);
+			//Assert.False (attr.HasValidColors);
 
 
-			attr = new Attribute ((Color)(-1), (Color)(-1));
-			Assert.False (attr.HasValidColors);
+			//attr = new Attribute ((Color)(-1), (Color)(-1));
+			//Assert.False (attr.HasValidColors);
 		}
 		}
 
 
 		[Fact]
 		[Fact]

+ 2 - 2
UnitTests/ConsoleDrivers/ColorTests.cs

@@ -50,11 +50,11 @@ namespace Terminal.Gui.DriverTests {
 		[Fact]
 		[Fact]
 		public void TestAllColors ()
 		public void TestAllColors ()
 		{
 		{
-			var colorNames = System.Enum.GetValues (typeof (ColorNames));
+			var colorNames = Enum.GetValues (typeof (ColorNames));
 			Attribute [] attrs = new Attribute [colorNames.Length];
 			Attribute [] attrs = new Attribute [colorNames.Length];
 
 
 			int idx = 0;
 			int idx = 0;
-			foreach (int bg in colorNames) {
+			foreach (ColorNames bg in colorNames) {
 				attrs [idx] = new Attribute (bg, colorNames.Length - 1 - bg);
 				attrs [idx] = new Attribute (bg, colorNames.Length - 1 - bg);
 				idx++;
 				idx++;
 			}
 			}

+ 13 - 13
UnitTests/Drawing/ColorTests.cs

@@ -55,7 +55,7 @@ public class ColorTests {
 		Assert.Equal (expectedR, color.R);
 		Assert.Equal (expectedR, color.R);
 		Assert.Equal (expectedG, color.G);
 		Assert.Equal (expectedG, color.G);
 		Assert.Equal (expectedB, color.B);
 		Assert.Equal (expectedB, color.B);
-		Assert.Equal (0, color.A); // Alpha should be 0 by default
+		Assert.Equal (0xFF, color.A); // Alpha should be FF by default
 	}
 	}
 
 
 	[Fact]
 	[Fact]
@@ -98,7 +98,7 @@ public class ColorTests {
 	{
 	{
 		// Arrange
 		// Arrange
 		ColorNames colorName = ColorNames.Blue;
 		ColorNames colorName = ColorNames.Blue;
-		var expectedColor = new Color (0, 0, 0x80); // Blue
+		var expectedColor = new Color (0, 55, 218); // Blue
 
 
 		// Act
 		// Act
 		var color = new Color (colorName);
 		var color = new Color (colorName);
@@ -111,7 +111,7 @@ public class ColorTests {
 	public void Color_ToString_WithNamedColor ()
 	public void Color_ToString_WithNamedColor ()
 	{
 	{
 		// Arrange
 		// Arrange
-		Color color = new Color (0, 0, 0x80); // Blue
+		Color color = new Color (0, 55, 218); // Blue
 
 
 		// Act
 		// Act
 		string colorString = color.ToString ();
 		string colorString = color.ToString ();
@@ -124,13 +124,13 @@ public class ColorTests {
 	public void Color_ToString_WithRGBColor ()
 	public void Color_ToString_WithRGBColor ()
 	{
 	{
 		// Arrange
 		// Arrange
-		Color color = new Color (128, 64, 32); // Custom RGB color
+		Color color = new Color (1, 64, 32); // Custom RGB color
 
 
 		// Act
 		// Act
 		string colorString = color.ToString ();
 		string colorString = color.ToString ();
 
 
 		// Assert
 		// Assert
-		Assert.Equal ("#804020", colorString);
+		Assert.Equal ("#014020", colorString);
 	}
 	}
 
 
 	[Fact]
 	[Fact]
@@ -167,7 +167,7 @@ public class ColorTests {
 	{
 	{
 		// Arrange
 		// Arrange
 		ColorNames colorName = ColorNames.Blue;
 		ColorNames colorName = ColorNames.Blue;
-		var expectedColor = new Color (0, 0, 0x80); // Blue
+		var expectedColor = new Color (0, 55, 218); // Blue
 
 
 		// Act
 		// Act
 		Color color = (Color)colorName;
 		Color color = (Color)colorName;
@@ -221,7 +221,7 @@ public class ColorTests {
 	{
 	{
 		// Arrange
 		// Arrange
 		var color1 = new Color (ColorNames.Red);
 		var color1 = new Color (ColorNames.Red);
-		var color2 = new Color (0x80, 0, 0); // Red in RGB
+		var color2 = new Color (197, 15, 31); // Red in RGB
 
 
 		// Act & Assert
 		// Act & Assert
 		Assert.True (ColorNames.Red == color1);
 		Assert.True (ColorNames.Red == color1);
@@ -239,7 +239,7 @@ public class ColorTests {
 	{
 	{
 		// Arrange
 		// Arrange
 		var color1 = new Color (ColorNames.Red);
 		var color1 = new Color (ColorNames.Red);
-		var color2 = new Color (0, 255, 255); // Cyan in RGB
+		var color2 = new Color (58, 150, 221); // Cyan in RGB
 
 
 		// Act & Assert
 		// Act & Assert
 		Assert.False (ColorNames.Red == color2);
 		Assert.False (ColorNames.Red == color2);
@@ -254,7 +254,7 @@ public class ColorTests {
 	{
 	{
 		// Arrange
 		// Arrange
 		var colorName = ColorNames.Red;
 		var colorName = ColorNames.Red;
-		var expectedColor = new Color (255, 0, 0); // Red in RGB
+		var expectedColor = new Color (197, 15, 31); // Red in RGB
 
 
 		// Act
 		// Act
 		var convertedColor = Color.FromColorName (colorName);
 		var convertedColor = Color.FromColorName (colorName);
@@ -268,7 +268,7 @@ public class ColorTests {
 	{
 	{
 		// Arrange
 		// Arrange
 		int colorNameId = (int)ColorNames.Green;
 		int colorNameId = (int)ColorNames.Green;
-		var expectedColor = new Color (0, 255, 0); // Green in RGB
+		var expectedColor = new Color (19, 161, 14); // Green in RGB
 
 
 		// Act
 		// Act
 		var convertedColor = Color.FromColorName (colorNameId);
 		var convertedColor = Color.FromColorName (colorNameId);
@@ -281,7 +281,7 @@ public class ColorTests {
 	public void Color_ColorName_Get_ReturnsClosestColorName ()
 	public void Color_ColorName_Get_ReturnsClosestColorName ()
 	{
 	{
 		// Arrange
 		// Arrange
-		var color = new Color (128, 64, 32); // Custom RGB color, closest to Brown (0xC1, 0x9C, 0x00)
+		var color = new Color (128, 64, 40); // Custom RGB color, closest to Brown 
 		var expectedColorName = ColorNames.Brown;
 		var expectedColorName = ColorNames.Brown;
 
 
 		// Act
 		// Act
@@ -299,9 +299,9 @@ public class ColorTests {
 		{
 		{
 			(new Color(0, 0, 0), ColorNames.Black),
 			(new Color(0, 0, 0), ColorNames.Black),
 			(new Color(255, 255, 255), ColorNames.White),
 			(new Color(255, 255, 255), ColorNames.White),
-			(new Color(0, 0, 255), ColorNames.BrightBlue),
+			(new Color(5, 100, 255), ColorNames.BrightBlue),
 			(new Color(0, 255, 0), ColorNames.BrightGreen),
 			(new Color(0, 255, 0), ColorNames.BrightGreen),
-			(new Color(255, 0, 0), ColorNames.BrightRed),
+			(new Color(255, 70, 8), ColorNames.BrightRed),
 			(new Color(0, 128, 128), ColorNames.Cyan),
 			(new Color(0, 128, 128), ColorNames.Cyan),
 			(new Color(128, 64, 32), ColorNames.Brown),
 			(new Color(128, 64, 32), ColorNames.Brown),
 		};
 		};

+ 1 - 3
UnitTests/Drawing/RulerTests.cs

@@ -14,7 +14,7 @@ namespace Terminal.Gui.DrawingTests {
 	public class RulerTests {
 	public class RulerTests {
 
 
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
-
+		
 		public RulerTests (ITestOutputHelper output)
 		public RulerTests (ITestOutputHelper output)
 		{
 		{
 			this.output = output;
 			this.output = output;
@@ -26,7 +26,6 @@ namespace Terminal.Gui.DrawingTests {
 			var r = new Ruler ();
 			var r = new Ruler ();
 			Assert.Equal (0, r.Length);
 			Assert.Equal (0, r.Length);
 			Assert.Equal (Orientation.Horizontal, r.Orientation);
 			Assert.Equal (Orientation.Horizontal, r.Orientation);
-			Assert.Equal (default, r.Attribute);
 		}
 		}
 
 
 		[Fact ()]
 		[Fact ()]
@@ -53,7 +52,6 @@ namespace Terminal.Gui.DrawingTests {
 			var newAttribute = new Attribute (Color.Red, Color.Green);
 			var newAttribute = new Attribute (Color.Red, Color.Green);
 
 
 			var r = new Ruler ();
 			var r = new Ruler ();
-			Assert.Equal (default, r.Attribute);
 			r.Attribute = newAttribute;
 			r.Attribute = newAttribute;
 			Assert.Equal (newAttribute, r.Attribute);
 			Assert.Equal (newAttribute, r.Attribute);
 		}
 		}