MCPcopy Create free account
hub / github.com/box-cli-maker/box-cli-maker / charWidth

Function charWidth

util.go:81–87  ·  view source on GitHub ↗

charWidth returns the visible width of a string, treating zero-width results as width 1 so that box calculations always make progress.

(s string)

Source from the content-addressed store, hash-verified

79// charWidth returns the visible width of a string, treating zero-width
80// results as width 1 so that box calculations always make progress.
81func charWidth(s string) int {
82 w := runewidth.StringWidth(ansi.Strip(s))
83 if w == 0 {
84 w = 1
85 }
86 return w
87}
88
89// buildSegment builds a horizontal segment with the given visual width using
90// the provided fill glyph, padding with spaces if needed to match width.

Callers 2

TestCharWidthFunction · 0.85
RenderMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestCharWidthFunction · 0.68