github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/result_status.go (about) 1 package controldisplay 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type ResultStatusRenderer struct { 9 status string 10 } 11 12 func NewResultStatusRenderer(status string) *ResultStatusRenderer { 13 return &ResultStatusRenderer{ 14 status: status, 15 } 16 } 17 18 // Render returns the status 19 func (r ResultStatusRenderer) Render() string { 20 // pad status string to fixed width 21 statusString := r.paddedStatusString() 22 23 // get the color for our status 24 colorFunc, ok := ControlColors.StatusColors[r.status] 25 26 if !ok { 27 // for unrecognised status, just return nothing - we should be validating elsewhere 28 return "" 29 } 30 // return status follow by colon and trailing space 31 return fmt.Sprintf("%-5s%s ", colorFunc(statusString), ControlColors.StatusColon(":")) 32 } 33 34 // pad out status toi length of longest status string = "ERROR" - 5 chars 35 func (r ResultStatusRenderer) paddedStatusString() string { 36 return fmt.Sprintf("%-5s", strings.ToUpper(r.status)) 37 }