-
Notifications
You must be signed in to change notification settings - Fork 786
/
gauge.go
72 lines (60 loc) · 1.54 KB
/
gauge.go
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
// Copyright 2017 Zack Guo <[email protected]>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import (
"fmt"
"log"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
g0 := widgets.NewGauge()
g0.Title = "Slim Gauge"
g0.SetRect(20, 20, 30, 30)
g0.Percent = 75
g0.BarColor = ui.ColorRed
g0.BorderStyle.Fg = ui.ColorWhite
g0.TitleStyle.Fg = ui.ColorCyan
g2 := widgets.NewGauge()
g2.Title = "Slim Gauge"
g2.SetRect(0, 3, 50, 6)
g2.Percent = 60
g2.BarColor = ui.ColorYellow
g2.LabelStyle = ui.NewStyle(ui.ColorBlue)
g2.BorderStyle.Fg = ui.ColorWhite
g1 := widgets.NewGauge()
g1.Title = "Big Gauge"
g1.SetRect(0, 6, 50, 11)
g1.Percent = 30
g1.BarColor = ui.ColorGreen
g1.LabelStyle = ui.NewStyle(ui.ColorYellow)
g1.TitleStyle.Fg = ui.ColorMagenta
g1.BorderStyle.Fg = ui.ColorWhite
g3 := widgets.NewGauge()
g3.Title = "Gauge with custom label"
g3.SetRect(0, 11, 50, 14)
g3.Percent = 50
g3.Label = fmt.Sprintf("%v%% (100MBs free)", g3.Percent)
g4 := widgets.NewGauge()
g4.Title = "Gauge"
g4.SetRect(0, 14, 50, 17)
g4.Percent = 50
g4.Label = "Gauge with custom highlighted label"
g4.BarColor = ui.ColorGreen
g4.LabelStyle = ui.NewStyle(ui.ColorYellow)
ui.Render(g0, g1, g2, g3, g4)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
}
}
}