mirror of
https://github.com/navidys/tvxwidgets.git
synced 2025-04-30 13:48:57 +08:00
42 lines
717 B
Go
42 lines
717 B
Go
// Demo code for the bar chart primitive.
|
|
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/navidys/tvxwidgets"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
func main() {
|
|
app := tview.NewApplication()
|
|
gauge := tvxwidgets.NewPercentageModeGauge()
|
|
gauge.SetTitle("percentage mode gauge")
|
|
gauge.SetRect(10, 4, 50, 3)
|
|
gauge.SetBorder(true)
|
|
|
|
value := 0
|
|
gauge.SetMaxValue(50)
|
|
|
|
update := func() {
|
|
tick := time.NewTicker(500 * time.Millisecond)
|
|
for {
|
|
select {
|
|
case <-tick.C:
|
|
if value > gauge.GetMaxValue() {
|
|
value = 0
|
|
} else {
|
|
value = value + 1
|
|
}
|
|
gauge.SetValue(value)
|
|
app.Draw()
|
|
}
|
|
}
|
|
}
|
|
go update()
|
|
|
|
if err := app.SetRoot(gauge, false).EnableMouse(true).Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|