sampler-fork/main.go

57 lines
1.6 KiB
Go
Raw Normal View History

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"
)
func main() {
2019-02-15 04:34:45 +00:00
cfg := config.Load()
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
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)
layout.AddComponent(config.TypeRunChart, chart, c.Title, c.Position, c.Size, *c.RefreshRateMs)
2019-01-28 23:09:52 +00:00
for _, item := range c.Items {
2019-02-17 23:00:00 +00:00
chart.AddLine(*item.Label, *item.Color)
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(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)
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)
}
}
handler := event.NewHandler(layout)
handler.HandleEvents()
2019-01-28 23:09:52 +00:00
}