mirror of https://github.com/gdamore/tcell.git
fixes #70 Background(), Foreground(), and Decompose() don't pass RGB
This commit is contained in:
parent
33f5ff39fa
commit
c46d32264a
|
@ -40,7 +40,10 @@ func makebox(s tcell.Screen) {
|
|||
lh := rand.Int() % (h - ly)
|
||||
st := tcell.StyleDefault
|
||||
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()))
|
||||
} else {
|
||||
st = st.Reverse(rand.Int()%2 == 0)
|
||||
|
|
14
style.go
14
style.go
|
@ -47,31 +47,31 @@ const (
|
|||
// as requested. ColorDefault can be used to select the global default.
|
||||
func (s Style) Foreground(c Color) Style {
|
||||
if c == ColorDefault {
|
||||
return (s &^ (0xffffff00000000 | styleFgSet))
|
||||
return (s &^ (0x1ffffff00000000 | styleFgSet))
|
||||
}
|
||||
return (s &^ Style(0xffffff00000000)) |
|
||||
((Style(c) & 0xffffff) << 32) | styleFgSet
|
||||
return (s &^ Style(0x1ffffff00000000)) |
|
||||
((Style(c) & 0x1ffffff) << 32) | styleFgSet
|
||||
}
|
||||
|
||||
// Background returns a new style based on s, with the background color set
|
||||
// as requested. ColorDefault can be used to select the global default.
|
||||
func (s Style) Background(c Color) Style {
|
||||
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,
|
||||
// and other attributes.
|
||||
func (s Style) Decompose() (fg Color, bg Color, attr AttrMask) {
|
||||
if s&styleFgSet != 0 {
|
||||
fg = Color(s>>32) & 0xffffff
|
||||
fg = Color(s>>32) & 0x1ffffff
|
||||
} else {
|
||||
fg = ColorDefault
|
||||
}
|
||||
if s&styleBgSet != 0 {
|
||||
bg = Color(s & 0xffffff)
|
||||
bg = Color(s & 0x1ffffff)
|
||||
} else {
|
||||
bg = ColorDefault
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue