forked from wtfutil/wtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.go
41 lines (30 loc) · 770 Bytes
/
widget.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
package status
import (
"github.com/senorprogrammer/wtf/wtf"
)
type Widget struct {
wtf.TextWidget
CurrentIcon int
}
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" Status ", "status", false),
CurrentIcon: 0,
}
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt()
widget.View.SetText(widget.animation())
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) animation() string {
icons := []string{"|", "/", "-", "\\", "|"}
next := icons[widget.CurrentIcon]
widget.CurrentIcon = widget.CurrentIcon + 1
if widget.CurrentIcon == len(icons) {
widget.CurrentIcon = 0
}
return next
}