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-03-24 22:46:39 +00:00
|
|
|
"github.com/sqshq/sampler/component/sparkline"
|
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
|
|
|
)
|
|
|
|
|
2019-03-17 23:55:24 +00:00
|
|
|
type Starter struct {
|
|
|
|
lout *layout.Layout
|
|
|
|
player *asset.AudioPlayer
|
2019-03-19 03:02:02 +00:00
|
|
|
opt config.Options
|
2019-03-17 23:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Starter) start(drawable ui.Drawable, consumer *data.Consumer, conponentConfig config.ComponentConfig, itemsConfig []config.Item, triggersConfig []config.TriggerConfig) {
|
|
|
|
cpt := component.NewComponent(drawable, consumer, conponentConfig)
|
2019-03-21 02:23:08 +00:00
|
|
|
triggers := data.NewTriggers(triggersConfig, consumer, s.opt, s.player)
|
|
|
|
data.NewSampler(consumer, data.NewItems(itemsConfig), triggers, s.opt, *conponentConfig.RefreshRateMs)
|
2019-03-17 23:55:24 +00:00
|
|
|
s.lout.AddComponent(cpt)
|
|
|
|
}
|
|
|
|
|
2019-01-28 23:09:52 +00:00
|
|
|
func main() {
|
|
|
|
|
2019-03-19 03:02:02 +00:00
|
|
|
cfg, opt := 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-24 00:16:59 +00:00
|
|
|
palette := console.GetPalette(*cfg.Theme)
|
2019-03-16 04:35:00 +00:00
|
|
|
width, height := ui.TerminalDimensions()
|
2019-03-24 00:16:59 +00:00
|
|
|
|
|
|
|
lout := layout.NewLayout(width, height, component.NewStatusLine(opt.ConfigFile, palette), component.NewMenu(palette))
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-03-19 03:02:02 +00:00
|
|
|
starter := &Starter{lout, player, opt}
|
2019-03-17 23:55:24 +00:00
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
for _, c := range cfg.RunCharts {
|
2019-03-24 00:16:59 +00:00
|
|
|
cpt := runchart.NewRunChart(c, palette)
|
2019-03-17 23:55:24 +00:00
|
|
|
starter.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers)
|
2019-01-31 00:02:38 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 22:46:39 +00:00
|
|
|
for _, c := range cfg.SparkLines {
|
|
|
|
cpt := sparkline.NewSparkLine(c, palette)
|
|
|
|
starter.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers)
|
|
|
|
}
|
|
|
|
|
2019-03-17 23:55:24 +00:00
|
|
|
for _, c := range cfg.AsciiBoxes {
|
2019-03-24 00:16:59 +00:00
|
|
|
cpt := asciibox.NewAsciiBox(c, palette)
|
2019-03-17 23:55:24 +00:00
|
|
|
starter.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers)
|
2019-02-17 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 23:55:24 +00:00
|
|
|
for _, c := range cfg.BarCharts {
|
2019-03-24 00:16:59 +00:00
|
|
|
cpt := barchart.NewBarChart(c, palette)
|
2019-03-17 23:55:24 +00:00
|
|
|
starter.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers)
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 23:55:24 +00:00
|
|
|
for _, c := range cfg.Gauges {
|
2019-03-24 00:16:59 +00:00
|
|
|
cpt := gauge.NewGauge(c, palette)
|
2019-03-17 23:55:24 +00:00
|
|
|
starter.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers)
|
2019-02-19 04:07:32 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 02:12:45 +00:00
|
|
|
handler := event.NewHandler(lout, opt)
|
2019-02-02 04:39:34 +00:00
|
|
|
handler.HandleEvents()
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|