diff options
Diffstat (limited to 'src/util/util.go')
| -rw-r--r-- | src/util/util.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/util.go b/src/util/util.go index a1c37f7a..cb211cbb 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -153,3 +153,23 @@ func Once(nextResponse bool) func() bool { return prevState } } + +// RepeatToFill repeats the given string to fill the given width +func RepeatToFill(str string, length int, limit int) string { + times := limit / length + rest := limit % length + output := strings.Repeat(str, times) + if rest > 0 { + for _, r := range str { + rest -= runewidth.RuneWidth(r) + if rest < 0 { + break + } + output += string(r) + if rest == 0 { + break + } + } + } + return output +} |
