This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathdisplay_text.go
101 lines (85 loc) · 1.73 KB
/
display_text.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2019 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"fmt"
"os"
)
type displayText struct {
file *os.File
}
func NewDisplayText(file *os.File) DisplayHandler {
return &displayText{
file: file,
}
}
func (d *displayText) DisplayLabels(lf *LabelsFile) error {
_, err := fmt.Fprintf(d.file, "Labels (count: %d):\n", len(lf.Labels))
if err != nil {
return err
}
for _, l := range lf.Labels {
err = d.displayLabel(l)
if err != nil {
return err
}
}
return nil
}
func (d *displayText) displayLabel(l Label) error {
_, err := fmt.Fprintf(d.file, " %s (%q) [category %q, colour %q, from %q]\n",
l.Name,
l.Description,
l.CategoryName,
l.Colour,
l.From)
return err
}
func (d *displayText) DisplayCategories(lf *LabelsFile, showLabels bool) error {
_, err := fmt.Fprintf(d.file, "Categories (count: %d):\n", len(lf.Categories))
if err != nil {
return err
}
for _, c := range lf.Categories {
err := d.displayCategory(c, lf, showLabels)
if err != nil {
return err
}
}
return nil
}
func (d *displayText) displayCategory(c Category, lf *LabelsFile, showLabels bool) error {
if showLabels {
labels, err := getLabelsByCategory(c.Name, lf)
if err != nil {
return err
}
_, err = fmt.Fprintf(d.file, " %s (%q, label count: %d, url: %v)\n",
c.Name,
c.Description,
len(labels),
c.URL)
if err != nil {
return err
}
for _, label := range labels {
_, err := fmt.Fprintf(d.file, " %s (%q)\n",
label.Name,
label.Description)
if err != nil {
return err
}
}
} else {
_, err := fmt.Printf(" %s (%q, url: %v)\n",
c.Name,
c.Description,
c.URL)
if err != nil {
return err
}
}
return nil
}