2019-01-28 23:09:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
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"
|
|
|
|
"github.com/sqshq/sampler/widgets"
|
2019-02-17 23:00:00 +00:00
|
|
|
"github.com/sqshq/sampler/widgets/asciibox"
|
2019-02-19 04:07:32 +00:00
|
|
|
"github.com/sqshq/sampler/widgets/barchart"
|
2019-02-15 04:34:45 +00:00
|
|
|
"github.com/sqshq/sampler/widgets/runchart"
|
2019-01-28 23:09:52 +00:00
|
|
|
ui "github.com/sqshq/termui"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2019-02-15 04:34:45 +00:00
|
|
|
cfg := 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()
|
|
|
|
layout := widgets.NewLayout(width, height, widgets.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-17 01:54:48 +00:00
|
|
|
layout.AddComponent(chart, c.Title, c.Position, c.Size, config.TypeRunChart)
|
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)
|
|
|
|
layout.AddComponent(box, a.Title, a.Position, a.Size, config.TypeAsciiBox)
|
|
|
|
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)
|
|
|
|
layout.AddComponent(chart, c.Title, c.Position, c.Size, config.TypeBarChart)
|
|
|
|
|
|
|
|
for _, item := range c.Items {
|
|
|
|
chart.AddBar(*item.Label, *item.Color)
|
|
|
|
data.NewSampler(chart, item, *c.RefreshRateMs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 04:39:34 +00:00
|
|
|
handler := event.Handler{
|
|
|
|
Layout: layout,
|
|
|
|
RenderEvents: time.NewTicker(console.RenderRate).C,
|
|
|
|
ConsoleEvents: ui.PollEvents(),
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
2019-02-02 04:39:34 +00:00
|
|
|
|
|
|
|
handler.HandleEvents()
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|