File: runecount.go

package info (click to toggle)
golang-gopkg-cheggaaa-pb.v1 1.0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, buster-backports, experimental, sid
  • size: 160 kB
  • sloc: makefile: 2
file content (17 lines) | stat: -rw-r--r-- 364 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
}