MCPcopy Index your code
hub / github.com/box-cli-maker/box-cli-maker / buildTitledBar

Function buildTitledBar

util.go:117–146  ·  view source on GitHub ↗

buildTitledBar builds a top or bottom bar containing a title. It left-aligns the title segment and fills the remaining space on the right with the horizontal glyph. Any leftover width that is not divisible by the glyph's width is emitted as spaces before the emoji sequence so that the last character

(left, fill, right string, leftW, rightW, lineWidth, horizontalWidth int, title string)

Source from the content-addressed store, hash-verified

115// width is emitted as spaces before the emoji sequence so that the last
116// character before the corner is the glyph, not a space.
117func buildTitledBar(left, fill, right string, leftW, rightW, lineWidth, horizontalWidth int, title string) string {
118 if title == "" {
119 return buildPlainBar(left, fill, right, leftW, rightW, lineWidth, horizontalWidth)
120 }
121
122 plainTitle := title
123 if strings.Contains(plainTitle, "\t") {
124 plainTitle = xstrings.ExpandTabs(plainTitle, 4)
125 }
126 titleWidth := runewidth.StringWidth(ansi.Strip(plainTitle))
127 titleSegWidth := titleWidth + 2 // one space padding on each side
128
129 inner := max(lineWidth-leftW-rightW, titleSegWidth)
130 remaining := inner - titleSegWidth
131
132 gapWidth := 0
133 fillWidth := remaining
134 if horizontalWidth > 1 {
135 gapWidth = remaining % horizontalWidth
136 fillWidth = remaining - gapWidth
137 }
138 leftSeg := ""
139 rightSeg := buildSegment(fill, fillWidth, horizontalWidth)
140 gap := ""
141 if gapWidth > 0 {
142 gap = strings.Repeat(" ", gapWidth)
143 }
144
145 return left + leftSeg + " " + plainTitle + " " + gap + rightSeg + right
146}
147
148// formatLine formats the line according to the information passed.
149func (b *Box) formatLine(lines2 []expandedLine, longestLine, titleLen int, sideMargin, title string, texts []string) ([]string, error) {

Callers 2

RenderMethod · 0.85

Calls 2

buildPlainBarFunction · 0.85
buildSegmentFunction · 0.85