mirror of
https://github.com/navidys/tvxwidgets.git
synced 2025-05-01 22:18:14 +08:00
40 lines
765 B
Go
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)
|
|
}
|
|
}
|