github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/group_title.go (about) 1 package controldisplay 2 3 import ( 4 "fmt" 5 "log" 6 7 "github.com/turbot/go-kit/helpers" 8 ) 9 10 // There will always be a space after the title, even if the title is empty 11 const minimumGroupTitleWidth = 1 12 13 type GroupTitleRenderer struct { 14 title string 15 width int 16 } 17 18 func NewGroupTitleRenderer(title string, width int) *GroupTitleRenderer { 19 return &GroupTitleRenderer{ 20 title: title, 21 width: width, 22 } 23 } 24 25 // Render returns the title, truncated to the max length if necessary 26 // NOTE: adds a trailing space 27 func (r GroupTitleRenderer) Render() string { 28 if r.width <= 0 { 29 // this should never happen, since the minimum width is set by the formatter 30 log.Printf("[WARN] group renderer has width of %d\n", r.width) 31 return "" 32 } 33 // allow room for trailing space 34 truncatedId := helpers.TruncateString(r.title, r.width-1) 35 str := fmt.Sprintf("%s ", ControlColors.GroupTitle(truncatedId)) 36 return str 37 }