mirror of
https://github.com/gdamore/tcell.git
synced 2025-04-24 13:48:51 +08:00
Color fixups.
This commit is contained in:
parent
5db823e7a8
commit
d78960c02d
6
color.go
6
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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user