1
0
Fork 0
mirror of https://github.com/Luzifer/share.git synced 2024-10-18 13:24:23 +00:00
share/vendor/github.com/cheggaaa/pb/runecount.go
Knut Ahlers 8af31b8e6b
Add progress output to CLI upload
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-10-11 20:15:12 +02:00

17 lines
364 B
Go

package pb
import (
"github.com/mattn/go-runewidth"
"regexp"
)
// Finds the control character sequences (like colors)
var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d")
func escapeAwareRuneCountInString(s string) int {
n := runewidth.StringWidth(s)
for _, sm := range ctrlFinder.FindAllString(s, -1) {
n -= runewidth.StringWidth(sm)
}
return n
}