Add --separator to customize the info separator

This commit is contained in:
Junegunn Choi
2022-11-10 16:23:33 +09:00
parent 2eec9892be
commit 8868d7d188
6 changed files with 164 additions and 63 deletions

View File

@@ -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
}