forked from marcusolsson/tui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.go
97 lines (84 loc) · 2.04 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package tui
// Color represents a color.
type Color int32
// Common colors.
const (
ColorDefault Color = iota
ColorBlack
ColorWhite
ColorRed
ColorGreen
ColorBlue
ColorCyan
ColorMagenta
ColorYellow
)
// Decoration represents a bold/underline/etc. state
type Decoration int
// Decoration modes: Inherit from parent widget, explicitly on, or explicitly off.
const (
DecorationInherit Decoration = iota
DecorationOn
DecorationOff
)
// Style determines how a cell should be painted.
// The zero value uses default from
type Style struct {
Fg Color
Bg Color
Reverse Decoration
Bold Decoration
Underline Decoration
}
// mergeIn returns the receiver Style, with any changes in delta applied.
func (s Style) mergeIn(delta Style) Style {
result := s
if delta.Fg != ColorDefault {
result.Fg = delta.Fg
}
if delta.Bg != ColorDefault {
result.Bg = delta.Bg
}
if delta.Reverse != DecorationInherit {
result.Reverse = delta.Reverse
}
if delta.Bold != DecorationInherit {
result.Bold = delta.Bold
}
if delta.Underline != DecorationInherit {
result.Underline = delta.Underline
}
return result
}
// 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: DecorationOn},
"table.cell.selected": {Reverse: DecorationOn},
"button.focused": {Reverse: DecorationOn},
},
}
// 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.
// If there is no Style associated with the name, it returns a default Style.
func (p *Theme) Style(name string) Style {
return p.styles[name]
}
// HasStyle returns whether an identifier is associated with an identifier.
func (p *Theme) HasStyle(name string) bool {
_, ok := p.styles[name]
return ok
}