-
Notifications
You must be signed in to change notification settings - Fork 44
/
events.go
94 lines (73 loc) · 1.62 KB
/
events.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
package solar
import (
"fmt"
"time"
spin "github.com/tj/go-spin"
)
type eventReporter func(interface{})
type events struct {
in chan interface{}
reporters []eventReporter
}
func (r *events) Submit(item interface{}) {
r.in <- item
}
// func (r *events) Subscribe(fn eventReporter) {
// r.reporters = append(r.reporters, fn)
// }
func (r *events) Start() {
ticker := time.NewTicker(150 * time.Millisecond)
var tickerInfo string
spinner := spin.New()
spinner.Set(spin.Spin3)
for {
select {
case <-ticker.C:
if tickerInfo != "" {
fmt.Printf("\r%s %s", spinner.Next(), tickerInfo)
}
case e := <-r.in:
switch e := e.(type) {
case eventProgress:
tickerInfo = e.info
// log.Println(e)
case eventProgressEnd:
fmt.Printf("\033[2K\033[1000D%s\n", e.info)
tickerInfo = ""
// log.Println(e)
}
}
// for _, reporterFn := range r.reporters {
// reporterFn(event)
// }
}
}
type eventProgress struct {
// [spinner] [info]
info string
}
type eventProgressEnd struct {
info string
}
// type eventConfirmContract struct {
// }
// type eventConfirmContractsStart struct {
// total int
// }
// type contractConfirmationReporter struct {
// init sync.Once
// }
// func (r *contractConfirmationReporter) Report(e interface{}) (err error) {
// switch e := e.(type) {
// case *eventConfirmContractsStart:
// }
// // if e, ok := i.(*eventConfirmContractProgress); ok {
// // // if e.n == 0 {
// // // r.init.Do(func() {
// // // })
// // // }
// // fmt.Sprintf("[%d/%d] Confirming contracts")
// // }
// }
// func (r *contractConfirmationReporter) Start() {
// }