-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.go
30 lines (20 loc) · 808 Bytes
/
table.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
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/rodaine/table"
"github.com/root27/go-crypto/CoinAPI"
)
func Table(data []CoinAPI.Coin) {
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
tbl := table.New("Name", "Price $", "Change in 1H", "Last Updated")
tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(color.New(color.FgYellow).SprintfFunc())
for _, coin := range data {
if coin.Quote.USD.PercentChange1H > 0 {
tbl.AddRow(coin.Name, coin.Quote.USD.Price, Colorize(fmt.Sprintf("+%f", coin.Quote.USD.PercentChange1H), ColorGreen), coin.Quote.USD.LastUpdated)
} else {
tbl.AddRow(coin.Name, coin.Quote.USD.Price, Colorize(fmt.Sprintf("%f", coin.Quote.USD.PercentChange1H), ColorRed), coin.Quote.USD.LastUpdated)
}
}
tbl.Print()
}