github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/result_reason.go (about) 1 package controldisplay 2 3 import ( 4 "fmt" 5 6 "github.com/turbot/go-kit/helpers" 7 ) 8 9 type ResultReasonRenderer struct { 10 status string 11 reason string 12 width int 13 } 14 15 func NewResultReasonRenderer(status, reason string, width int) *ResultReasonRenderer { 16 return &ResultReasonRenderer{ 17 status: status, 18 reason: reason, 19 width: width, 20 } 21 } 22 23 // Render returns the reason, truncated to the max length if necessary 24 // NOTE: adds a trailing space 25 func (r ResultReasonRenderer) Render() string { 26 // get the color for our status 27 colorFunc, ok := ControlColors.ReasonColors[r.status] 28 if !ok { 29 return "" 30 } 31 // truncate the reason (allow for trailing space) 32 availableWidth := r.width - 1 33 formattedReason := fmt.Sprintf("%s ", colorFunc(helpers.TruncateString(r.reason, availableWidth))) 34 return formattedReason 35 }