forked from wtfutil/wtf
/
widget.go
63 lines (48 loc) · 1.42 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cryptolive
import (
"fmt"
"sync"
"github.com/olebedev/config"
"github.com/senorprogrammer/wtf/cryptoexchanges/cryptolive/price"
"github.com/senorprogrammer/wtf/cryptoexchanges/cryptolive/toplist"
"github.com/senorprogrammer/wtf/wtf"
)
// Config is a pointer to the global config object
var Config *config.Config
// Widget define wtf widget to register widget later
type Widget struct {
wtf.TextWidget
priceWidget *price.Widget
toplistWidget *toplist.Widget
}
// NewWidget Make new instance of widget
func NewWidget() *Widget {
price.Config = Config
toplist.Config = Config
widget := Widget{
TextWidget: wtf.NewTextWidget(" CryptoLive ", "cryptolive", false),
priceWidget: price.NewWidget(),
toplistWidget: toplist.NewWidget(),
}
widget.priceWidget.RefreshInterval = widget.RefreshInterval()
widget.toplistWidget.RefreshInterval = widget.RefreshInterval()
return &widget
}
/* -------------------- Exported Functions -------------------- */
// Refresh & update after interval time
func (widget *Widget) Refresh() {
var wg sync.WaitGroup
wg.Add(2)
widget.priceWidget.Refresh(&wg)
widget.toplistWidget.Refresh(&wg)
wg.Wait()
widget.UpdateRefreshedAt()
display(widget)
}
/* -------------------- Unexported Functions -------------------- */
func display(widget *Widget) {
str := ""
str += widget.priceWidget.Result
str += widget.toplistWidget.Result
widget.View.SetText(fmt.Sprintf("\n%s", str))
}