package main import ( ui "github.com/sqshq/termui" "github.com/sqshq/vcmd/config" "github.com/sqshq/vcmd/data" "github.com/sqshq/vcmd/layout" "github.com/sqshq/vcmd/widgets" "log" "time" ) func main() { cfg := config.Load("/Users/sqshq/Go/src/github.com/sqshq/vcmd/config.yml") if err := ui.Init(); err != nil { log.Fatalf("failed to initialize termui: %v", err) } defer ui.Close() events := ui.PollEvents() pollers := make([]data.Poller, 0) lout := layout.NewLayout(ui.TerminalDimensions()) for _, chartConfig := range cfg.RunCharts { chart := widgets.NewRunChart(chartConfig.Title) lout.AddItem(chart, chartConfig.Position, chartConfig.Size) for _, item := range chartConfig.Items { pollers = append(pollers, data.NewPoller(chart, item, chartConfig.RefreshRateMs)) } } ticker := time.NewTicker(30 * time.Millisecond) for { select { case e := <-events: switch e.ID { case "q", "": return case "": payload := e.Payload.(ui.Resize) lout.ChangeDimensions(payload.Width, payload.Height) case "": //payload := e.Payload.(ui.Mouse) //x, y := payload.X, payload.Y //log.Printf("x: %v, y: %v", x, y) } switch e.Type { case ui.KeyboardEvent: switch e.ID { case "": // here we are going to move selection (special type of layout item) //lout.GetItem("").Move(-1, 0) case "": //lout.GetItem(0).Move(1, 0) case "": //lout.GetItem(0).Move(0, 1) case "": //lout.GetItem(0).Move(0, -1) case "p": for _, poller := range pollers { poller.TogglePause() } } } case <-ticker.C: ui.Render(lout) } } }