forked from gizak/termui
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (49 loc) · 1.16 KB
/
main.go
File metadata and controls
57 lines (49 loc) · 1.16 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"log"
"math/rand"
ui "github.com/metaspartan/gotui/v5"
"github.com/metaspartan/gotui/v5/widgets"
)
func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize gotui: %v", err)
}
defer ui.Close()
h := widgets.NewHeatmap()
h.Title = "Server Load Heatmap"
// Generate random data
// 10 rows, 10 cols
data := make([][]float64, 15)
for i := range data {
row := make([]float64, 10)
for j := range row {
row[j] = rand.Float64() * 100
}
data[i] = row
}
h.Data = data
h.CellWidth = 3
h.YLabels = []string{"Node1", "Node2", "Node3", "Node4", "Node5", "Node6", "Node7", "Node8", "Node9", "Node10"}
h.Colors = []ui.Color{
ui.NewRGBColor(0, 255, 0), // Green
ui.NewRGBColor(255, 255, 0), // Yellow
ui.NewRGBColor(255, 165, 0), // Orange
ui.NewRGBColor(255, 0, 0), // Red
}
termWidth, termHeight := ui.TerminalDimensions()
h.SetRect(0, 0, termWidth, termHeight)
ui.Render(h)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
case "<Resize>":
payload := e.Payload.(ui.Resize)
h.SetRect(0, 0, payload.Width, payload.Height)
ui.Render(h)
}
}
}