Przeglądaj źródła

Removed GetColors (no longer needed)

Tigger Kindel 1 rok temu
rodzic
commit
c9ce86578c

+ 3 - 21
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -425,24 +425,6 @@ 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>
-	/// <param name="value">The platform-dependent color value.</param>
-	/// <param name="foreground">The foreground.</param>
-	/// <param name="background">The background.</param>
-	internal abstract void GetColors (int value, out ColorNames foreground, out ColorNames background);
-
 	/// <summary>
 	/// Gets the current <see cref="Attribute"/>.
 	/// </summary>
@@ -452,10 +434,10 @@ public abstract class ConsoleDriver {
 	/// <summary>
 	/// Makes an <see cref="Attribute"/>.
 	/// </summary>
-	/// <param name="foreground">The foreground color.</param>
-	/// <param name="background">The background color.</param>
+	/// <param name="foregroundName">The foreground color.</param>
+	/// <param name="backgroundName">The background color.</param>
 	/// <returns>The attribute for the foreground and background colors.</returns>
-	public abstract Attribute MakeColor (ColorNames foreground, ColorNames background);
+	public abstract Attribute MakeColor (ColorNames foregroundName, ColorNames backgroundName);
 
 	/// <summary>
 	/// Makes an <see cref="Attribute"/>.

+ 31 - 37
Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

@@ -78,8 +78,8 @@ internal class CursesDriver : ConsoleDriver {
 		Curses.InitColorPair (v, foreground, background);
 		return new Attribute (
 			platformColor: Curses.ColorPair (v),
-			foreground: CursesColorNumberToColor (foreground),
-			background: CursesColorNumberToColor (background));
+			foreground: CursesColorNumberToColorName (foreground),
+			background: CursesColorNumberToColorName (background));
 	}
 
 	/// <remarks>
@@ -88,18 +88,25 @@ 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 (ColorNames fore, ColorNames back)
+	public override Attribute MakeColor (ColorNames foregroundName, ColorNames backgroundName)
 	{
 		if (!RunningUnitTests) {
-			return MakeColor (ColorNameToCursesColorNumber (fore), ColorNameToCursesColorNumber (back));
+			return MakeColor (ColorNameToCursesColorNumber (foregroundName), ColorNameToCursesColorNumber (backgroundName));
 		} else {
 			return new Attribute (
 				platformColor: 0,
-				foreground: ColorNameToCursesColorNumber (fore),
-				background: ColorNameToCursesColorNumber (back));
+				foreground: ColorNameToCursesColorNumber (foregroundName),
+				background: ColorNameToCursesColorNumber (backgroundName));
 		}
 	}
 
+
+	/// <remarks>
+	/// In the CursesDriver, colors are encoded as an int. 
+	/// The foreground color is stored in the most significant 4 bits, 
+	/// 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 foreground, Color background)
 	{
 		if (!RunningUnitTests) {
@@ -151,58 +158,45 @@ internal class CursesDriver : ConsoleDriver {
 		throw new ArgumentException ("Invalid color code");
 	}
 
-	static ColorNames CursesColorNumberToColor (short color)
+	static ColorNames CursesColorNumberToColorName (short color)
 	{
 		switch (color) {
 		case Curses.COLOR_BLACK:
-			return Color.Black;
+			return ColorNames.Black;
 		case Curses.COLOR_BLUE:
-			return Color.Blue;
+			return ColorNames.Blue;
 		case Curses.COLOR_GREEN:
-			return Color.Green;
+			return ColorNames.Green;
 		case Curses.COLOR_CYAN:
-			return Color.Cyan;
+			return ColorNames.Cyan;
 		case Curses.COLOR_RED:
-			return Color.Red;
+			return ColorNames.Red;
 		case Curses.COLOR_MAGENTA:
-			return Color.Magenta;
+			return ColorNames.Magenta;
 		case Curses.COLOR_YELLOW:
-			return Color.Brown;
+			return ColorNames.Brown;
 		case Curses.COLOR_WHITE:
-			return Color.Gray;
+			return ColorNames.Gray;
 		case Curses.COLOR_GRAY:
-			return Color.DarkGray;
+			return ColorNames.DarkGray;
 		case Curses.COLOR_BLUE | Curses.COLOR_GRAY:
-			return Color.BrightBlue;
+			return ColorNames.BrightBlue;
 		case Curses.COLOR_GREEN | Curses.COLOR_GRAY:
-			return Color.BrightGreen;
+			return ColorNames.BrightGreen;
 		case Curses.COLOR_CYAN | Curses.COLOR_GRAY:
-			return Color.BrightCyan;
+			return ColorNames.BrightCyan;
 		case Curses.COLOR_RED | Curses.COLOR_GRAY:
-			return Color.BrightRed;
+			return ColorNames.BrightRed;
 		case Curses.COLOR_MAGENTA | Curses.COLOR_GRAY:
-			return Color.BrightMagenta;
+			return ColorNames.BrightMagenta;
 		case Curses.COLOR_YELLOW | Curses.COLOR_GRAY:
-			return Color.BrightYellow;
+			return ColorNames.BrightYellow;
 		case Curses.COLOR_WHITE | Curses.COLOR_GRAY:
-			return Color.White;
+			return ColorNames.White;
 		}
 		throw new ArgumentException ("Invalid curses color code");
 	}
 
-	/// <remarks>
-	/// In the CursesDriver, colors are encoded as an int. 
-	/// The foreground color is stored in the most significant 4 bits, 
-	/// 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>
-	internal override void GetColors (int value, out ColorNames foreground, out ColorNames background)
-	{
-		// Assume a 4-bit encoded value for both foreground and background colors.
-		foreground = CursesColorNumberToColor ((short)((value >> 4) & 0xF));
-		background = CursesColorNumberToColor ((short)(value & 0xF));
-	}
-
 	#endregion
 
 	public override void UpdateCursor ()
@@ -681,7 +675,7 @@ internal class CursesDriver : ConsoleDriver {
 			Curses.UseDefaultColors ();
 		}
 
-		CurrentAttribute = MakeColor (Color.White, Color.Black);
+		CurrentAttribute = MakeColor (ColorNames.White, ColorNames.Black);
 		InitializeColorSchemes ();
 
 		TerminalResized = terminalResized;

+ 0 - 12
Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs

@@ -187,18 +187,6 @@ public class FakeDriver : ConsoleDriver {
 
 	#region Color Handling
 
-	/// <remarks>
-	/// In the FakeDriver, colors are encoded as an int; same as NetDriver
-	/// Extracts the foreground and background colors from the encoded value.
-	/// Assumes a 4-bit encoded value for both foreground and background colors.
-	/// </remarks>
-	internal override void GetColors (int value, out ColorNames foreground, out ColorNames background)
-	{
-		// Assume a 4-bit encoded value for both foreground and background colors.
-		foreground = (ColorNames)((value >> 16) & 0xF);
-		background = (ColorNames)(value & 0xF);
-	}
-
 	/// <remarks>
 	/// In the FakeDriver, colors are encoded as an int; same as NetDriver
 	/// However, the foreground color is stored in the most significant 16 bits, 

+ 0 - 12
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -862,18 +862,6 @@ internal class NetDriver : ConsoleDriver {
 		return colorMap.TryGetValue (color, out var colorValue) ? colorValue + (isForeground ? 0 : 10) : 0;
 	}
 
-	/// <remarks>
-	/// In the NetDriver, colors are encoded as an int. 
-	/// Extracts the foreground and background colors from the encoded value.
-	/// Assumes a 4-bit encoded value for both foreground and background colors.
-	/// </remarks>
-	internal override void GetColors (int value, out ColorNames foreground, out ColorNames background)
-	{
-		// Assume a 4-bit encoded value for both foreground and background colors.
-		foreground = (ColorNames)((value >> 16) & 0xF);
-		background = (ColorNames)(value & 0xF);
-	}
-
 	/// <remarks>
 	/// In the NetDriver, colors are encoded as an int. 
 	/// However, the foreground color is stored in the most significant 16 bits, 

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

@@ -1659,17 +1659,6 @@ internal class WindowsDriver : ConsoleDriver {
 		return MakeColor (new Color (foreground), new Color (background));
 	}
 
-	/// <summary>
-	/// Extracts the foreground and background colors from the encoded value.
-	/// Assumes a 4-bit encoded value for both foreground and background colors.
-	/// </summary>
-	internal override void GetColors (int value, out ColorNames foreground, out ColorNames background)
-	{
-		// Assume a 4-bit encoded value for both foreground and background colors.
-		foreground = (ColorNames)((value >> 16) & 0xF);
-		background = (ColorNames)(value & 0xF);
-	}
-
 	#endregion
 
 	CursorVisibility _cachedCursorVisibility;

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

@@ -584,7 +584,7 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// The <see cref="ConsoleDriver"/>-specific color value. If <see cref="Initialized"/> is <see langword="false"/> 
 		/// 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.
+		/// and the attribute should be re-made before it is used.
 		/// </summary>
 		[JsonIgnore (Condition = JsonIgnoreCondition.Always)]
 		internal int Value { get; }

+ 0 - 31
UnitTests/Drawing/AttributeTests.cs

@@ -271,37 +271,6 @@ public class AttributeTests {
 		Assert.Equal (bg, attr.Background);
 	}
 
-	[Fact]
-	[AutoInitShutdown]
-	public void GetColors_Based_On_Value ()
-	{
-		var driver = Application.Driver;
-		var attrValue = new Attribute (Color.Red, Color.Green).Value;
-		driver.GetColors (attrValue, out ColorNames fg, out ColorNames bg);
-
-		Assert.Equal ((Color)Color.Red, (Color)fg);
-		Assert.Equal ((Color)Color.Green, (Color)bg);
-	}
-
-	[Fact]
-	public void IsValid_Tests ()
-	{
-		var attr = new Attribute ();
-		//Assert.True (attr.HasValidColors);
-
-		attr = new Attribute (Color.Red, Color.Green);
-		//Assert.True (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)(-1));
-		//Assert.False (attr.HasValidColors);
-	}
-
 	[Fact]
 	public void Equals_NotInitialized ()
 	{

+ 4 - 10
UnitTests/Views/GraphViewTests.cs

@@ -547,11 +547,8 @@ namespace Terminal.Gui.ViewsTests {
 		[Fact]
 		public void MultiBarSeriesColors_WrongNumber ()
 		{
-
-			var fake = new FakeDriver ();
-
 			var colors = new []{
-				fake.MakeAttribute(Color.Green,Color.Black)
+				new Attribute (Color.Green,Color.Black)
 			};
 
 			// user passes 1 color only but asks for 5 bars
@@ -565,13 +562,10 @@ namespace Terminal.Gui.ViewsTests {
 		[Fact]
 		public void MultiBarSeriesColors_RightNumber ()
 		{
-
-			var fake = new FakeDriver ();
-
 			var colors = new []{
-				fake.MakeAttribute(Color.Green,Color.Black),
-				fake.MakeAttribute(Color.Green,Color.White),
-				fake.MakeAttribute(Color.BrightYellow,Color.White)
+				new Attribute (Color.Green,Color.Black),
+				new Attribute (Color.Green,Color.White),
+				new Attribute (Color.BrightYellow,Color.White)
 			};
 
 			// user passes 3 colors and asks for 3 bars