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
116 lines (102 loc) · 2.27 KB
/
main.go
File metadata and controls
116 lines (102 loc) · 2.27 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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()
sinFloat64 := (func() []float64 {
n := 400
data := make([]float64, n)
for i := range data {
data[i] = 1 + math.Sin(float64(i)/5)
}
return data
})()
sl := widgets.NewSparkline()
sl.Data = sinFloat64[:100]
sl.LineColor = ui.ColorLightCyan
sl.TitleStyle.Fg = ui.ColorWhite
slg := widgets.NewSparklineGroup(sl)
slg.Title = "Sparkline"
lc := widgets.NewPlot()
lc.Title = "braille-mode Line Chart"
lc.Data = append(lc.Data, sinFloat64)
lc.AxesColor = ui.ColorWhite
lc.LineColors[0] = ui.ColorYellow
gs := make([]*widgets.Gauge, 3)
for i := range gs {
gs[i] = widgets.NewGauge()
gs[i].Percent = i * 10
gs[i].BarColor = ui.ColorRed
}
ls := widgets.NewList()
ls.Rows = []string{
"[1] Downloading File 1",
"",
"",
"",
"[2] Downloading File 2",
"",
"",
"",
"[3] Uploading File 3",
}
ls.Border = false
p := widgets.NewParagraph()
p.Text = "<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget"
p.Title = "Demonstration"
grid := ui.NewGrid()
termWidth, termHeight := ui.TerminalDimensions()
grid.SetRect(0, 0, termWidth, termHeight)
grid.Set(
ui.NewRow(1.0/2,
ui.NewCol(1.0/2, slg),
ui.NewCol(1.0/2, lc),
),
ui.NewRow(1.0/2,
ui.NewCol(1.0/4, ls),
ui.NewCol(1.0/4,
ui.NewRow(.9/3, gs[0]),
ui.NewRow(.9/3, gs[1]),
ui.NewRow(1.2/3, gs[2]),
),
ui.NewCol(1.0/2, p),
),
)
ui.Render(grid)
tickerCount := 1
uiEvents := ui.PollEvents()
ticker := time.NewTicker(time.Second).C
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:
if tickerCount == 100 {
return
}
for _, g := range gs {
g.Percent = (g.Percent + 3) % 100
}
slg.Sparklines[0].Data = sinFloat64[tickerCount : tickerCount+100]
lc.Data[0] = sinFloat64[2*tickerCount:]
ui.Render(grid)
tickerCount++
}
}
}