forked from wtfutil/wtf
/
display.go
56 lines (45 loc) · 967 Bytes
/
display.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
package wtf
import (
"github.com/rivo/tview"
)
type Display struct {
Grid *tview.Grid
}
func NewDisplay(widgets []Wtfable) *Display {
display := Display{
Grid: tview.NewGrid(),
}
display.build(widgets)
display.Grid.SetBackgroundColor(
ColorFor(
Config.UString("wtf.colors.background", "black"),
),
)
return &display
}
/* -------------------- Unexported Functions -------------------- */
func (display *Display) add(widget Wtfable) {
if widget.Disabled() {
return
}
display.Grid.AddItem(
widget.TextView(),
widget.Top(),
widget.Left(),
widget.Height(),
widget.Width(),
0,
0,
false,
)
}
func (display *Display) build(widgets []Wtfable) *tview.Grid {
display.Grid.SetColumns(ToInts(Config.UList("wtf.grid.columns"))...)
display.Grid.SetRows(ToInts(Config.UList("wtf.grid.rows"))...)
display.Grid.SetBorder(false)
for _, widget := range widgets {
display.add(widget)
go Schedule(widget)
}
return display.Grid
}