MCPcopy Create free account
hub / github.com/diillson/chatcli / wrapLabel

Function wrapLabel

cli/graph_command.go:162–188  ·  view source on GitHub ↗

wrapLabel breaks a label on word boundaries to at most width characters per line and at most three lines (the rest elided), so long fact titles do not blow up a node. Newlines use the DOT label convention.

(s string, width int)

Source from the content-addressed store, hash-verified

160// line and at most three lines (the rest elided), so long fact titles do not
161// blow up a node. Newlines use the DOT label convention.
162func wrapLabel(s string, width int) string {
163 words := strings.Fields(s)
164 if len(words) == 0 {
165 return s
166 }
167 var lines []string
168 cur := ""
169 for _, w := range words {
170 switch {
171 case cur == "":
172 cur = w
173 case len(cur)+1+len(w) > width:
174 lines = append(lines, cur)
175 cur = w
176 default:
177 cur += " " + w
178 }
179 }
180 if cur != "" {
181 lines = append(lines, cur)
182 }
183 if len(lines) > 3 {
184 lines = lines[:3]
185 lines[2] += "…"
186 }
187 return strings.Join(lines, "\n")
188}
189
190// kindColor maps a node kind to a saturated fill that stays legible under white
191// label text.

Callers 1

graphToDOTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected