mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 19:39:05 +00:00
18 lines
364 B
Go
18 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
|
||
|
}
|