forked from navidys/tvxwidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (34 loc) · 765 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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)
}
}