github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/summary_severity.go (about) 1 package controldisplay 2 3 import ( 4 "github.com/turbot/go-kit/helpers" 5 "github.com/turbot/steampipe/pkg/control/controlexecute" 6 ) 7 8 type SummarySeverityRenderer struct { 9 resultTree *controlexecute.ExecutionTree 10 width int 11 } 12 13 func NewSummarySeverityRenderer(resultTree *controlexecute.ExecutionTree, width int) *SummarySeverityRenderer { 14 return &SummarySeverityRenderer{ 15 resultTree: resultTree, 16 width: width, 17 } 18 } 19 20 func (r *SummarySeverityRenderer) Render() []string { 21 availableWidth := r.width 22 23 // render the critical line 24 criticalSeverityRow := NewSummarySeverityRowRenderer(r.resultTree, availableWidth, "critical").Render() 25 criticalWidth := helpers.PrintableLength(criticalSeverityRow) 26 // if there is a critical line, use this to set the max width 27 if criticalWidth > 0 { 28 availableWidth = criticalWidth 29 } 30 31 // render the high line 32 highSeverityRow := NewSummarySeverityRowRenderer(r.resultTree, availableWidth, "high").Render() 33 highWidth := helpers.PrintableLength(highSeverityRow) 34 35 // build the severity block 36 var strs []string 37 if criticalWidth > 0 { 38 strs = append(strs, criticalSeverityRow) 39 } 40 if highWidth > 0 { 41 strs = append(strs, highSeverityRow) 42 } 43 return strs 44 }