Render whitespaces.
(width int)
| 28 | |
| 29 | // Render whitespaces. |
| 30 | func (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. |
| 60 | func PlaceOverlay(x, y int, fg, bg string, opts ...WhitespaceOption) string { |