diff --git a/Terminal.Gui/Drawing/Color/Color.cs b/Terminal.Gui/Drawing/Color/Color.cs index f220de1ab..995249c13 100644 --- a/Terminal.Gui/Drawing/Color/Color.cs +++ b/Terminal.Gui/Drawing/Color/Color.cs @@ -113,7 +113,7 @@ public readonly partial record struct Color : ISpanParsable, IUtf8SpanPar /// Initializes a new instance of the color from a value in the enum. /// The 16-color value. - public Color (in StandardColor colorName) : this ((int)colorName) { } + public Color (in StandardColor colorName) : this (StandardColors.GetArgb (colorName)) { } /// /// Initializes a new instance of the color from string. See diff --git a/Tests/UnitTestsParallelizable/Drawing/Color/ColorStandardColorTests.cs b/Tests/UnitTestsParallelizable/Drawing/Color/ColorStandardColorTests.cs new file mode 100644 index 000000000..eaf107010 --- /dev/null +++ b/Tests/UnitTestsParallelizable/Drawing/Color/ColorStandardColorTests.cs @@ -0,0 +1,27 @@ +using Xunit; + +namespace Terminal.Gui.DrawingTests; + +public class ColorStandardColorTests +{ + [Fact] + public void ToString_Returns_Standard_Name_For_StandardColor_CadetBlue() + { + // Without the fix, this uses Color(in StandardColor) -> this((int)colorName), + // which sets A=0x00 and prevents name resolution (expects A=0xFF). + var c = new Terminal.Gui.Drawing.Color(Terminal.Gui.Drawing.StandardColor.CadetBlue); + + // Expected: named color + Assert.Equal("CadetBlue", c.ToString()); + } + + [Fact] + public void ToString_G_Prints_Opaque_ARGB_For_StandardColor_CadetBlue() + { + // Without the fix, A=0x00, so "G" prints "#005F9EA0" instead of "#FF5F9EA0". + var c = new Terminal.Gui.Drawing.Color(Terminal.Gui.Drawing.StandardColor.CadetBlue); + + // Expected: #AARRGGBB with A=FF (opaque) + Assert.Equal("#FF5F9EA0", c.ToString("G", null)); + } +} \ No newline at end of file