func Display()

in pkg/display/graph/dashboard/global.go [234:300]


func Display(ctx *cli.Context, data *dashboard.GlobalData) error {
	t, err := termbox.New(termbox.ColorMode(terminalapi.ColorMode256))
	if err != nil {
		return err
	}
	defer t.Close()

	c, err := container.New(
		t,
		container.Border(linestyle.Light),
		container.BorderTitle("[Global Dashboard]-PRESS Q TO QUIT"),
		container.ID(rootID))
	if err != nil {
		return err
	}

	te, err := dashboard.LoadTemplate(ctx.String("template"))
	if err != nil {
		return err
	}
	template = te

	// Initialization
	allWidgets = &widgets{
		gauges:  nil,
		linears: nil,
		heatmap: nil,
		buttons: nil,
	}
	err = newWidgets(data)
	if err != nil {
		return err
	}
	lb, err := newLayoutButtons(c)
	if err != nil {
		return err
	}
	allWidgets.buttons = lb

	gridOpts, err := gridLayout(layoutMetrics)
	if err != nil {
		return err
	}

	if e := c.Update(rootID, gridOpts...); e != nil {
		return e
	}

	con, cancel := context.WithCancel(context.Background())
	quitter := func(keyboard *terminalapi.Keyboard) {
		if strings.EqualFold(keyboard.Key.String(), "q") {
			cancel()
		}
	}

	refreshInterval := time.Duration(ctx.Int("refresh")) * time.Second
	dt := utils.DurationType(ctx.String("duration-type"))

	// Only when users use the relative time, the duration will be adjusted to refresh.
	if dt != utils.BothPresent {
		go refresh(con, ctx, refreshInterval)
	}

	err = termdash.Run(con, t, c, termdash.KeyboardSubscriber(quitter), termdash.RedrawInterval(refreshInterval))

	return err
}