mirror of
https://github.com/navidys/tvxwidgets.git
synced 2025-04-28 13:48:52 +08:00
29 lines
783 B
Go
29 lines
783 B
Go
// Demo code for the bar chart primitive.
|
|
package main
|
|
|
|
import (
|
|
"github.com/gdamore/tcell/v2"
|
|
"github.com/navidys/tvxwidgets"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
func main() {
|
|
app := tview.NewApplication()
|
|
barGraph := tvxwidgets.NewBarChart()
|
|
barGraph.SetRect(4, 2, 50, 20)
|
|
barGraph.SetBorder(true)
|
|
barGraph.SetTitle("System Resource Usage")
|
|
// display system metric usage
|
|
barGraph.AddBar("cpu", 80, tcell.ColorBlue)
|
|
barGraph.AddBar("mem", 20, tcell.ColorRed)
|
|
barGraph.AddBar("swap", 40, tcell.ColorGreen)
|
|
barGraph.AddBar("disk", 40, tcell.ColorOrange)
|
|
barGraph.SetMaxValue(100)
|
|
barGraph.SetAxesColor(tcell.ColorAntiqueWhite)
|
|
barGraph.SetAxesLabelColor(tcell.ColorAntiqueWhite)
|
|
|
|
if err := app.SetRoot(barGraph, false).EnableMouse(true).Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|