mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
ColorNames->ColorName
This commit is contained in:
@@ -54,7 +54,7 @@ namespace Terminal.Gui {
|
||||
public static bool UseSystemConsole { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether <see cref="Application.Driver"/> will be forced to output only the 16 colors defined in <see cref="ColorNames"/>.
|
||||
/// Gets or sets whether <see cref="Application.Driver"/> will be forced to output only the 16 colors defined in <see cref="ColorName"/>.
|
||||
/// The default is <see langword="false"/>, meaning 24-bit (TrueColor) colors will be output as long as the selected <see cref="ConsoleDriver"/>
|
||||
/// supports TrueColor.
|
||||
/// </summary>
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Terminal.Gui {
|
||||
var colorString = reader.GetString ();
|
||||
|
||||
// Check if the color string is a color name
|
||||
if (Enum.TryParse (colorString, ignoreCase: true, out ColorNames color)) {
|
||||
if (Enum.TryParse (colorString, ignoreCase: true, out ColorName color)) {
|
||||
// Return the parsed color
|
||||
return new Color(color);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ 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>
|
||||
private Attribute MakeColor (ColorNames foregroundName, ColorNames backgroundName)
|
||||
private Attribute MakeColor (ColorName foregroundName, ColorName backgroundName)
|
||||
{
|
||||
if (!RunningUnitTests) {
|
||||
return MakeColor (ColorNameToCursesColorNumber (foregroundName), ColorNameToCursesColorNumber (backgroundName));
|
||||
@@ -119,80 +119,80 @@ internal class CursesDriver : ConsoleDriver {
|
||||
}
|
||||
}
|
||||
|
||||
static short ColorNameToCursesColorNumber (ColorNames color)
|
||||
static short ColorNameToCursesColorNumber (ColorName color)
|
||||
{
|
||||
switch (color) {
|
||||
case ColorNames.Black:
|
||||
case ColorName.Black:
|
||||
return Curses.COLOR_BLACK;
|
||||
case ColorNames.Blue:
|
||||
case ColorName.Blue:
|
||||
return Curses.COLOR_BLUE;
|
||||
case ColorNames.Green:
|
||||
case ColorName.Green:
|
||||
return Curses.COLOR_GREEN;
|
||||
case ColorNames.Cyan:
|
||||
case ColorName.Cyan:
|
||||
return Curses.COLOR_CYAN;
|
||||
case ColorNames.Red:
|
||||
case ColorName.Red:
|
||||
return Curses.COLOR_RED;
|
||||
case ColorNames.Magenta:
|
||||
case ColorName.Magenta:
|
||||
return Curses.COLOR_MAGENTA;
|
||||
case ColorNames.Yellow:
|
||||
case ColorName.Yellow:
|
||||
return Curses.COLOR_YELLOW;
|
||||
case ColorNames.Gray:
|
||||
case ColorName.Gray:
|
||||
return Curses.COLOR_WHITE;
|
||||
case ColorNames.DarkGray:
|
||||
case ColorName.DarkGray:
|
||||
return Curses.COLOR_GRAY;
|
||||
case ColorNames.BrightBlue:
|
||||
case ColorName.BrightBlue:
|
||||
return Curses.COLOR_BLUE | Curses.COLOR_GRAY;
|
||||
case ColorNames.BrightGreen:
|
||||
case ColorName.BrightGreen:
|
||||
return Curses.COLOR_GREEN | Curses.COLOR_GRAY;
|
||||
case ColorNames.BrightCyan:
|
||||
case ColorName.BrightCyan:
|
||||
return Curses.COLOR_CYAN | Curses.COLOR_GRAY;
|
||||
case ColorNames.BrightRed:
|
||||
case ColorName.BrightRed:
|
||||
return Curses.COLOR_RED | Curses.COLOR_GRAY;
|
||||
case ColorNames.BrightMagenta:
|
||||
case ColorName.BrightMagenta:
|
||||
return Curses.COLOR_MAGENTA | Curses.COLOR_GRAY;
|
||||
case ColorNames.BrightYellow:
|
||||
case ColorName.BrightYellow:
|
||||
return Curses.COLOR_YELLOW | Curses.COLOR_GRAY;
|
||||
case ColorNames.White:
|
||||
case ColorName.White:
|
||||
return Curses.COLOR_WHITE | Curses.COLOR_GRAY;
|
||||
}
|
||||
throw new ArgumentException ("Invalid color code");
|
||||
}
|
||||
|
||||
static ColorNames CursesColorNumberToColorName (short color)
|
||||
static ColorName CursesColorNumberToColorName (short color)
|
||||
{
|
||||
switch (color) {
|
||||
case Curses.COLOR_BLACK:
|
||||
return ColorNames.Black;
|
||||
return ColorName.Black;
|
||||
case Curses.COLOR_BLUE:
|
||||
return ColorNames.Blue;
|
||||
return ColorName.Blue;
|
||||
case Curses.COLOR_GREEN:
|
||||
return ColorNames.Green;
|
||||
return ColorName.Green;
|
||||
case Curses.COLOR_CYAN:
|
||||
return ColorNames.Cyan;
|
||||
return ColorName.Cyan;
|
||||
case Curses.COLOR_RED:
|
||||
return ColorNames.Red;
|
||||
return ColorName.Red;
|
||||
case Curses.COLOR_MAGENTA:
|
||||
return ColorNames.Magenta;
|
||||
return ColorName.Magenta;
|
||||
case Curses.COLOR_YELLOW:
|
||||
return ColorNames.Yellow;
|
||||
return ColorName.Yellow;
|
||||
case Curses.COLOR_WHITE:
|
||||
return ColorNames.Gray;
|
||||
return ColorName.Gray;
|
||||
case Curses.COLOR_GRAY:
|
||||
return ColorNames.DarkGray;
|
||||
return ColorName.DarkGray;
|
||||
case Curses.COLOR_BLUE | Curses.COLOR_GRAY:
|
||||
return ColorNames.BrightBlue;
|
||||
return ColorName.BrightBlue;
|
||||
case Curses.COLOR_GREEN | Curses.COLOR_GRAY:
|
||||
return ColorNames.BrightGreen;
|
||||
return ColorName.BrightGreen;
|
||||
case Curses.COLOR_CYAN | Curses.COLOR_GRAY:
|
||||
return ColorNames.BrightCyan;
|
||||
return ColorName.BrightCyan;
|
||||
case Curses.COLOR_RED | Curses.COLOR_GRAY:
|
||||
return ColorNames.BrightRed;
|
||||
return ColorName.BrightRed;
|
||||
case Curses.COLOR_MAGENTA | Curses.COLOR_GRAY:
|
||||
return ColorNames.BrightMagenta;
|
||||
return ColorName.BrightMagenta;
|
||||
case Curses.COLOR_YELLOW | Curses.COLOR_GRAY:
|
||||
return ColorNames.BrightYellow;
|
||||
return ColorName.BrightYellow;
|
||||
case Curses.COLOR_WHITE | Curses.COLOR_GRAY:
|
||||
return ColorNames.White;
|
||||
return ColorName.White;
|
||||
}
|
||||
throw new ArgumentException ("Invalid curses color code");
|
||||
}
|
||||
@@ -675,7 +675,7 @@ internal class CursesDriver : ConsoleDriver {
|
||||
Curses.UseDefaultColors ();
|
||||
}
|
||||
|
||||
CurrentAttribute = MakeColor (ColorNames.White, ColorNames.Black);
|
||||
CurrentAttribute = MakeColor (ColorName.White, ColorName.Black);
|
||||
|
||||
TerminalResized = terminalResized;
|
||||
|
||||
|
||||
@@ -2,19 +2,12 @@
|
||||
// FakeDriver.cs: A fake ConsoleDriver for unit tests.
|
||||
//
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
using Unix.Terminal;
|
||||
using static Terminal.Gui.WindowsConsole;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Terminal.Gui;
|
||||
/// <summary>
|
||||
@@ -80,9 +73,7 @@ public class FakeDriver : ConsoleDriver {
|
||||
Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
|
||||
FakeConsole.Clear ();
|
||||
ResizeScreen ();
|
||||
// Call InitializeColorSchemes before UpdateOffScreen as it references Colors
|
||||
CurrentAttribute = new Attribute (Color.White, Color.Black);
|
||||
//InitializeColorSchemes ();
|
||||
ClearContents ();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -81,7 +81,7 @@ namespace Terminal.Gui {
|
||||
|
||||
set {
|
||||
var colorIndex = value.Y * _cols + value.X;
|
||||
SelectedColor = (ColorNames)colorIndex;
|
||||
SelectedColor = (ColorName)colorIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,13 +93,13 @@ namespace Terminal.Gui {
|
||||
/// <summary>
|
||||
/// Selected color.
|
||||
/// </summary>
|
||||
public ColorNames SelectedColor {
|
||||
public ColorName SelectedColor {
|
||||
get {
|
||||
return (ColorNames)_selectColorIndex;
|
||||
return (ColorName)_selectColorIndex;
|
||||
}
|
||||
|
||||
set {
|
||||
ColorNames prev = (ColorNames)_selectColorIndex;
|
||||
ColorName prev = (ColorName)_selectColorIndex;
|
||||
_selectColorIndex = (int)value;
|
||||
ColorChanged?.Invoke (this, new ColorEventArgs () {
|
||||
PreviousColor = new Color (prev),
|
||||
@@ -160,7 +160,7 @@ namespace Terminal.Gui {
|
||||
for (var y = 0; y < (Bounds.Height / BoxHeight); y++) {
|
||||
for (var x = 0; x < (Bounds.Width / BoxWidth); x++) {
|
||||
var foregroundColorIndex = y == 0 ? colorIndex + _cols : colorIndex - _cols;
|
||||
Driver.SetAttribute (new Attribute ((ColorNames)foregroundColorIndex, (ColorNames)colorIndex));
|
||||
Driver.SetAttribute (new Attribute ((ColorName)foregroundColorIndex, (ColorName)colorIndex));
|
||||
var selected = x == Cursor.X && y == Cursor.Y;
|
||||
DrawColorBox (x, y, selected);
|
||||
colorIndex++;
|
||||
|
||||
@@ -10,10 +10,10 @@ namespace UICatalog.Scenarios {
|
||||
var vx = 30;
|
||||
var x = 30;
|
||||
var y = 14;
|
||||
var colors = System.Enum.GetValues (typeof (ColorNames));
|
||||
var colors = System.Enum.GetValues (typeof (ColorName));
|
||||
|
||||
|
||||
foreach (ColorNames bg in colors) {
|
||||
foreach (ColorName bg in colors) {
|
||||
Attribute attr = new Attribute (bg, colors.Length - 1 - bg);
|
||||
var vl = new Label (bg.ToString (), TextDirection.TopBottom_LeftRight) {
|
||||
X = vx,
|
||||
@@ -34,7 +34,7 @@ namespace UICatalog.Scenarios {
|
||||
};
|
||||
Win.Add (hl);
|
||||
vx++;
|
||||
foreach (ColorNames fg in colors) {
|
||||
foreach (ColorName fg in colors) {
|
||||
var c = new Attribute (fg, bg);
|
||||
var t = x.ToString ();
|
||||
var l = new Label (x, y, t [t.Length - 1].ToString ()) {
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace UICatalog.Scenarios {
|
||||
|
||||
about.Text = "Housing Expenditures by income thirds 1996-2003";
|
||||
|
||||
var fore = graphView.ColorScheme.Normal.Foreground == new Color(ColorNames.Black) ? new Color(ColorNames.White) : graphView.ColorScheme.Normal.Foreground;
|
||||
var fore = graphView.ColorScheme.Normal.Foreground == new Color(ColorName.Black) ? new Color(ColorName.White) : graphView.ColorScheme.Normal.Foreground;
|
||||
var black = new Attribute (fore, Color.Black);
|
||||
var cyan = new Attribute (Color.BrightCyan, Color.Black);
|
||||
var magenta = new Attribute (Color.BrightMagenta, Color.Black);
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace UICatalog.Scenarios {
|
||||
Win.ColorScheme = Colors.TopLevel;
|
||||
|
||||
List<Label> labels = new List<Label> ();
|
||||
var foreColors = Enum.GetValues (typeof (ColorNames)).Cast<ColorNames> ().ToArray ();
|
||||
var foreColors = Enum.GetValues (typeof (ColorName)).Cast<ColorName> ().ToArray ();
|
||||
for (int y = 0; y < foreColors.Length; y++) {
|
||||
|
||||
var fore = foreColors [y];
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Terminal.Gui.ConfigurationTests {
|
||||
[InlineData ("Magenta", Color.Magenta)]
|
||||
[InlineData ("Red", Color.Red)]
|
||||
[InlineData ("White", Color.White)]
|
||||
public void TestColorDeserializationFromHumanReadableColorNames (string colorName, ColorNames expectedColor)
|
||||
public void TestColorDeserializationFromHumanReadableColorNames (string colorName, ColorName expectedColor)
|
||||
{
|
||||
// Arrange
|
||||
string json = $"\"{colorName}\"";
|
||||
@@ -34,23 +34,23 @@ namespace Terminal.Gui.ConfigurationTests {
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (ColorNames.Black, "Black")]
|
||||
[InlineData (ColorNames.Blue, "Blue")]
|
||||
[InlineData (ColorNames.Green, "Green")]
|
||||
[InlineData (ColorNames.Cyan, "Cyan")]
|
||||
[InlineData (ColorNames.Gray, "Gray")]
|
||||
[InlineData (ColorNames.Red, "Red")]
|
||||
[InlineData (ColorNames.Magenta, "Magenta")]
|
||||
[InlineData (ColorNames.Yellow, "Yellow")]
|
||||
[InlineData (ColorNames.DarkGray, "DarkGray")]
|
||||
[InlineData (ColorNames.BrightBlue, "BrightBlue")]
|
||||
[InlineData (ColorNames.BrightGreen, "BrightGreen")]
|
||||
[InlineData (ColorNames.BrightCyan, "BrightCyan")]
|
||||
[InlineData (ColorNames.BrightRed, "BrightRed")]
|
||||
[InlineData (ColorNames.BrightMagenta, "BrightMagenta")]
|
||||
[InlineData (ColorNames.BrightYellow, "BrightYellow")]
|
||||
[InlineData (ColorNames.White, "White")]
|
||||
public void SerializesEnumValuesAsStrings (ColorNames colorName, string expectedJson)
|
||||
[InlineData (ColorName.Black, "Black")]
|
||||
[InlineData (ColorName.Blue, "Blue")]
|
||||
[InlineData (ColorName.Green, "Green")]
|
||||
[InlineData (ColorName.Cyan, "Cyan")]
|
||||
[InlineData (ColorName.Gray, "Gray")]
|
||||
[InlineData (ColorName.Red, "Red")]
|
||||
[InlineData (ColorName.Magenta, "Magenta")]
|
||||
[InlineData (ColorName.Yellow, "Yellow")]
|
||||
[InlineData (ColorName.DarkGray, "DarkGray")]
|
||||
[InlineData (ColorName.BrightBlue, "BrightBlue")]
|
||||
[InlineData (ColorName.BrightGreen, "BrightGreen")]
|
||||
[InlineData (ColorName.BrightCyan, "BrightCyan")]
|
||||
[InlineData (ColorName.BrightRed, "BrightRed")]
|
||||
[InlineData (ColorName.BrightMagenta, "BrightMagenta")]
|
||||
[InlineData (ColorName.BrightYellow, "BrightYellow")]
|
||||
[InlineData (ColorName.White, "White")]
|
||||
public void SerializesEnumValuesAsStrings (ColorName colorName, string expectedJson)
|
||||
{
|
||||
var converter = new ColorJsonConverter ();
|
||||
var options = new JsonSerializerOptions { Converters = { converter } };
|
||||
@@ -95,7 +95,7 @@ namespace Terminal.Gui.ConfigurationTests {
|
||||
{
|
||||
// Arrange
|
||||
var json = "\"Black\"";
|
||||
var expectedColor = new Color (ColorNames.Black);
|
||||
var expectedColor = new Color (ColorName.Black);
|
||||
|
||||
// Act
|
||||
var color = JsonSerializer.Deserialize<Color> (json, new JsonSerializerOptions {
|
||||
@@ -111,7 +111,7 @@ namespace Terminal.Gui.ConfigurationTests {
|
||||
{
|
||||
// Arrange
|
||||
var json = "\"BrightRed\"";
|
||||
var expectedColor = new Color (ColorNames.BrightRed);
|
||||
var expectedColor = new Color (ColorName.BrightRed);
|
||||
|
||||
// Act
|
||||
var color = JsonSerializer.Deserialize<Color> (json, new JsonSerializerOptions {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class AttributeTests {
|
||||
public void ColorNamesConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var attribute = new Attribute (ColorNames.Blue);
|
||||
var attribute = new Attribute (ColorName.Blue);
|
||||
|
||||
// Assert
|
||||
Assert.Equal ((Color)Color.Blue, attribute.Foreground);
|
||||
@@ -65,7 +65,7 @@ public class AttributeTests {
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColorName = ColorNames.Black;
|
||||
var backgroundColorName = ColorName.Black;
|
||||
var attribute = new Attribute (foregroundColor, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
@@ -77,7 +77,7 @@ public class AttributeTests {
|
||||
public void ColorNamesAndColorConstructor ()
|
||||
{
|
||||
// Arrange & Act
|
||||
var foregroundColorName = ColorNames.BrightYellow;
|
||||
var foregroundColorName = ColorName.BrightYellow;
|
||||
var backgroundColor = new Color (128, 128, 128);
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColor);
|
||||
|
||||
@@ -149,8 +149,8 @@ public class AttributeTests {
|
||||
public void MakeColorNamesAndColorNames_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColorName = ColorNames.BrightYellow;
|
||||
var backgroundColorName = ColorNames.Black;
|
||||
var foregroundColorName = ColorName.BrightYellow;
|
||||
var backgroundColorName = ColorName.Black;
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColorName);
|
||||
@@ -164,7 +164,7 @@ public class AttributeTests {
|
||||
public void MakeColorNamesAndColor_ForegroundAndBackgroundShouldMatchInput ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColorName = ColorNames.Green;
|
||||
var foregroundColorName = ColorName.Green;
|
||||
var backgroundColor = new Color (128, 128, 128);
|
||||
|
||||
// Act
|
||||
@@ -180,7 +180,7 @@ public class AttributeTests {
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (255, 0, 0);
|
||||
var backgroundColorName = ColorNames.White;
|
||||
var backgroundColorName = ColorName.White;
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColorName);
|
||||
|
||||
@@ -26,11 +26,11 @@ public class ColorTests {
|
||||
[Fact]
|
||||
public void TestAllColors ()
|
||||
{
|
||||
var colorNames = Enum.GetValues (typeof (ColorNames)).Cast<int> ().Distinct ().ToList();
|
||||
var colorNames = Enum.GetValues (typeof (ColorName)).Cast<int> ().Distinct ().ToList();
|
||||
Attribute [] attrs = new Attribute [colorNames.Count];
|
||||
|
||||
int idx = 0;
|
||||
foreach (ColorNames bg in colorNames) {
|
||||
foreach (ColorName bg in colorNames) {
|
||||
attrs [idx] = new Attribute (bg, colorNames.Count - 1 - bg);
|
||||
idx++;
|
||||
}
|
||||
@@ -56,28 +56,28 @@ public class ColorTests {
|
||||
[Fact]
|
||||
public void ColorNames_HasOnly16DistinctElements ()
|
||||
{
|
||||
Assert.Equal (16, Enum.GetValues (typeof (ColorNames)).Cast<int> ().Distinct ().Count ());
|
||||
Assert.Equal (16, Enum.GetValues (typeof (ColorName)).Cast<int> ().Distinct ().Count ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorNames_HaveCorrectOrdinals ()
|
||||
{
|
||||
Assert.Equal (0, (int)ColorNames.Black);
|
||||
Assert.Equal (1, (int)ColorNames.Blue);
|
||||
Assert.Equal (2, (int)ColorNames.Green);
|
||||
Assert.Equal (3, (int)ColorNames.Cyan);
|
||||
Assert.Equal (4, (int)ColorNames.Red);
|
||||
Assert.Equal (5, (int)ColorNames.Magenta);
|
||||
Assert.Equal (6, (int)ColorNames.Yellow);
|
||||
Assert.Equal (7, (int)ColorNames.Gray);
|
||||
Assert.Equal (8, (int)ColorNames.DarkGray);
|
||||
Assert.Equal (9, (int)ColorNames.BrightBlue);
|
||||
Assert.Equal (10, (int)ColorNames.BrightGreen);
|
||||
Assert.Equal (11, (int)ColorNames.BrightCyan);
|
||||
Assert.Equal (12, (int)ColorNames.BrightRed);
|
||||
Assert.Equal (13, (int)ColorNames.BrightMagenta);
|
||||
Assert.Equal (14, (int)ColorNames.BrightYellow);
|
||||
Assert.Equal (15, (int)ColorNames.White);
|
||||
Assert.Equal (0, (int)ColorName.Black);
|
||||
Assert.Equal (1, (int)ColorName.Blue);
|
||||
Assert.Equal (2, (int)ColorName.Green);
|
||||
Assert.Equal (3, (int)ColorName.Cyan);
|
||||
Assert.Equal (4, (int)ColorName.Red);
|
||||
Assert.Equal (5, (int)ColorName.Magenta);
|
||||
Assert.Equal (6, (int)ColorName.Yellow);
|
||||
Assert.Equal (7, (int)ColorName.Gray);
|
||||
Assert.Equal (8, (int)ColorName.DarkGray);
|
||||
Assert.Equal (9, (int)ColorName.BrightBlue);
|
||||
Assert.Equal (10, (int)ColorName.BrightGreen);
|
||||
Assert.Equal (11, (int)ColorName.BrightCyan);
|
||||
Assert.Equal (12, (int)ColorName.BrightRed);
|
||||
Assert.Equal (13, (int)ColorName.BrightMagenta);
|
||||
Assert.Equal (14, (int)ColorName.BrightYellow);
|
||||
Assert.Equal (15, (int)ColorName.White);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -137,7 +137,7 @@ public class ColorTests {
|
||||
public void Color_Constructor_WithColorName ()
|
||||
{
|
||||
// Arrange
|
||||
ColorNames colorName = ColorNames.Blue;
|
||||
ColorName colorName = ColorName.Blue;
|
||||
var expectedColor = new Color (0, 55, 218); // Blue
|
||||
|
||||
// Act
|
||||
@@ -206,7 +206,7 @@ public class ColorTests {
|
||||
public void Color_ImplicitOperator_FromColorNames ()
|
||||
{
|
||||
// Arrange
|
||||
ColorNames colorName = ColorNames.Blue;
|
||||
ColorName colorName = ColorName.Blue;
|
||||
var expectedColor = new Color (0, 55, 218); // Blue
|
||||
|
||||
// Act
|
||||
@@ -221,10 +221,10 @@ public class ColorTests {
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (0, 0, 0x80); // Blue
|
||||
ColorNames expectedColorName = ColorNames.Blue;
|
||||
ColorName expectedColorName = ColorName.Blue;
|
||||
|
||||
// Act
|
||||
ColorNames colorName = (ColorNames)color;
|
||||
ColorName colorName = (ColorName)color;
|
||||
|
||||
// Assert
|
||||
Assert.Equal (expectedColorName, colorName);
|
||||
@@ -260,40 +260,40 @@ public class ColorTests {
|
||||
public void Color_EqualityOperator_WithColorNamesAndColor ()
|
||||
{
|
||||
// Arrange
|
||||
var color1 = new Color (ColorNames.Red);
|
||||
var color1 = new Color (ColorName.Red);
|
||||
var color2 = new Color (197, 15, 31); // Red in RGB
|
||||
|
||||
// Act & Assert
|
||||
Assert.True (ColorNames.Red == color1);
|
||||
Assert.False (ColorNames.Red != color1);
|
||||
Assert.True (ColorName.Red == color1);
|
||||
Assert.False (ColorName.Red != color1);
|
||||
|
||||
Assert.True (color1 == ColorNames.Red);
|
||||
Assert.False (color1 != ColorNames.Red);
|
||||
Assert.True (color1 == ColorName.Red);
|
||||
Assert.False (color1 != ColorName.Red);
|
||||
|
||||
Assert.True (color2 == ColorNames.Red);
|
||||
Assert.False (color2 != ColorNames.Red);
|
||||
Assert.True (color2 == ColorName.Red);
|
||||
Assert.False (color2 != ColorName.Red);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Color_InequalityOperator_WithColorNamesAndColor ()
|
||||
{
|
||||
// Arrange
|
||||
var color1 = new Color (ColorNames.Red);
|
||||
var color1 = new Color (ColorName.Red);
|
||||
var color2 = new Color (58, 150, 221); // Cyan in RGB
|
||||
|
||||
// Act & Assert
|
||||
Assert.False (ColorNames.Red == color2);
|
||||
Assert.True (ColorNames.Red != color2);
|
||||
Assert.False (ColorName.Red == color2);
|
||||
Assert.True (ColorName.Red != color2);
|
||||
|
||||
Assert.False (color2 == ColorNames.Red);
|
||||
Assert.True (color2 != ColorNames.Red);
|
||||
Assert.False (color2 == ColorName.Red);
|
||||
Assert.True (color2 != ColorName.Red);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Color_FromColorName_ConvertsColorNamesToColor ()
|
||||
{
|
||||
// Arrange
|
||||
var colorName = ColorNames.Red;
|
||||
var colorName = ColorName.Red;
|
||||
var expectedColor = new Color (197, 15, 31); // Red in RGB
|
||||
|
||||
// Act
|
||||
@@ -308,7 +308,7 @@ public class ColorTests {
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (128, 64, 40); // Custom RGB color, closest to Yellow
|
||||
var expectedColorName = ColorNames.Yellow;
|
||||
var expectedColorName = ColorName.Yellow;
|
||||
|
||||
// Act
|
||||
var colorName = color.ColorName;
|
||||
@@ -323,13 +323,13 @@ public class ColorTests {
|
||||
// Test cases with RGB values and expected closest color names
|
||||
var testCases = new []
|
||||
{
|
||||
(new Color(0, 0, 0), ColorNames.Black),
|
||||
(new Color(255, 255, 255), ColorNames.White),
|
||||
(new Color(5, 100, 255), ColorNames.BrightBlue),
|
||||
(new Color(0, 255, 0), ColorNames.BrightGreen),
|
||||
(new Color(255, 70, 8), ColorNames.BrightRed),
|
||||
(new Color(0, 128, 128), ColorNames.Cyan),
|
||||
(new Color(128, 64, 32), ColorNames.Yellow),
|
||||
(new Color(0, 0, 0), ColorName.Black),
|
||||
(new Color(255, 255, 255), ColorName.White),
|
||||
(new Color(5, 100, 255), ColorName.BrightBlue),
|
||||
(new Color(0, 255, 0), ColorName.BrightGreen),
|
||||
(new Color(255, 70, 8), ColorName.BrightRed),
|
||||
(new Color(0, 128, 128), ColorName.Cyan),
|
||||
(new Color(128, 64, 32), ColorName.Yellow),
|
||||
};
|
||||
|
||||
foreach (var testCase in testCases) {
|
||||
@@ -347,10 +347,10 @@ public class ColorTests {
|
||||
{
|
||||
// Arrange
|
||||
var color = new Color (0, 0, 0); // Black
|
||||
var expectedColor = new Color (ColorNames.Magenta);
|
||||
var expectedColor = new Color (ColorName.Magenta);
|
||||
|
||||
// Act
|
||||
color.ColorName = ColorNames.Magenta;
|
||||
color.ColorName = ColorName.Magenta;
|
||||
|
||||
// Assert
|
||||
Assert.Equal (expectedColor, color);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
public void Constructors ()
|
||||
{
|
||||
var colorPicker = new ColorPicker ();
|
||||
Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.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 (ColorNames.Black, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Black, colorPicker.SelectedColor);
|
||||
|
||||
Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
|
||||
Assert.Equal (ColorNames.Blue, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Blue, colorPicker.SelectedColor);
|
||||
|
||||
Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
|
||||
Assert.Equal (ColorNames.BrightBlue, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.BrightBlue, colorPicker.SelectedColor);
|
||||
|
||||
Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
|
||||
Assert.Equal (ColorNames.DarkGray, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.DarkGray, colorPicker.SelectedColor);
|
||||
|
||||
Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
|
||||
Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Black, colorPicker.SelectedColor);
|
||||
|
||||
Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
|
||||
Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Black, colorPicker.SelectedColor);
|
||||
|
||||
Assert.True (colorPicker.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
|
||||
Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Black, colorPicker.SelectedColor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -57,14 +57,14 @@ namespace Terminal.Gui.ViewsTests {
|
||||
Height = 4,
|
||||
Width = 32
|
||||
};
|
||||
Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Black, colorPicker.SelectedColor);
|
||||
Application.Top.Add (colorPicker);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.False (colorPicker.MouseEvent (new MouseEvent ()));
|
||||
|
||||
Assert.True (colorPicker.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked, X = 4, Y = 1 }));
|
||||
Assert.Equal (ColorNames.Blue, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Blue, colorPicker.SelectedColor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -72,7 +72,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
public void SelectedColorAndCursor ()
|
||||
{
|
||||
var colorPicker = new ColorPicker ();
|
||||
colorPicker.SelectedColor = ColorNames.White;
|
||||
colorPicker.SelectedColor = ColorName.White;
|
||||
Assert.Equal (7, colorPicker.Cursor.X);
|
||||
Assert.Equal (1, colorPicker.Cursor.Y);
|
||||
|
||||
@@ -81,10 +81,10 @@ namespace Terminal.Gui.ViewsTests {
|
||||
Assert.Equal (0, colorPicker.Cursor.Y);
|
||||
|
||||
colorPicker.Cursor = new Point (7, 1);
|
||||
Assert.Equal (ColorNames.White, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.White, colorPicker.SelectedColor);
|
||||
|
||||
colorPicker.Cursor = new Point (0, 0);
|
||||
Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
|
||||
Assert.Equal (ColorName.Black, colorPicker.SelectedColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user