-
Notifications
You must be signed in to change notification settings - Fork 262
/
summary_total_row.go
55 lines (45 loc) · 1.35 KB
/
summary_total_row.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
package controldisplay
import (
"fmt"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/steampipe/pkg/control/controlexecute"
)
type SummaryTotalRowRenderer struct {
resultTree *controlexecute.ExecutionTree
width int
}
func NewSummaryTotalRowRenderer(resultTree *controlexecute.ExecutionTree, width int) *SummaryTotalRowRenderer {
return &SummaryTotalRowRenderer{
resultTree: resultTree,
width: width,
}
}
func (r *SummaryTotalRowRenderer) Render() string {
head := fmt.Sprintf("%s ", ControlColors.GroupTitle("TOTAL"))
count := NewCounterRenderer(
r.resultTree.Root.Summary.Status.FailedCount(),
r.resultTree.Root.Summary.Status.TotalCount(),
r.resultTree.Root.Summary.Status.FailedCount(),
r.resultTree.Root.Summary.Status.TotalCount(),
CounterRendererOptions{
AddLeadingSpace: false,
},
).Render()
graph := NewCounterGraphRenderer(
r.resultTree.Root.Summary.Status.FailedCount(),
r.resultTree.Root.Summary.Status.TotalCount(),
r.resultTree.Root.Summary.Status.TotalCount(),
CounterGraphRendererOptions{
FailedColorFunc: ControlColors.CountGraphFail,
},
).Render()
spaceWidth := r.width - (helpers.PrintableLength(head) + helpers.PrintableLength(count) + helpers.PrintableLength(graph))
spacer := NewSpacerRenderer(spaceWidth)
return fmt.Sprintf(
"%s%s%s%s",
head,
spacer.Render(),
count,
graph,
)
}