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-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}
|
|
|
|
chart := runchart.NewRunChart(c.Title, c.Precision, c.RefreshRateMs, legend)
|
2019-02-11 03:26:51 +00:00
|
|
|
layout.AddComponent(chart, c.Title, c.Position, c.Size, widgets.TypeRunChart)
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-02-11 03:26:51 +00:00
|
|
|
for _, item := range c.Items {
|
|
|
|
data.NewSampler(chart, item, c.RefreshRateMs)
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
2019-01-31 00:02:38 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|