forked from marcusolsson/tui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.go
68 lines (58 loc) · 1.3 KB
/
theme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package tui
// Color represents a color.
type Color int
// Common colors.
const (
ColorDefault Color = iota
ColorBlack
ColorWhite
ColorRed
ColorGreen
ColorBlue
ColorCyan
ColorMagenta
ColorYellow
)
// Style determines how a cell should be painted.
type Style struct {
Fg Color
Bg Color
Reverse bool
Bold bool
Underline bool
}
// Theme defines the styles for a set of identifiers.
type Theme struct {
styles map[string]Style
}
// DefaultTheme is a theme with reasonable defaults.
var DefaultTheme = &Theme{
styles: map[string]Style{
"list.item.selected": {Reverse: true},
"table.cell.selected": {Reverse: true},
"button.focused": {Reverse: true},
"box.focused": {Reverse: true},
},
}
// NewTheme return an empty theme.
func NewTheme() *Theme {
return &Theme{
styles: make(map[string]Style),
}
}
// SetStyle sets a style for a given identifier.
func (p *Theme) SetStyle(n string, i Style) {
p.styles[n] = i
}
// Style returns the style associated with an identifier.
func (p *Theme) Style(name string) Style {
if c, ok := p.styles[name]; ok {
return c
}
return Style{Fg: ColorDefault, Bg: ColorDefault}
}
// HasStyle returns whether an identifier is associated with an identifier.
func (p *Theme) HasStyle(name string) bool {
_, ok := p.styles[name]
return ok
}