-
Notifications
You must be signed in to change notification settings - Fork 12
/
gauge_am.go
101 lines (79 loc) · 2.33 KB
/
gauge_am.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
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
package tvxwidgets
import (
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
// ActivityModeGauge represents activity mode gauge permitive.
type ActivityModeGauge struct {
*tview.Box
// counter value
counter int
// pgBgColor: progress block background color
pgBgColor tcell.Color
}
// NewActivityModeGauge returns new activity mode gauge permitive.
func NewActivityModeGauge() *ActivityModeGauge {
gauge := &ActivityModeGauge{
Box: tview.NewBox(),
counter: 0,
pgBgColor: tcell.ColorBlue,
}
return gauge
}
// Draw draws this primitive onto the screen.
func (g *ActivityModeGauge) Draw(screen tcell.Screen) {
g.Box.DrawForSubclass(screen, g)
x, y, width, height := g.Box.GetInnerRect()
tickStr := g.tickStr(width)
for i := range height {
tview.Print(screen, tickStr, x, y+i, width, tview.AlignLeft, g.pgBgColor)
}
}
// Focus is called when this primitive receives focus.
func (g *ActivityModeGauge) Focus(delegate func(p tview.Primitive)) { //nolint:revive
}
// HasFocus returns whether or not this primitive has focus.
func (g *ActivityModeGauge) HasFocus() bool {
return g.Box.HasFocus()
}
// GetRect return primitive current rect.
func (g *ActivityModeGauge) GetRect() (int, int, int, int) {
return g.Box.GetRect()
}
// SetRect sets rect for this primitive.
func (g *ActivityModeGauge) SetRect(x, y, width, height int) {
g.Box.SetRect(x, y, width, height)
}
// SetPgBgColor sets progress block background color.
func (g *ActivityModeGauge) SetPgBgColor(color tcell.Color) {
g.pgBgColor = color
}
// Pulse pulse update the gauge progress bar.
func (g *ActivityModeGauge) Pulse() {
g.counter++
}
// Reset resets the gauge counter (set to 0).
func (g *ActivityModeGauge) Reset() {
g.counter = 0
}
func (g *ActivityModeGauge) tickStr(maxCount int) string {
var (
prgHeadStr string
prgEndStr string
prgStr string
)
if g.counter >= maxCount-4 {
g.counter = 0
}
hWidth := 0
for range g.counter {
prgHeadStr += fmt.Sprintf("[%s::]%s", getColorName(tview.Styles.PrimitiveBackgroundColor), prgCell)
hWidth++
}
prgStr = prgCell + prgCell + prgCell + prgCell
for range maxCount + hWidth + 4 {
prgEndStr += fmt.Sprintf("[%s::]%s", getColorName(tview.Styles.PrimitiveBackgroundColor), prgCell)
}
return fmt.Sprintf("%s[%s::]%s%s", prgHeadStr, getColorName(g.pgBgColor), prgStr, prgEndStr)
}