summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2022-11-10 16:23:33 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2022-11-10 16:23:33 +0900
commit8868d7d1883178b5d196fe0d8eaafb22668343ed (patch)
tree14d1badb6050651e28819806bb1d31646b3f24b6 /src/util
parent2eec9892be78bc5fbf8d0cdcd5b90317f426e944 (diff)
Add --separator to customize the info separator
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util.go20
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
+}