Forráskód Böngészése

inital commit - proving Color can be made a class without breaking tons of code

Tig Kindel 1 éve
szülő
commit
26580aca6a

+ 2 - 2
Terminal.Gui/Configuration/ColorJsonConverter.cs

@@ -31,9 +31,9 @@ namespace Terminal.Gui {
 				var colorString = reader.GetString ();
 
 				// Check if the color string is a color name
-				if (Enum.TryParse (colorString, ignoreCase: true, out Color color)) {
+				if (Enum.TryParse (colorString, ignoreCase: true, out ColorNames color)) {
 					// Return the parsed color
-					return color;
+					return new Color(color);
 				} else {
 					// Parse the color string as an RGB value
 					var match = Regex.Match (colorString, @"rgb\((\d+),(\d+),(\d+)\)");

+ 18 - 0
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -425,6 +425,16 @@ public abstract class ConsoleDriver {
 		return MakeColor (fore, back);
 	}
 
+	/// <summary>
+	/// Make the attribute for the foreground and background colors.
+	/// </summary>
+	/// <param name="fore">Foreground.</param>
+	/// <param name="back">Background.</param>
+	/// <returns></returns>
+	public virtual Attribute MakeAttribute (ColorNames fore, ColorNames back)
+	{
+		return MakeColor (fore, back);
+	}
 	/// <summary>
 	/// Gets the foreground and background colors based on a platform-dependent color value.
 	/// </summary>
@@ -439,6 +449,14 @@ public abstract class ConsoleDriver {
 	/// <returns>The current attribute.</returns>
 	public Attribute GetAttribute () => CurrentAttribute;
 
+	/// <summary>
+	/// Makes an <see cref="Attribute"/>.
+	/// </summary>
+	/// <param name="foreground">The foreground color.</param>
+	/// <param name="background">The background color.</param>
+	/// <returns>The attribute for the foreground and background colors.</returns>
+	public abstract Attribute MakeColor (ColorNames foreground, ColorNames background);
+
 	/// <summary>
 	/// Makes an <see cref="Attribute"/>.
 	/// </summary>

+ 33 - 21
Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

@@ -88,52 +88,64 @@ internal class CursesDriver : ConsoleDriver {
 	/// and the background color is stored in the least significant 4 bits.
 	/// The Terminal.GUi Color values are converted to curses color encoding before being encoded.
 	/// </remarks>
-	public override Attribute MakeColor (Color fore, Color back)
+	public override Attribute MakeColor (ColorNames fore, ColorNames back)
 	{
 		if (!RunningUnitTests) {
-			return MakeColor (ColorToCursesColorNumber (fore), ColorToCursesColorNumber (back));
+			return MakeColor (ColorNameToCursesColorNumber (fore), ColorNameToCursesColorNumber (back));
 		} else {
 			return new Attribute (
 				value: 0,
-				foreground: fore,
-				background: back);
+				foreground: ColorNameToCursesColorNumber (fore),
+				background: ColorNameToCursesColorNumber (back));
 		}
 	}
 
-	static short ColorToCursesColorNumber (Color color)
+	public override Attribute MakeColor (Color foreground, Color background)
+	{
+		if (!RunningUnitTests) {
+			return MakeColor (foreground, background);
+		} else {
+			return new Attribute (
+				value: 0,
+				foreground: foreground,
+				background: background);
+		}
+	}
+
+	static short ColorNameToCursesColorNumber (ColorNames color)
 	{
 		switch (color) {
-		case Color.Black:
+		case ColorNames.Black:
 			return Curses.COLOR_BLACK;
-		case Color.Blue:
+		case ColorNames.Blue:
 			return Curses.COLOR_BLUE;
-		case Color.Green:
+		case ColorNames.Green:
 			return Curses.COLOR_GREEN;
-		case Color.Cyan:
+		case ColorNames.Cyan:
 			return Curses.COLOR_CYAN;
-		case Color.Red:
+		case ColorNames.Red:
 			return Curses.COLOR_RED;
-		case Color.Magenta:
+		case ColorNames.Magenta:
 			return Curses.COLOR_MAGENTA;
-		case Color.Brown:
+		case ColorNames.Brown:
 			return Curses.COLOR_YELLOW;
-		case Color.Gray:
+		case ColorNames.Gray:
 			return Curses.COLOR_WHITE;
-		case Color.DarkGray:
+		case ColorNames.DarkGray:
 			return Curses.COLOR_GRAY;
-		case Color.BrightBlue:
+		case ColorNames.BrightBlue:
 			return Curses.COLOR_BLUE | Curses.COLOR_GRAY;
-		case Color.BrightGreen:
+		case ColorNames.BrightGreen:
 			return Curses.COLOR_GREEN | Curses.COLOR_GRAY;
-		case Color.BrightCyan:
+		case ColorNames.BrightCyan:
 			return Curses.COLOR_CYAN | Curses.COLOR_GRAY;
-		case Color.BrightRed:
+		case ColorNames.BrightRed:
 			return Curses.COLOR_RED | Curses.COLOR_GRAY;
-		case Color.BrightMagenta:
+		case ColorNames.BrightMagenta:
 			return Curses.COLOR_MAGENTA | Curses.COLOR_GRAY;
-		case Color.BrightYellow:
+		case ColorNames.BrightYellow:
 			return Curses.COLOR_YELLOW | Curses.COLOR_GRAY;
-		case Color.White:
+		case ColorNames.White:
 			return Curses.COLOR_WHITE | Curses.COLOR_GRAY;
 		}
 		throw new ArgumentException ("Invalid color code");

+ 8 - 4
Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs

@@ -69,7 +69,7 @@ public class FakeDriver : ConsoleDriver {
 		FakeConsole.ResetColor ();
 		FakeConsole.Clear ();
 	}
-	
+
 	public override void Init (Action terminalResized)
 	{
 		FakeConsole.MockKeyPresses.Clear ();
@@ -134,8 +134,8 @@ public class FakeDriver : ConsoleDriver {
 					// Performance: Only send the escape sequence if the attribute has changed.
 					if (attr != redrawAttr) {
 						redrawAttr = attr;
-						FakeConsole.ForegroundColor = (ConsoleColor)attr.Foreground;
-						FakeConsole.BackgroundColor = (ConsoleColor)attr.Background;
+						FakeConsole.ForegroundColor = (ConsoleColor)attr.Foreground.Value;
+						FakeConsole.BackgroundColor = (ConsoleColor)attr.Background.Value;
 					}
 					outputWidth++;
 					var rune = (Rune)Contents [row, col].Runes [0];
@@ -168,7 +168,7 @@ public class FakeDriver : ConsoleDriver {
 			foreach (var c in output.ToString ()) {
 				FakeConsole.Write (c);
 			}
-			
+
 			output.Clear ();
 			lastCol += outputWidth;
 			outputWidth = 0;
@@ -229,6 +229,10 @@ public class FakeDriver : ConsoleDriver {
 		);
 	}
 
+	public override Attribute MakeColor (ColorNames foreground, ColorNames background)
+	{
+		return MakeColor (new Color (foreground), new Color (background));
+	}
 	#endregion
 
 	public ConsoleKeyInfo FromVKPacketToKConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo)

+ 9 - 5
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -152,7 +152,7 @@ internal class NetEvents : IDisposable {
 			} finally {
 				_inputReady.Reset ();
 			}
-			
+
 #if PROCESS_REQUEST
 				_neededProcessRequest = false;
 #endif
@@ -184,7 +184,7 @@ internal class NetEvents : IDisposable {
 	void ProcessInputQueue ()
 	{
 		while (!_inputReadyCancellationTokenSource.Token.IsCancellationRequested) {
-	
+
 			_waitForStart.Wait (_inputReadyCancellationTokenSource.Token);
 			_waitForStart.Reset ();
 
@@ -793,7 +793,7 @@ internal class NetDriver : ConsoleDriver {
 
 						if (Force16Colors) {
 							output.Append (EscSeqUtils.CSI_SetGraphicsRendition (
-								MapColors ((ConsoleColor)attr.Background, false), MapColors ((ConsoleColor)attr.Foreground, true)));
+								MapColors ((ConsoleColor)attr.Background.Value, false), MapColors ((ConsoleColor)attr.Foreground.Value, true)));
 						} else {
 							output.Append (EscSeqUtils.CSI_SetForegroundColorRGB (attr.TrueColorForeground.Value.Red, attr.TrueColorForeground.Value.Green, attr.TrueColorForeground.Value.Blue));
 							output.Append (EscSeqUtils.CSI_SetBackgroundColorRGB (attr.TrueColorBackground.Value.Red, attr.TrueColorBackground.Value.Green, attr.TrueColorBackground.Value.Blue));
@@ -889,6 +889,10 @@ internal class NetDriver : ConsoleDriver {
 		);
 	}
 
+	public override Attribute MakeColor (ColorNames foreground, ColorNames background)
+	{
+		return MakeColor (new Color (foreground), new Color (background));
+	}
 	#endregion
 
 	#region Cursor Handling
@@ -1418,14 +1422,14 @@ internal class NetMainLoop : IMainLoopDriver {
 			ProcessInput?.Invoke (_resultQueue.Dequeue ().Value);
 		}
 	}
-	
+
 	void IMainLoopDriver.TearDown ()
 	{
 		_inputHandlerTokenSource?.Cancel ();
 		_inputHandlerTokenSource?.Dispose ();
 		_eventReadyTokenSource?.Cancel ();
 		_eventReadyTokenSource?.Dispose ();
-		
+
 		_eventReady?.Dispose ();
 
 		_resultQueue?.Clear ();

+ 4 - 0
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -1654,6 +1654,10 @@ internal class WindowsDriver : ConsoleDriver {
 		    background: background
 		);
 	}
+	public override Attribute MakeColor (ColorNames foreground, ColorNames background)
+	{
+		return MakeColor (new Color (foreground), new Color (background));
+	}
 
 	/// <summary>
 	/// Extracts the foreground and background colors from the encoded value.

+ 171 - 26
Terminal.Gui/Drawing/Color.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Immutable;
 using System.Diagnostics.CodeAnalysis;
@@ -15,7 +16,7 @@ namespace Terminal.Gui {
 	/// The <see cref="Attribute.HasValidColors"/> value indicates either no-color has been set or the color is invalid.
 	/// </remarks>
 	[JsonConverter (typeof (ColorJsonConverter))]
-	public enum Color {
+	public enum ColorNames {
 		/// <summary>
 		/// The black color.
 		/// </summary>
@@ -82,6 +83,109 @@ namespace Terminal.Gui {
 		White
 	}
 
+	public class Color {
+		public Color (ColorNames colorName)
+		{
+			var tc = TrueColor.FromColorName (colorName).GetValueOrDefault ();
+			Value = (tc.Alpha << 24) | (tc.Red << 16) | (tc.Green << 8) | tc.Blue;
+		}
+
+		public Color ()
+		{
+			Value = -1;
+		}
+
+		/// <summary>
+		/// The black color.
+		/// </summary>
+		public const int Black = (int)ColorNames.Black;
+
+		/// <summary>
+		/// The blue color.
+		/// </summary>
+		public const int Blue = (int)ColorNames.Blue;
+		/// <summary>
+		/// The green color.
+		/// </summary>
+		public const int Green = (int)ColorNames.Green;
+		/// <summary>
+		/// The cyan color.
+		/// </summary>
+		public const int Cyan = (int)ColorNames.Cyan;
+		/// <summary>
+		/// The red color.
+		/// </summary>
+		public const int Red = (int)ColorNames.Red;
+		/// <summary>
+		/// The magenta color.
+		/// </summary>
+		public const int Magenta = (int)ColorNames.Magenta;
+		/// <summary>
+		/// The brown color.
+		/// </summary>
+		public const int Brown = (int)ColorNames.Brown;
+		/// <summary>
+		/// The gray color.
+		/// </summary>
+		public const int Gray = (int)ColorNames.Gray;
+		/// <summary>
+		/// The dark gray color.
+		/// </summary>
+		public const int DarkGray = (int)ColorNames.DarkGray;
+		/// <summary>
+		/// The bright bBlue color.
+		/// </summary>
+		public const int BrightBlue = (int)ColorNames.BrightBlue;
+		/// <summary>
+		/// The bright green color.
+		/// </summary>
+		public const int BrightGreen = (int)ColorNames.BrightGreen;
+		/// <summary>
+		/// The bright cyan color.
+		/// </summary>
+		public const int BrightCyan = (int)ColorNames.BrightCyan;
+		/// <summary>
+		/// The bright red color.
+		/// </summary>
+		public const int BrightRed = (int)ColorNames.BrightRed;
+		/// <summary>
+		/// The bright magenta color.
+		/// </summary>
+		public const int BrightMagenta = (int)ColorNames.BrightMagenta;
+		/// <summary>
+		/// The bright yellow color.
+		/// </summary>
+		public const int BrightYellow = (int)ColorNames.BrightYellow;
+		/// <summary>
+		/// The White color.
+		/// </summary>
+		public const int White = (int)ColorNames.White;
+
+		/// <summary>
+		/// The truecolor value. -1 if not valid. 
+		/// </summary>
+		public int Value { get; set; }
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="value"></param>
+		public static implicit operator Color (int value)
+		{
+			return new Color { Value = value };
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="color"></param>
+		public static explicit operator int (Color color)
+		{
+			return color.Value;
+		}
+
+	}
+
 	/// <summary>
 	/// Indicates the RGB for true colors.
 	/// </summary>
@@ -119,6 +223,14 @@ namespace Terminal.Gui {
 		/// </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="TrueColor"/> struct.
 		/// </summary>
@@ -186,29 +298,38 @@ namespace Terminal.Gui {
 		/// </summary>
 		/// <param name="consoleColor">The <see cref="Color"/> to convert.</param>
 		/// <returns></returns>
-		public static TrueColor? FromConsoleColor (Color consoleColor)
+		public static TrueColor? FromColorName (ColorNames consoleColor)
 		{
 			return consoleColor switch {
-				Color.Black => new TrueColor (0, 0, 0),
-				Color.Blue => new TrueColor (0, 0, 0x80),
-				Color.Green => new TrueColor (0, 0x80, 0),
-				Color.Cyan => new TrueColor (0, 0x80, 0x80),
-				Color.Red => new TrueColor (0x80, 0, 0),
-				Color.Magenta => new TrueColor (0x80, 0, 0x80),
-				Color.Brown => new TrueColor (0xC1, 0x9C, 0x00) // TODO confirm this
+				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
 				,
-				Color.Gray => new TrueColor (0xC0, 0xC0, 0xC0),
-				Color.DarkGray => new TrueColor (0x80, 0x80, 0x80),
-				Color.BrightBlue => new TrueColor (0, 0, 0xFF),
-				Color.BrightGreen => new TrueColor (0, 0xFF, 0),
-				Color.BrightCyan => new TrueColor (0, 0xFF, 0xFF),
-				Color.BrightRed => new TrueColor (0xFF, 0, 0),
-				Color.BrightMagenta => new TrueColor (0xFF, 0, 0xFF),
-				Color.BrightYellow => new TrueColor (0xFF, 0xFF, 0),
-				Color.White => new TrueColor (0xFF, 0xFF, 0xFF),
+				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>
@@ -339,8 +460,8 @@ namespace Terminal.Gui {
 			Value = value;
 			Foreground = foreground;
 			Background = background;
-			TrueColorForeground = TrueColor.FromConsoleColor (foreground);
-			TrueColorBackground = TrueColor.FromConsoleColor (background);
+			//TrueColorForeground = TrueColor.FromColorName (foreground);
+			//TrueColorBackground = TrueColor.FromColorName (background);
 		}
 
 		/// <summary>
@@ -353,8 +474,8 @@ namespace Terminal.Gui {
 		{
 			Foreground = foreground;
 			Background = background;
-			TrueColorForeground = TrueColor.FromConsoleColor (foreground);
-			TrueColorBackground = TrueColor.FromConsoleColor (background);
+			//TrueColorForeground = TrueColor.FromColorName (foreground);
+			//TrueColorBackground = TrueColor.FromColorName (background);
 			Value = value;
 			Initialized = true;
 		}
@@ -364,12 +485,12 @@ namespace Terminal.Gui {
 		/// </summary>
 		/// <param name="foreground">Foreground</param>
 		/// <param name="background">Background</param>
-		public Attribute (Color foreground = new Color (), Color background = new Color ())
+		public Attribute (Color foreground, Color background)
 		{
 			Foreground = foreground;
 			Background = background;
-			TrueColorForeground = TrueColor.FromConsoleColor (foreground);
-			TrueColorBackground = TrueColor.FromConsoleColor (background);
+			//TrueColorForeground = TrueColor.FromColorName (foreground);
+			//TrueColorBackground = TrueColor.FromColorName (background);
 
 			var make = Make (foreground, background);
 			Initialized = make.Initialized;
@@ -490,6 +611,30 @@ namespace Terminal.Gui {
 			return Application.Driver.MakeAttribute (foreground, background);
 		}
 
+
+		/// <summary>
+		/// Creates an <see cref="Attribute"/> from the specified foreground and background colors.
+		/// </summary>
+		/// <remarks>
+		/// If a <see cref="ConsoleDriver"/> has not been loaded (<c>Application.Driver == null</c>) this
+		/// method will return an attribute with <see cref="Initialized"/> set to  <see langword="false"/>.
+		/// </remarks>
+		/// <returns>The new attribute.</returns>
+		/// <param name="foreground">Foreground color to use.</param>
+		/// <param name="background">Background color to use.</param>
+		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);
+		}
+
 		/// <summary>
 		/// Gets the current <see cref="Attribute"/> from the driver.
 		/// </summary>

+ 1 - 1
Terminal.Gui/Terminal.Gui.csproj

@@ -20,7 +20,7 @@
   </PropertyGroup>
   <PropertyGroup>
     <TargetFrameworks>net7.0</TargetFrameworks>
-    <LangVersion>10.0</LangVersion>
+    <LangVersion>11.0</LangVersion>
     <RootNamespace>Terminal.Gui</RootNamespace>
     <AssemblyName>Terminal.Gui</AssemblyName>
     <SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>

+ 6 - 6
Terminal.Gui/Views/ColorPicker.cs

@@ -80,7 +80,7 @@ namespace Terminal.Gui {
 
 			set {
 				var colorIndex = value.Y * _cols + value.X;
-				SelectedColor = (Color)colorIndex;
+				SelectedColor = (ColorNames)colorIndex;
 			}
 		}
 
@@ -92,17 +92,17 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// Selected color.
 		/// </summary>
-		public Color SelectedColor {
+		public ColorNames SelectedColor {
 			get {
-				return (Color)_selectColorIndex;
+				return (ColorNames)_selectColorIndex;
 			}
 
 			set {
-				Color prev = (Color)_selectColorIndex;
+				ColorNames prev = (ColorNames)_selectColorIndex;
 				_selectColorIndex = (int)value;
 				ColorChanged?.Invoke (this, new ColorEventArgs () {
-					PreviousColor = prev,
-					Color = value,
+					PreviousColor = new Color(prev),
+					Color = new Color(value),
 				});
 				SetNeedsDisplay ();
 			}

+ 2 - 2
Terminal.Gui/Views/FileDialog.cs

@@ -1198,8 +1198,8 @@ namespace Terminal.Gui {
 
 
 			var color = Style.ColorProvider.GetTrueColor (stats.FileSystemInfo)
-			?? TrueColor.FromConsoleColor (Color.White);
-			var black = TrueColor.FromConsoleColor (Color.Black);
+			?? TrueColor.FromColorName (Color.White);
+			var black = TrueColor.FromColorName (Color.Black);
 
 			// TODO: Add some kind of cache for this
 			return new ColorScheme {

+ 6 - 5
Terminal.Gui/Views/TextView.cs

@@ -2514,11 +2514,12 @@ namespace Terminal.Gui {
 
 		private static void SetValidUsedColor (ColorScheme colorScheme)
 		{
-			if ((colorScheme!.HotNormal.Foreground & colorScheme.Focus.Background) == colorScheme.Focus.Foreground) {
-				Driver.SetAttribute (new Attribute (colorScheme.Focus.Background, colorScheme.Focus.Foreground));
-			} else {
-				Driver.SetAttribute (new Attribute (colorScheme!.HotNormal.Foreground & colorScheme.Focus.Background, colorScheme.Focus.Foreground));
-			}
+			// BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now
+			//if ((colorScheme!.HotNormal.Foreground & colorScheme.Focus.Background) == colorScheme.Focus.Foreground) {
+			//	Driver.SetAttribute (new Attribute (colorScheme.Focus.Background, colorScheme.Focus.Foreground));
+			//} else {
+			//	Driver.SetAttribute (new Attribute (colorScheme!.HotNormal.Foreground & colorScheme.Focus.Background, colorScheme.Focus.Foreground));
+			//}
 		}
 
 		bool _isReadOnly = false;

+ 2 - 2
UICatalog/Scenarios/BasicColors.cs

@@ -10,9 +10,9 @@ namespace UICatalog.Scenarios {
 			var vx = 30;
 			var x = 30;
 			var y = 14;
-			var colors = System.Enum.GetValues (typeof (Color));
+			var colors = System.Enum.GetValues (typeof (ColorNames));
 
-			foreach (Color bg in colors) {
+			foreach (int bg in colors) {
 				Attribute attr = new Attribute (bg, colors.Length - 1 - bg);
 				var vl = new Label (bg.ToString (), TextDirection.TopBottom_LeftRight) {
 					X = vx,

+ 6 - 3
UICatalog/Scenarios/ColorPicker.cs

@@ -89,8 +89,9 @@ namespace UICatalog.Scenarios {
 			Win.Add (_demoView);
 
 			// Set default colors.
-			backgroundColorPicker.SelectedColor = _demoView.SuperView.ColorScheme.Normal.Background;
-			foregroundColorPicker.SelectedColor = _demoView.SuperView.ColorScheme.Normal.Foreground;
+			// BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now
+			//backgroundColorPicker.SelectedColor = _demoView.SuperView.ColorScheme.Normal.Background;
+			//foregroundColorPicker.SelectedColor = _demoView.SuperView.ColorScheme.Normal.Foreground;
 		}
 
 		/// <summary>
@@ -124,7 +125,9 @@ namespace UICatalog.Scenarios {
 		/// Update Demo Label.
 		/// </summary>
 		private void UpdateDemoLabel () => _demoView.ColorScheme = new ColorScheme () {
-			Normal = new Terminal.Gui.Attribute (foregroundColorPicker.SelectedColor, backgroundColorPicker.SelectedColor)
+			// BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now
+
+			//Normal = new Terminal.Gui.Attribute (foregroundColorPicker.SelectedColor, backgroundColorPicker.SelectedColor)
 		};
 	}
 }

+ 10 - 8
UICatalog/Scenarios/Frames.cs

@@ -116,9 +116,10 @@ namespace UICatalog.Scenarios {
 					BorderStyle = LineStyle.Single,
 					SuperViewRendersLineCanvas = true
 				};
-				_foregroundColorPicker.ColorChanged += (o, a) =>
-					AttributeChanged?.Invoke (this,
-						new Terminal.Gui.Attribute (_foregroundColorPicker.SelectedColor, _backgroundColorPicker.SelectedColor));
+				// BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now
+				//_foregroundColorPicker.ColorChanged += (o, a) =>
+				//	AttributeChanged?.Invoke (this,
+				//		new Terminal.Gui.Attribute (_foregroundColorPicker.SelectedColor, _backgroundColorPicker.SelectedColor));
 				Add (_foregroundColorPicker);
 
 				// Background ColorPicker.
@@ -132,11 +133,12 @@ namespace UICatalog.Scenarios {
 					SuperViewRendersLineCanvas = true
 				};
 
-				_backgroundColorPicker.ColorChanged += (o, a) =>
-					AttributeChanged?.Invoke (this,
-						new Terminal.Gui.Attribute (
-							_foregroundColorPicker.SelectedColor,
-							_backgroundColorPicker.SelectedColor));
+				// BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now
+				//_backgroundColorPicker.ColorChanged += (o, a) =>
+				//	AttributeChanged?.Invoke (this,
+				//		new Terminal.Gui.Attribute (
+				//			_foregroundColorPicker.SelectedColor,
+				//			_backgroundColorPicker.SelectedColor));
 				Add (_backgroundColorPicker);
 
 				_topEdit.Text = $"{Thickness.Top}";

+ 2 - 1
UICatalog/Scenarios/GraphViewExample.cs

@@ -96,7 +96,8 @@ namespace UICatalog.Scenarios {
 
 			about.Text = "Housing Expenditures by income thirds 1996-2003";
 
-			var fore = graphView.ColorScheme.Normal.Foreground == Color.Black ? Color.White : graphView.ColorScheme.Normal.Foreground;
+			// BUGBUG: (v2 truecolor) This code depends on 8-bit color names; refactor
+			var fore = graphView.ColorScheme.Normal.Foreground == new Color(ColorNames.Black) ? new Color(ColorNames.White) : graphView.ColorScheme.Normal.Foreground;
 			var black = Application.Driver.MakeAttribute (fore, Color.Black);
 			var cyan = Application.Driver.MakeAttribute (Color.BrightCyan, Color.Black);
 			var magenta = Application.Driver.MakeAttribute (Color.BrightMagenta, Color.Black);

+ 4 - 4
UnitTests/ConsoleDrivers/ColorTests.cs

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

+ 13 - 13
UnitTests/Views/ColorPickerTests.cs

@@ -11,7 +11,7 @@ namespace Terminal.Gui.ViewsTests {
 		public void Constructors ()
 		{
 			var colorPicker = new ColorPicker ();
-			Assert.Equal (Color.Black, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
 			Assert.Equal (new Point (0, 0), colorPicker.Cursor);
 			Assert.True (colorPicker.CanFocus);
 
@@ -26,25 +26,25 @@ namespace Terminal.Gui.ViewsTests {
 		public void KeyBindings_Command ()
 		{
 			var colorPicker = new ColorPicker ();
-			Assert.Equal (Color.Black, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
 
 			Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
-			Assert.Equal (Color.Blue, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Blue, colorPicker.SelectedColor);
 
 			Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
-			Assert.Equal (Color.BrightBlue, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.BrightBlue, colorPicker.SelectedColor);
 
 			Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
-			Assert.Equal (Color.DarkGray, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.DarkGray, colorPicker.SelectedColor);
 
 			Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
-			Assert.Equal (Color.Black, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
 
 			Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
-			Assert.Equal (Color.Black, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
 
 			Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
-			Assert.Equal (Color.Black, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
 		}
 
 		[Fact]
@@ -52,12 +52,12 @@ namespace Terminal.Gui.ViewsTests {
 		public void MouseEvents ()
 		{
 			var colorPicker = new ColorPicker ();
-			Assert.Equal (Color.Black, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
 
 			Assert.False (colorPicker.MouseEvent (new MouseEvent ()));
 
 			Assert.True (colorPicker.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked, X = 4, Y = 0 }));
-			Assert.Equal (Color.Blue, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Blue, colorPicker.SelectedColor);
 		}
 
 		[Fact]
@@ -65,7 +65,7 @@ namespace Terminal.Gui.ViewsTests {
 		public void SelectedColorAndCursor ()
 		{
 			var colorPicker = new ColorPicker ();
-			colorPicker.SelectedColor = Color.White;
+			colorPicker.SelectedColor = ColorNames.White;
 			Assert.Equal (7, colorPicker.Cursor.X);
 			Assert.Equal (1, colorPicker.Cursor.Y);
 
@@ -74,10 +74,10 @@ namespace Terminal.Gui.ViewsTests {
 			Assert.Equal (0, colorPicker.Cursor.Y);
 
 			colorPicker.Cursor = new Point (7, 1);
-			Assert.Equal (Color.White, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.White, colorPicker.SelectedColor);
 
 			colorPicker.Cursor = new Point (0, 0);
-			Assert.Equal (Color.Black, colorPicker.SelectedColor);
+			Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
 		}
 	}
 }