~pedronis/snappy-hub/assert-fetcher

« back to all changes in this revision

Viewing changes to vendor/github.com/cheggaaa/pb/runecount.go

  • Committer: Samuele Pedroni (Canonical Services Ltd.)
  • Date: 2017-02-10 19:13:46 UTC
  • Revision ID: samuele.pedroni@canonical.com-20170210191346-0vzytr5n503cce3q
initial commit aka 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package pb
 
2
 
 
3
import (
 
4
        "github.com/mattn/go-runewidth"
 
5
        "regexp"
 
6
)
 
7
 
 
8
// Finds the control character sequences (like colors)
 
9
var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d")
 
10
 
 
11
func escapeAwareRuneCountInString(s string) int {
 
12
        n := runewidth.StringWidth(s)
 
13
        for _, sm := range ctrlFinder.FindAllString(s, -1) {
 
14
                n -= len(sm)
 
15
        }
 
16
        return n
 
17
}