-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
styles.go
251 lines (218 loc) · 6.03 KB
/
styles.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package config
import (
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"gopkg.in/yaml.v3"
"io"
"os"
)
// StyleListener represents a skin's listener.
type StyleListener interface {
// StylesChanged notifies listener the skin changed.
StylesChanged(*Styles)
}
type (
// Styles tracks process compose styling options.
Styles struct {
Style Style `yaml:"style"`
}
// Style tracks PC styles.
Style struct {
Name string `yaml:"name"`
Body Body `yaml:"body"`
StatTable StatTable `yaml:"stat_table"`
ProcTable ProcTable `yaml:"proc_table"`
Help Help `yaml:"help"`
Dialog Dialog `yaml:"dialog"`
}
// Body tracks body styles.
Body struct {
FgColor Color `yaml:"fgColor"`
BgColor Color `yaml:"bgColor"`
SecondaryTextColor Color `yaml:"secondaryTextColor"`
TertiaryTextColor Color `yaml:"tertiaryTextColor"`
BorderColor Color `yaml:"borderColor"`
}
// StatTable tracks stats table styles.
StatTable struct {
KeyFgColor Color `yaml:"keyFgColor"`
ValueFgColor Color `yaml:"valueFgColor"`
BgColor Color `yaml:"bgColor"`
LogoColor Color `yaml:"logoColor"`
}
// ProcTable tracks processes table styles.
ProcTable struct {
FgColor Color `yaml:"fgColor"`
FgWarning Color `yaml:"fgWarning"`
FgPending Color `yaml:"fgPending"`
FgCompleted Color `yaml:"fgCompleted"`
FgError Color `yaml:"fgError"`
BgColor Color `yaml:"bgColor"`
HeaderFgColor Color `yaml:"headerFgColor"`
}
// Help tracks help styles.
Help struct {
KeyColor Color `yaml:"keyColor"`
FgColor Color `yaml:"fgColor"`
HlColor Color `yaml:"hlColor"`
FgCategoryColor Color `yaml:"categoryFgColor"`
}
// Dialog tracks dialog styles.
Dialog struct {
FgColor Color `yaml:"fgColor"`
BgColor Color `yaml:"bgColor"`
ContrastBgColor Color `yaml:"contrastBgColor"`
AttentionBgColor Color `yaml:"attentionBgColor"`
ButtonFgColor Color `yaml:"buttonFgColor"`
ButtonBgColor Color `yaml:"buttonBgColor"`
ButtonFocusFgColor Color `yaml:"buttonFocusFgColor"`
ButtonFocusBgColor Color `yaml:"buttonFocusBgColor"`
LabelFgColor Color `yaml:"labelFgColor"`
FieldFgColor Color `yaml:"fieldFgColor"`
FieldBgColor Color `yaml:"fieldBgColor"`
}
)
func newStyle() Style {
return Style{
Name: "Default",
Body: newBody(),
StatTable: newStatTable(),
ProcTable: newProcTable(),
Help: newHelp(),
Dialog: newDialog(),
}
}
func newBody() Body {
return Body{
FgColor: "white",
BgColor: "black",
SecondaryTextColor: "yellow",
TertiaryTextColor: "green",
BorderColor: "white",
}
}
func newStatTable() StatTable {
return StatTable{
KeyFgColor: "yellow",
ValueFgColor: "white",
BgColor: "black",
LogoColor: "yellow",
}
}
func newProcTable() ProcTable {
return ProcTable{
HeaderFgColor: "white",
FgColor: "lightskyblue",
BgColor: "black",
FgWarning: "yellow",
FgPending: "grey",
FgCompleted: "lightgreen",
FgError: "red",
}
}
func newHelp() Help {
return Help{
FgColor: "black",
KeyColor: "white",
HlColor: "green",
FgCategoryColor: "lightskyblue",
}
}
func newDialog() Dialog {
return Dialog{
FgColor: "cadetblue",
BgColor: "black",
ButtonBgColor: "lightskyblue",
ButtonFgColor: "black",
ButtonFocusBgColor: "dodgerblue",
ButtonFocusFgColor: "black",
LabelFgColor: "yellow",
FieldFgColor: "black",
FieldBgColor: "lightskyblue",
}
}
// NewStyles creates a new default config.
func NewStyles() *Styles {
//var s Styles
//if err := yaml.Unmarshal(stockThemeTpl, &s); err == nil {
// return &s
//}
return &Styles{
Style: newStyle(),
}
}
// Load process compose styles from file.
func (s *Styles) Load(path string) error {
b, err := os.ReadFile(path)
if err != nil {
return err
}
if err := yaml.Unmarshal(b, s); err != nil {
return err
}
return nil
}
// FgColor returns the foreground color.
func (s *Styles) FgColor() tcell.Color {
return s.Body().FgColor.Color()
}
// BgColor returns the background color.
func (s *Styles) BgColor() tcell.Color {
return s.Body().BgColor.Color()
}
// ContrastBgColor returns the Contrast background color.
func (s *Styles) ContrastBgColor() tcell.Color {
return s.Dialog().ContrastBgColor.Color()
}
// AttentionBgColor returns the Contrast background color.
func (s *Styles) AttentionBgColor() tcell.Color {
return s.Dialog().AttentionBgColor.Color()
}
// BorderColor returns the border color.
func (s *Styles) BorderColor() tcell.Color {
return s.Body().BorderColor.Color()
}
// Body returns body styles.
func (s *Styles) Body() Body {
return s.Style.Body
}
// StatTable returns stat table styles.
func (s *Styles) StatTable() StatTable {
return s.Style.StatTable
}
// ProcTable returns process table styles.
func (s *Styles) ProcTable() ProcTable {
return s.Style.ProcTable
}
// Help returns help styles.
func (s *Styles) Help() Help {
return s.Style.Help
}
// Dialog returns dialog styles.
func (s *Styles) Dialog() Dialog {
return s.Style.Dialog
}
// Update apply terminal colors based on styles.
func (s *Styles) Update() {
tview.Styles.PrimitiveBackgroundColor = s.BgColor()
tview.Styles.ContrastBackgroundColor = s.ContrastBgColor()
tview.Styles.MoreContrastBackgroundColor = s.AttentionBgColor()
tview.Styles.PrimaryTextColor = s.FgColor()
tview.Styles.BorderColor = s.BorderColor()
tview.Styles.TitleColor = s.FgColor()
tview.Styles.GraphicsColor = s.FgColor()
tview.Styles.SecondaryTextColor = s.Body().SecondaryTextColor.Color()
tview.Styles.TertiaryTextColor = s.Body().TertiaryTextColor.Color()
tview.Styles.InverseTextColor = s.FgColor()
tview.Styles.ContrastSecondaryTextColor = s.FgColor()
}
// GetStyleName returns the style name
func (s *Styles) GetStyleName() string {
return s.Style.Name
}
// Dump for debug.
func (s *Styles) Dump(w io.Writer) {
b, _ := yaml.Marshal(s)
_, _ = fmt.Fprintf(w, "%s", b)
}