MCPcopy
hub / github.com/urfave/cli / wrapLine

Function wrapLine

help.go:562–586  ·  view source on GitHub ↗
(input string, offset int, wrapAt int, padding string)

Source from the content-addressed store, hash-verified

560}
561
562func wrapLine(input string, offset int, wrapAt int, padding string) string {
563 if wrapAt <= offset || len(input) <= wrapAt-offset {
564 return input
565 }
566
567 lineWidth := wrapAt - offset
568 words := strings.Fields(input)
569 if len(words) == 0 {
570 return input
571 }
572
573 wrapped := words[0]
574 spaceLeft := lineWidth - len(wrapped)
575 for _, word := range words[1:] {
576 if len(word)+1 > spaceLeft {
577 wrapped += "\n" + padding + word
578 spaceLeft = lineWidth - len(word)
579 } else {
580 wrapped += " " + word
581 spaceLeft -= 1 + len(word)
582 }
583 }
584
585 return wrapped
586}
587
588func offset(input string, fixed int) int {
589 return len(input) + fixed

Callers 2

wrapFunction · 0.85
TestWrapLineFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestWrapLineFunction · 0.68