-
-
Notifications
You must be signed in to change notification settings - Fork 566
/
main.go
87 lines (76 loc) · 3 KB
/
main.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
package main
import (
ui "github.com/gizak/termui/v3"
"github.com/sqshq/sampler/asset"
"github.com/sqshq/sampler/component"
"github.com/sqshq/sampler/component/asciibox"
"github.com/sqshq/sampler/component/barchart"
"github.com/sqshq/sampler/component/gauge"
"github.com/sqshq/sampler/component/layout"
"github.com/sqshq/sampler/component/runchart"
"github.com/sqshq/sampler/component/sparkline"
"github.com/sqshq/sampler/component/textbox"
"github.com/sqshq/sampler/config"
"github.com/sqshq/sampler/console"
"github.com/sqshq/sampler/data"
"github.com/sqshq/sampler/event"
"time"
)
type Starter struct {
player *asset.AudioPlayer
lout *layout.Layout
palette console.Palette
opt config.Options
cfg config.Config
}
func (s *Starter) startAll() []*data.Sampler {
samplers := make([]*data.Sampler, 0)
for _, c := range s.cfg.RunCharts {
cpt := runchart.NewRunChart(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers))
}
for _, c := range s.cfg.SparkLines {
cpt := sparkline.NewSparkLine(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers))
}
for _, c := range s.cfg.BarCharts {
cpt := barchart.NewBarChart(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers))
}
for _, c := range s.cfg.Gauges {
cpt := gauge.NewGauge(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Cur, c.Min, c.Max}, c.Triggers))
}
for _, c := range s.cfg.AsciiBoxes {
cpt := asciibox.NewAsciiBox(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers))
}
for _, c := range s.cfg.TextBoxes {
cpt := textbox.NewTextBox(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers))
}
return samplers
}
func (s *Starter) start(drawable ui.Drawable, consumer *data.Consumer, componentConfig config.ComponentConfig, itemsConfig []config.Item, triggersConfig []config.TriggerConfig) *data.Sampler {
cpt := component.NewComponent(drawable, consumer, componentConfig)
triggers := data.NewTriggers(triggersConfig, consumer, s.opt, s.player)
items := data.NewItems(itemsConfig, *componentConfig.RateMs)
s.lout.AddComponent(cpt)
time.Sleep(10 * time.Millisecond) // desync coroutines
return data.NewSampler(consumer, items, triggers, s.opt, s.cfg.Variables, *componentConfig.RateMs)
}
func main() {
cfg, opt := config.LoadConfig()
console.Init()
defer console.Close()
player := asset.NewAudioPlayer()
if player != nil {
defer player.Close()
}
palette := console.GetPalette(*cfg.Theme)
lout := layout.NewLayout(component.NewStatusBar(*opt.ConfigFile, palette), component.NewMenu(palette))
starter := &Starter{player, lout, palette, opt, *cfg}
samplers := starter.startAll()
handler := event.NewHandler(samplers, opt, lout)
handler.HandleEvents()
}