mirror of
https://github.com/minio/minio.git
synced 2024-12-25 22:55:54 -05:00
4ab57f7d60
Some environments might disable access to `/dev/tty`, fall back to '80' in such scenarios. Move to 'cheggaaa/pb' package for better cross platform support on fetching terminal width. Fixes #1891
18 lines
330 B
Go
18 lines
330 B
Go
package pb
|
|
|
|
import (
|
|
"regexp"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
// Finds the control character sequences (like colors)
|
|
var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d")
|
|
|
|
func escapeAwareRuneCountInString(s string) int {
|
|
n := utf8.RuneCountInString(s)
|
|
for _, sm := range ctrlFinder.FindAllString(s, -1) {
|
|
n -= len(sm)
|
|
}
|
|
return n
|
|
}
|