-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
output_tablewriter.go
45 lines (38 loc) · 978 Bytes
/
output_tablewriter.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
package trdsql
import (
"github.com/olekukonko/tablewriter"
)
// TwOut is tablewriter struct
type TwOut struct {
writer *tablewriter.Table
results []string
}
func (trdsql *TRDSQL) twOutNew(markdown bool) *TwOut {
tw := &TwOut{}
tw.writer = tablewriter.NewWriter(trdsql.OutStream)
tw.writer.SetAutoFormatHeaders(false)
if markdown {
tw.writer.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
tw.writer.SetCenterSeparator("|")
}
return tw
}
// First is preparation
func (tw *TwOut) First(columns []string, types []string) error {
tw.writer.SetHeader(columns)
tw.results = make([]string, len(columns))
return nil
}
// WriteRow is Addition to array
func (tw *TwOut) WriteRow(values []interface{}, columns []string) error {
for i, col := range values {
tw.results[i] = valString(col)
}
tw.writer.Append(tw.results)
return nil
}
// Last is Actual output
func (tw *TwOut) Last() error {
tw.writer.Render()
return nil
}