MCPcopy
hub / github.com/yorukot/superfile / render

Method render

src/pkg/string_function/overplace.go:30–57  ·  view source on GitHub ↗

Render whitespaces.

(width int)

Source from the content-addressed store, hash-verified

28
29// Render whitespaces.
30func (w whitespace) render(width int) string {
31 if w.chars == "" {
32 w.chars = " "
33 }
34
35 r := []rune(w.chars)
36 j := 0
37 b := strings.Builder{}
38
39 // Cycle through runes and print them into the whitespace.
40 for i := 0; i < width; {
41 b.WriteRune(r[j])
42 j++
43 if j >= len(r) {
44 j = 0
45 }
46 i += charmansi.StringWidth(string(r[j]))
47 }
48
49 // Fill any extra gaps white spaces. This might be necessary if any runes
50 // are more than one cell wide, which could leave a one-rune gap.
51 short := width - charmansi.StringWidth(b.String())
52 if short > 0 {
53 b.WriteString(strings.Repeat(" ", short))
54 }
55
56 return w.style.Styled(b.String())
57}
58
59// PlaceOverlay places fg on top of bg.
60func PlaceOverlay(x, y int, fg, bg string, opts ...WhitespaceOption) string {

Callers 1

PlaceOverlayFunction · 0.95

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected