2019-01-28 23:09:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
ui "github.com/sqshq/termui"
|
|
|
|
"github.com/sqshq/vcmd/config"
|
2019-01-31 00:02:38 +00:00
|
|
|
"github.com/sqshq/vcmd/data"
|
|
|
|
"github.com/sqshq/vcmd/layout"
|
2019-01-28 23:09:52 +00:00
|
|
|
"github.com/sqshq/vcmd/widgets"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-01-31 00:02:38 +00:00
|
|
|
/*
|
|
|
|
TODO validation
|
|
|
|
- title uniquness and mandatory within a single type of widget
|
|
|
|
- label uniqueness and mandatory (if > 1 data bullets)
|
|
|
|
*/
|
2019-01-28 23:09:52 +00:00
|
|
|
func main() {
|
|
|
|
|
2019-01-31 00:02:38 +00:00
|
|
|
// todo error handling + validation
|
2019-01-28 23:09:52 +00:00
|
|
|
cfg := config.Load("/Users/sqshq/Go/src/github.com/sqshq/vcmd/config.yml")
|
|
|
|
|
|
|
|
if err := ui.Init(); err != nil {
|
2019-01-31 00:02:38 +00:00
|
|
|
log.Fatalf("failed to initialize termui: %v", err)
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defer ui.Close()
|
2019-01-31 00:02:38 +00:00
|
|
|
events := ui.PollEvents()
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-01-31 00:02:38 +00:00
|
|
|
pollers := make([]data.Poller, 0)
|
|
|
|
lout := layout.NewLayout(ui.TerminalDimensions())
|
2019-01-30 00:21:57 +00:00
|
|
|
|
2019-01-31 01:41:51 +00:00
|
|
|
for _, chartConfig := range cfg.RunCharts {
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-01-31 01:41:51 +00:00
|
|
|
chart := widgets.NewRunChart(chartConfig.Title)
|
2019-01-31 00:02:38 +00:00
|
|
|
lout.AddItem(chart, chartConfig.Position, chartConfig.Size)
|
2019-01-28 23:09:52 +00:00
|
|
|
|
2019-01-31 00:02:38 +00:00
|
|
|
for _, chartData := range chartConfig.DataConfig {
|
|
|
|
pollers = append(pollers,
|
|
|
|
data.NewPoller(chart, chartData.Script, chartData.Label, chartConfig.RefreshRateMs))
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
2019-01-31 00:02:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 04:15:15 +00:00
|
|
|
ticker := time.NewTicker(30 * time.Millisecond)
|
2019-01-28 23:09:52 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
2019-01-31 00:02:38 +00:00
|
|
|
case e := <-events:
|
2019-01-28 23:09:52 +00:00
|
|
|
switch e.ID {
|
2019-01-31 00:02:38 +00:00
|
|
|
case "q", "<C-c>":
|
2019-01-28 23:09:52 +00:00
|
|
|
return
|
2019-01-30 00:21:57 +00:00
|
|
|
case "<Resize>":
|
|
|
|
payload := e.Payload.(ui.Resize)
|
2019-01-31 00:02:38 +00:00
|
|
|
lout.ChangeDimensions(payload.Width, payload.Height)
|
|
|
|
case "<MouseLeft>":
|
|
|
|
//payload := e.Payload.(ui.Mouse)
|
|
|
|
//x, y := payload.X, payload.Y
|
|
|
|
//log.Printf("x: %v, y: %v", x, y)
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
|
|
|
switch e.Type {
|
2019-01-31 00:02:38 +00:00
|
|
|
case ui.KeyboardEvent:
|
2019-01-28 23:09:52 +00:00
|
|
|
switch e.ID {
|
|
|
|
case "<Left>":
|
2019-01-31 00:02:38 +00:00
|
|
|
// here we are going to move selection (special type of layout item)
|
2019-01-31 01:41:51 +00:00
|
|
|
//lout.GetItem("").Move(-1, 0)
|
2019-01-28 23:09:52 +00:00
|
|
|
case "<Right>":
|
2019-01-31 01:41:51 +00:00
|
|
|
//lout.GetItem(0).Move(1, 0)
|
2019-01-28 23:09:52 +00:00
|
|
|
case "<Down>":
|
2019-01-31 01:41:51 +00:00
|
|
|
//lout.GetItem(0).Move(0, 1)
|
2019-01-28 23:09:52 +00:00
|
|
|
case "<Up>":
|
2019-01-31 01:41:51 +00:00
|
|
|
//lout.GetItem(0).Move(0, -1)
|
2019-01-28 23:09:52 +00:00
|
|
|
case "p":
|
2019-01-31 00:02:38 +00:00
|
|
|
for _, poller := range pollers {
|
|
|
|
poller.TogglePause()
|
|
|
|
}
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-31 00:02:38 +00:00
|
|
|
case <-ticker.C:
|
|
|
|
ui.Render(lout)
|
2019-01-28 23:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|