2019-01-28 23:09:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-03-14 03:01:44 +00:00
|
|
|
ui "github.com/gizak/termui/v3"
|
2019-03-10 04:41:23 +00:00
|
|
|
"github.com/sqshq/sampler/asset"
|
2019-02-24 04:49:09 +00:00
|
|
|
"github.com/sqshq/sampler/component"
|
|
|
|
"github.com/sqshq/sampler/component/asciibox"
|
|
|
|
"github.com/sqshq/sampler/component/barchart"
|
2019-02-26 04:36:23 +00:00
|
|
|
"github.com/sqshq/sampler/component/gauge"
|
2019-03-08 04:04:46 +00:00
|
|
|
"github.com/sqshq/sampler/component/layout"
|
2019-02-24 04:49:09 +00:00
|
|
|
"github.com/sqshq/sampler/component/runchart"
|
2019-02-02 14:45:53 +00:00
|
|
|
"github.com/sqshq/sampler/config"
|
|
|
|
"github.com/sqshq/sampler/console"
|
|
|
|
"github.com/sqshq/sampler/data"
|
|
|
|
"github.com/sqshq/sampler/event"
|
2019-01-28 23:09:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2019-02-25 00:08:36 +00:00
|
|
|
cfg, flg := config.Load()
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
console.Init()
|
|
|
|
defer console.Close()
|
2019-01-30 00:21:57 +00:00
|
|
|
|
2019-03-10 04:41:23 +00:00
|
|
|
player := asset.NewAudioPlayer()
|
|
|
|
defer player.Close()
|
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
width, height := ui.TerminalDimensions()
|
|
|
|
lout := layout.NewLayout(width, height, component.NewStatusLine(flg.ConfigFileName), component.NewMenu())
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
for _, c := range cfg.RunCharts {
|
|
|
|
chart := runchart.NewRunChart(c)
|
2019-03-16 23:59:28 +00:00
|
|
|
cpt := component.NewComponent(chart, chart.Consumer, c.ComponentConfig, config.TypeRunChart)
|
2019-03-10 04:41:23 +00:00
|
|
|
triggers := data.NewTriggers(c.Triggers, chart.Consumer, player)
|
2019-03-16 04:35:00 +00:00
|
|
|
data.NewSampler(chart.Consumer, data.NewItems(c.Items), triggers, *c.RefreshRateMs)
|
2019-03-16 23:59:28 +00:00
|
|
|
lout.AddComponent(cpt)
|
2019-01-31 00:02:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 23:00:00 +00:00
|
|
|
for _, a := range cfg.AsciiBoxes {
|
2019-03-08 04:04:46 +00:00
|
|
|
box := asciibox.NewAsciiBox(a)
|
2019-03-16 23:59:28 +00:00
|
|
|
cpt := component.NewComponent(box, box.Consumer, a.ComponentConfig, config.TypeRunChart)
|
2019-03-10 04:41:23 +00:00
|
|
|
triggers := data.NewTriggers(a.Triggers, box.Consumer, player)
|
2019-03-16 04:35:00 +00:00
|
|
|
data.NewSampler(box.Consumer, data.NewItems([]config.Item{a.Item}), triggers, *a.RefreshRateMs)
|
2019-03-16 23:59:28 +00:00
|
|
|
lout.AddComponent(cpt)
|
2019-02-17 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
for _, b := range cfg.BarCharts {
|
2019-03-16 04:35:00 +00:00
|
|
|
chart := barchart.NewBarChart(b)
|
2019-03-16 23:59:28 +00:00
|
|
|
cpt := component.NewComponent(chart, chart.Consumer, b.ComponentConfig, config.TypeRunChart)
|
2019-03-10 04:41:23 +00:00
|
|
|
triggers := data.NewTriggers(b.Triggers, chart.Consumer, player)
|
2019-03-16 04:35:00 +00:00
|
|
|
data.NewSampler(chart.Consumer, data.NewItems(b.Items), triggers, *b.RefreshRateMs)
|
2019-03-16 23:59:28 +00:00
|
|
|
lout.AddComponent(cpt)
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, gc := range cfg.Gauges {
|
2019-03-16 04:35:00 +00:00
|
|
|
g := gauge.NewGauge(gc)
|
2019-03-16 23:59:28 +00:00
|
|
|
cpt := component.NewComponent(g, g.Consumer, gc.ComponentConfig, config.TypeRunChart)
|
2019-03-10 04:41:23 +00:00
|
|
|
triggers := data.NewTriggers(gc.Triggers, g.Consumer, player)
|
2019-03-16 04:35:00 +00:00
|
|
|
data.NewSampler(g.Consumer, data.NewItems(gc.Items), triggers, *gc.RefreshRateMs)
|
2019-03-16 23:59:28 +00:00
|
|
|
lout.AddComponent(cpt)
|
2019-02-19 04:07:32 +00:00
|
|
|
}
|
|
|
|
|
2019-03-08 04:04:46 +00:00
|
|
|
handler := event.NewHandler(lout)
|
2019-02-02 04:39:34 +00:00
|
|
|
handler.HandleEvents()
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|