fixes #70 Background(), Foreground(), and Decompose() don't pass RGB

This commit is contained in:
Garrett D'Amore 2015-11-03 12:52:42 -08:00
parent 33f5ff39fa
commit c46d32264a
2 changed files with 11 additions and 8 deletions

View File

@ -40,7 +40,10 @@ func makebox(s tcell.Screen) {
lh := rand.Int() % (h - ly) lh := rand.Int() % (h - ly)
st := tcell.StyleDefault st := tcell.StyleDefault
gl := ' ' gl := ' '
if s.Colors() > 1 { if s.Colors() > 256 {
rgb := tcell.NewHexColor(int32(rand.Int() & 0xffffff))
st = st.Background(rgb)
} else if s.Colors() > 1 {
st = st.Background(tcell.Color(rand.Int() % s.Colors())) st = st.Background(tcell.Color(rand.Int() % s.Colors()))
} else { } else {
st = st.Reverse(rand.Int()%2 == 0) st = st.Reverse(rand.Int()%2 == 0)

View File

@ -47,31 +47,31 @@ const (
// as requested. ColorDefault can be used to select the global default. // as requested. ColorDefault can be used to select the global default.
func (s Style) Foreground(c Color) Style { func (s Style) Foreground(c Color) Style {
if c == ColorDefault { if c == ColorDefault {
return (s &^ (0xffffff00000000 | styleFgSet)) return (s &^ (0x1ffffff00000000 | styleFgSet))
} }
return (s &^ Style(0xffffff00000000)) | return (s &^ Style(0x1ffffff00000000)) |
((Style(c) & 0xffffff) << 32) | styleFgSet ((Style(c) & 0x1ffffff) << 32) | styleFgSet
} }
// Background returns a new style based on s, with the background color set // Background returns a new style based on s, with the background color set
// as requested. ColorDefault can be used to select the global default. // as requested. ColorDefault can be used to select the global default.
func (s Style) Background(c Color) Style { func (s Style) Background(c Color) Style {
if c == ColorDefault { if c == ColorDefault {
return (s &^ (0xffffff | styleBgSet)) return (s &^ (0x1ffffff | styleBgSet))
} }
return (s &^ (0xffffff)) | (Style(c) & 0xffffff) | styleBgSet return (s &^ (0x1ffffff)) | (Style(c) & 0x1ffffff) | styleBgSet
} }
// Decompose breaks a style up, returning the foreground, background, // Decompose breaks a style up, returning the foreground, background,
// and other attributes. // and other attributes.
func (s Style) Decompose() (fg Color, bg Color, attr AttrMask) { func (s Style) Decompose() (fg Color, bg Color, attr AttrMask) {
if s&styleFgSet != 0 { if s&styleFgSet != 0 {
fg = Color(s>>32) & 0xffffff fg = Color(s>>32) & 0x1ffffff
} else { } else {
fg = ColorDefault fg = ColorDefault
} }
if s&styleBgSet != 0 { if s&styleBgSet != 0 {
bg = Color(s & 0xffffff) bg = Color(s & 0x1ffffff)
} else { } else {
bg = ColorDefault bg = ColorDefault
} }