/
display.go
50 lines (45 loc) · 983 Bytes
/
display.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
package cmd
import (
"fmt"
"github.com/nleeper/goment"
"github.com/olekukonko/tablewriter"
"os"
)
func waitForInput() {
fmt.Println()
var pause string
fmt.Scanln(&pause)
}
func DisplayStats(statsData [][]string) {
table := tablewriter.NewWriter(os.Stdout)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.AppendBulk(statsData)
table.Render()
}
func DisplayTable(g []goment.Goment, desc string, pause bool, highlight int) {
if len(g) == 0 {
if pause {
waitForInput()
}
return
}
var display [][]string
for i, gom := range g {
star := ""
if i == highlight {
star = " * "
}
row := []string{ fmt.Sprintf("%s%d", star, i), gom.Format(dateOutputFmt)}
display = append(display,row)
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Index", fmt.Sprintf("Date - %s", desc)})
table.SetAutoWrapText(false)
table.AppendBulk(display)
fmt.Println()
table.Render()
if pause {
waitForInput()
}
}