forked from tmrts/boilr
/
print.go
39 lines (29 loc) · 787 Bytes
/
print.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
package tabular
import (
"os"
"strings"
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
)
// Print writes the given header and data in a tabular format to stdout.
func Print(header []string, data [][]string) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetCenterSeparator(color.GreenString("+"))
table.SetColumnSeparator(color.GreenString("|"))
table.SetRowSeparator(color.GreenString("-"))
table.SetHeader(header)
for _, datum := range data {
datum[0] = color.RedString(datum[0])
if strings.HasPrefix(datum[1], "local:") {
datum[1] = color.BlueString(datum[1])
} else {
datum[1] = color.YellowString(datum[1])
}
table.Append(datum)
}
if len(data) == 0 {
table.Append([]string{"", "", ""})
}
table.Render()
return nil
}