Navid Yaghoobi 4339ead54b demo update
Signed-off-by: Navid Yaghoobi <navidys@fedoraproject.org>
2022-12-23 14:14:09 +11:00

40 lines
765 B
Go

// Demo code for the bar chart primitive.
package main
import (
"math/rand"
"time"
"github.com/gdamore/tcell/v2"
"github.com/navidys/tvxwidgets"
"github.com/rivo/tview"
)
func main() {
app := tview.NewApplication()
gauge := tvxwidgets.NewUtilModeGauge()
gauge.SetLabel("cpu usage:")
gauge.SetLabelColor(tcell.ColorLightSkyBlue)
gauge.SetRect(10, 4, 50, 3)
gauge.SetWarnPercentage(65)
gauge.SetCritPercentage(80)
gauge.SetBorder(true)
update := func() {
tick := time.NewTicker(500 * time.Millisecond)
for {
select {
case <-tick.C:
randNum := float64(rand.Float64() * 100)
gauge.SetValue(randNum)
app.Draw()
}
}
}
go update()
if err := app.SetRoot(gauge, false).EnableMouse(true).Run(); err != nil {
panic(err)
}
}