From d78960c02d140502a6d1caa6993a18f60ca73b7c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 20 Feb 2023 20:52:19 -0800 Subject: [PATCH] Color fixups. --- color.go | 6 +++--- color_test.go | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/color.go b/color.go index 8e50fa3..e6581b0 100644 --- a/color.go +++ b/color.go @@ -1002,14 +1002,14 @@ func (c Color) IsRGB() bool { } // Hex returns the color's hexadecimal RGB 24-bit value with each component -// consisting of a single byte, ala R << 16 | G << 8 | B. If the color +// consisting of a single byte, R << 16 | G << 8 | B. If the color // is unknown or unset, -1 is returned. func (c Color) Hex() int32 { if !c.Valid() { return -1 } if c&ColorIsRGB != 0 { - return int32(c) & 0xffffff + return int32(c & 0xffffff) } if v, ok := ColorValues[c]; ok { return v @@ -1036,7 +1036,7 @@ func (c Color) TrueColor() Color { return ColorDefault } if c&ColorIsRGB != 0 { - return c + return c | ColorValid } return Color(c.Hex()) | ColorIsRGB | ColorValid } diff --git a/color_test.go b/color_test.go index 91725b7..b41c92e 100644 --- a/color_test.go +++ b/color_test.go @@ -24,19 +24,24 @@ func TestColorValues(t *testing.T) { color Color hex int32 }{ - {ColorRed, 0x00FF0000}, - {ColorGreen, 0x00008000}, - {ColorLime, 0x0000FF00}, - {ColorBlue, 0x000000FF}, - {ColorBlack, 0x00000000}, - {ColorWhite, 0x00FFFFFF}, - {ColorSilver, 0x00C0C0C0}, + {ColorRed, 0xFF0000}, + {ColorGreen, 0x008000}, + {ColorLime, 0x00FF00}, + {ColorBlue, 0x0000FF}, + {ColorBlack, 0x000000}, + {ColorWhite, 0xFFFFFF}, + {ColorSilver, 0xC0C0C0}, + {ColorNavy, 0x000080}, } for _, tc := range values { if tc.color.Hex() != tc.hex { t.Errorf("Color: %x != %x", tc.color.Hex(), tc.hex) } + + if tc.color.TrueColor().Hex() != tc.hex { + t.Errorf("TrueColor %x != %x", tc.color.TrueColor().Hex(), tc.hex) + } } }