forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_markdown.go
75 lines (54 loc) · 1.34 KB
/
display_markdown.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
72
73
74
75
// Copyright (c) 2019 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"os"
"github.com/olekukonko/tablewriter"
)
type displayMD struct {
writer *tablewriter.Table
}
func NewDisplayMD(file *os.File) DisplayHandler {
md := &displayMD{}
md.writer = tablewriter.NewWriter(file)
md.writer.SetCenterSeparator("|")
md.writer.SetBorders(tablewriter.Border{
Left: true,
Right: true,
Top: false,
Bottom: false,
})
// Critical for GitHub Flavoured Markdown
md.writer.SetAutoWrapText(false)
return md
}
func (d *displayMD) render(headerFields []string, records [][]string) {
d.writer.SetHeader(headerFields)
d.writer.AppendBulk(records)
d.writer.Render()
}
func (d *displayMD) DisplayLabels(lf *LabelsFile) error {
var records [][]string
for _, l := range lf.Labels {
record := labelToRecord(l, true)
records = append(records, record)
}
headerFields := labelHeaderRecord()
d.render(headerFields, records)
return nil
}
func (d *displayMD) DisplayCategories(lf *LabelsFile, showLabels bool) error {
headerFields := categoryHeaderRecord(showLabels)
var records [][]string
for _, c := range lf.Categories {
record, err := categoryToRecord(lf, c, showLabels, true)
if err != nil {
return err
}
records = append(records, record)
}
d.render(headerFields, records)
return nil
}