-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
81 lines (61 loc) · 1.54 KB
/
main.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
package main
import (
"fmt"
"net/http"
"os"
term "github.com/buger/goterm"
"github.com/pkg/errors"
)
func (p *Parser) Start(responses chan *http.Response, symbols ...string) (err error) {
p.symbols = symbols
for {
p.count++
term.MoveCursor(0, 0)
imap := unwrap(<-responses)
for symIdx, sym := range symbols {
title := imap.Title(sym)
if sym == "0000" {
term.Print(title)
p.countUnchanged++
continue
}
last, lastf, err := imap.Last(sym)
if err != nil {
return errors.Wrap(err, "Parser.Start @ imap.Last")
}
change, changePct := imap.Change(sym)
curColor, titleColor, defaultColor := p.getColors(sym, lastf, imap)
titlePad, lastPad, changePctPad, changePad := 22, 10, 10, 15
ln := fmt.Sprintf("%s%s%s%s%s%s%s%s %s",
toColor(title, titleColor, titleColor),
padding(title, titlePad),
toColor(last, curColor, titleColor),
padding(last, lastPad),
toColor(changePct, defaultColor, titleColor),
padding(changePct, changePctPad),
toColor(change, defaultColor, titleColor),
padding(change, changePad),
imap.Technical(sym, titleColor),
)
if symIdx == 0 {
p.header(titlePad, lastPad, changePctPad, changePad)
}
term.Println(ln)
}
p.status()
p.flush()
}
}
func main() {
fmt.Print("\033[?25l")
defer fmt.Print("\033[?25h")
term.Clear()
responses := make(chan *http.Response, 2)
go fetch(responses, defaultPairsSlice...)
p := newParser()
err := p.Start(responses, defaultPairsSlice...)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}