What's wrong
The Foreground/Background getters in TUI/Models/TextStyle.cs return Color.Name. The XML docs on TryParseHexColor say the bare hex forms exist "so a value read from one can be assigned back", and TextStyleColorTests tests that round trip.
For an unnamed color, System.Drawing.Color.Name is Convert.ToString(argb, 16), which drops leading zeros:
- Alpha 0x01-0x0F gives a 7-digit name, e.g.
a123456. TryParseHexColor accepts only 6 or 8 digits, so assigning it back throws ArgumentException.
- Alpha 0x00 with non-zero red gives a 6-digit name, e.g.
123456, which parses as RRGGBB and is forced to alpha 0xFF. The copy silently differs and TextStyle equality fails.
- Shorter values, e.g.
Color.FromArgb(0) → "0", also throw.
Failure scenario
var src = new TextStyle { ForegroundColor = Color.FromArgb(0x0A, 0x12, 0x34, 0x56) };
var copy = new TextStyle { Foreground = src.Foreground }; // throws
This is the documented pattern (style with { Foreground = other.Foreground }). It throws ArgumentException: 'a123456' is not a recognized color name or hex value. (Parameter 'Foreground'). With alpha 0x00, the copy's ARGB is FF123456 while the original is 00123456.
How verified
A scratch console app referencing TUI/TUI.csproj:
a=FF name=ff123456 orig=FF123456 copy=FF123456
a=80 name=80123456 orig=80123456 copy=80123456
a=10 name=10123456 orig=10123456 copy=10123456
a=0A name=a123456 THROWS ArgumentException: 'a123456' is not a recognized color name or hex value. (Parameter 'Foreground')
a=00 name=123456 orig=00123456 copy=FF123456
Suggested fix / acceptance criteria
- For unnamed colors, return a fixed-width string from the getters, e.g.
$"#{c.ToArgb():X8}", instead of Color.Name. Known colors keep their names.
- Extend the existing round-trip test with rows for alpha
0x00, 0x01, 0x0F and Color.FromArgb(0); every row gives back the same ARGB with no exception.
What's wrong
The
Foreground/Backgroundgetters inTUI/Models/TextStyle.csreturnColor.Name. The XML docs onTryParseHexColorsay the bare hex forms exist "so a value read from one can be assigned back", andTextStyleColorTeststests that round trip.For an unnamed color,
System.Drawing.Color.NameisConvert.ToString(argb, 16), which drops leading zeros:a123456.TryParseHexColoraccepts only 6 or 8 digits, so assigning it back throwsArgumentException.123456, which parses asRRGGBBand is forced to alpha0xFF. The copy silently differs andTextStyleequality fails.Color.FromArgb(0)→"0", also throw.Failure scenario
This is the documented pattern (
style with { Foreground = other.Foreground }). It throwsArgumentException: 'a123456' is not a recognized color name or hex value. (Parameter 'Foreground'). With alpha0x00, the copy's ARGB isFF123456while the original is00123456.How verified
A scratch console app referencing
TUI/TUI.csproj:Suggested fix / acceptance criteria
$"#{c.ToArgb():X8}", instead ofColor.Name. Known colors keep their names.0x00,0x01,0x0FandColor.FromArgb(0); every row gives back the same ARGB with no exception.