github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/summary_total_row.go (about)

     1  package controldisplay
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/turbot/go-kit/helpers"
     7  	"github.com/turbot/steampipe/pkg/control/controlexecute"
     8  )
     9  
    10  type SummaryTotalRowRenderer struct {
    11  	resultTree *controlexecute.ExecutionTree
    12  	width      int
    13  }
    14  
    15  func NewSummaryTotalRowRenderer(resultTree *controlexecute.ExecutionTree, width int) *SummaryTotalRowRenderer {
    16  	return &SummaryTotalRowRenderer{
    17  		resultTree: resultTree,
    18  		width:      width,
    19  	}
    20  }
    21  
    22  func (r *SummaryTotalRowRenderer) Render() string {
    23  
    24  	head := fmt.Sprintf("%s ", ControlColors.GroupTitle("TOTAL"))
    25  	count := NewCounterRenderer(
    26  		r.resultTree.Root.Summary.Status.FailedCount(),
    27  		r.resultTree.Root.Summary.Status.TotalCount(),
    28  		r.resultTree.Root.Summary.Status.FailedCount(),
    29  		r.resultTree.Root.Summary.Status.TotalCount(),
    30  		CounterRendererOptions{
    31  			AddLeadingSpace: false,
    32  		},
    33  	).Render()
    34  
    35  	graph := NewCounterGraphRenderer(
    36  		r.resultTree.Root.Summary.Status.FailedCount(),
    37  		r.resultTree.Root.Summary.Status.TotalCount(),
    38  		r.resultTree.Root.Summary.Status.TotalCount(),
    39  		CounterGraphRendererOptions{
    40  			FailedColorFunc: ControlColors.CountGraphFail,
    41  		},
    42  	).Render()
    43  
    44  	spaceWidth := r.width - (helpers.PrintableLength(head) + helpers.PrintableLength(count) + helpers.PrintableLength(graph))
    45  
    46  	spacer := NewSpacerRenderer(spaceWidth)
    47  
    48  	return fmt.Sprintf(
    49  		"%s%s%s%s",
    50  		head,
    51  		spacer.Render(),
    52  		count,
    53  		graph,
    54  	)
    55  }