-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
71 lines (63 loc) · 1.18 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
package main
import (
"encoding/csv"
"fmt"
"github.com/logrusorgru/aurora"
"io"
"os"
)
// DELIMITER holds a string to delimition.
const DELIMITER = " "
func main() {
fp := readStdin()
reader := csv.NewReader(fp)
reader.Comma = ','
reader.LazyQuotes = true
for {
record, err := reader.Read()
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
for i, col := range record {
rotateColor(i, col)
}
fmt.Println()
}
}
// rotateColor exports the colored columns with circuration.
func rotateColor(i int, col interface{}) {
switch i % 7 {
case 0:
fmt.Print(aurora.Magenta(col), DELIMITER)
case 1:
fmt.Print(aurora.Blue(col), DELIMITER)
case 2:
fmt.Print(aurora.Brown(col), DELIMITER)
case 3:
fmt.Print(aurora.Green(col), DELIMITER)
case 4:
fmt.Print(aurora.White(col), DELIMITER)
case 5:
fmt.Print(aurora.Cyan(col), DELIMITER)
case 6:
fmt.Print(aurora.Red(col), DELIMITER)
}
return
}
// readStdin returns the CSV from stdin.
func readStdin() *os.File {
var fp *os.File
if len(os.Args) < 2 {
fp = os.Stdin
} else {
var err error
fp, err = os.Open(os.Args[1])
if err != nil {
panic(err)
}
defer fp.Close()
}
return fp
}