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
84 lines (73 loc) · 1.73 KB
/
main.go
File metadata and controls
84 lines (73 loc) · 1.73 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"log"
"math"
"time"
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()
// 1. Basic Sine Wave (Braille)
p1 := widgets.NewPlot()
p1.Title = "Braille Line Chart (Sine Wave)"
p1.Data = make([][]float64, 2)
p1.Data[0] = make([]float64, 100)
p1.Data[1] = make([]float64, 100)
p1.AxesColor = ui.ColorWhite
p1.LineColors[0] = ui.ColorLightCyan
p1.LineColors[1] = ui.ColorYellow
p1.Marker = widgets.MarkerBraille
p1.Fill = true // Enable filled area mode // Default, gives high resolution lines
// 2. Dot Mode Comparison
p2 := widgets.NewPlot()
p2.Title = "Dot Mode (Same Data)"
p2.Data = make([][]float64, 2)
p2.AxesColor = ui.ColorWhite
p2.LineColors[0] = ui.ColorLightCyan
p2.LineColors[1] = ui.ColorYellow
p2.Marker = widgets.MarkerDot
// Grid layout
grid := ui.NewGrid()
termWidth, termHeight := ui.TerminalDimensions()
grid.SetRect(0, 0, termWidth, termHeight)
grid.Set(
ui.NewRow(1.0,
ui.NewCol(0.5, p1),
ui.NewCol(0.5, p2),
),
)
update := func(tick int) {
for i := 0; i < 100; i++ {
p1.Data[0][i] = math.Sin(float64(i+tick) / 10)
p1.Data[1][i] = math.Cos(float64(i+tick) / 10)
}
p2.Data = p1.Data
}
update(0)
ui.Render(grid)
ticker := time.NewTicker(50 * time.Millisecond).C
uiEvents := ui.PollEvents()
count := 0
for {
select {
case e := <-uiEvents:
switch e.ID {
case "q", "<C-c>":
return
case "<Resize>":
payload := e.Payload.(ui.Resize)
grid.SetRect(0, 0, payload.Width, payload.Height)
ui.Clear()
ui.Render(grid)
}
case <-ticker:
count++
update(count)
ui.Render(grid)
}
}
}