2019-01-28 23:09:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
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"
|
|
|
|
"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
|
|
|
ui "github.com/sqshq/termui"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2019-02-25 00:08:36 +00:00
|
|
|
cfg, flg := config.Load()
|
2019-02-02 04:39:34 +00:00
|
|
|
csl := console.Console{}
|
|
|
|
csl.Init()
|
|
|
|
defer csl.Close()
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-02-11 02:51:55 +00:00
|
|
|
width, height := ui.TerminalDimensions()
|
2019-02-25 00:08:36 +00:00
|
|
|
layout := component.NewLayout(width, height, component.NewStatusLine(flg.ConfigFileName), component.NewMenu())
|
2019-01-30 00:21:57 +00:00
|
|
|
|
2019-02-11 03:26:51 +00:00
|
|
|
for _, c := range cfg.RunCharts {
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-02-15 04:34:45 +00:00
|
|
|
legend := runchart.Legend{Enabled: c.Legend.Enabled, Details: c.Legend.Details}
|
2019-02-19 04:07:32 +00:00
|
|
|
chart := runchart.NewRunChart(c.Title, *c.Scale, *c.RefreshRateMs, legend)
|
2019-02-24 04:42:52 +00:00
|
|
|
layout.AddComponent(config.TypeRunChart, chart, c.Title, c.Position, c.Size, *c.RefreshRateMs)
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-02-11 03:26:51 +00:00
|
|
|
for _, item := range c.Items {
|
2019-02-17 23:00:00 +00:00
|
|
|
chart.AddLine(*item.Label, *item.Color)
|
2019-02-17 01:54:48 +00:00
|
|
|
data.NewSampler(chart, item, *c.RefreshRateMs)
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
2019-01-31 00:02:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 23:00:00 +00:00
|
|
|
for _, a := range cfg.AsciiBoxes {
|
|
|
|
box := asciibox.NewAsciiBox(a.Title, *a.Font, *a.Item.Color)
|
2019-02-24 04:42:52 +00:00
|
|
|
layout.AddComponent(config.TypeAsciiBox, box, a.Title, a.Position, a.Size, *a.RefreshRateMs)
|
2019-02-17 23:00:00 +00:00
|
|
|
data.NewSampler(box, a.Item, *a.RefreshRateMs)
|
|
|
|
}
|
|
|
|
|
2019-02-19 04:07:32 +00:00
|
|
|
for _, c := range cfg.BarCharts {
|
|
|
|
|
|
|
|
chart := barchart.NewBarChart(c.Title, *c.Scale)
|
2019-02-24 04:42:52 +00:00
|
|
|
layout.AddComponent(config.TypeBarChart, chart, c.Title, c.Position, c.Size, *c.RefreshRateMs)
|
2019-02-19 04:07:32 +00:00
|
|
|
|
|
|
|
for _, item := range c.Items {
|
|
|
|
chart.AddBar(*item.Label, *item.Color)
|
|
|
|
data.NewSampler(chart, item, *c.RefreshRateMs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 04:42:52 +00:00
|
|
|
handler := event.NewHandler(layout)
|
2019-02-02 04:39:34 +00:00
|
|
|
handler.HandleEvents()
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|