Codebase list golang-github-vbauerster-mpb / 674c2d9
use rivo/uniseg to replace utf8.RuneCountInString Vladimir Bauer 5 years ago
1 changed file(s) with 7 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
55 "unicode/utf8"
66
77 "github.com/mattn/go-runewidth"
8 "github.com/rivo/uniseg"
89 "github.com/vbauerster/mpb/v6/decor"
910 "github.com/vbauerster/mpb/v6/internal"
1011 )
9293 if !utf8.ValidString(style) {
9394 panic("invalid bar style")
9495 }
95 rcount := utf8.RuneCountInString(style)
96 srcFormat := make([][]byte, rcount)
97 srcRwidth := make([]int, rcount)
98 i := 0
99 for _, r := range style {
100 srcRwidth[i] = runewidth.RuneWidth(r)
101 srcFormat[i] = []byte(string(r))
102 i++
96 srcFormat := make([][]byte, 0, len(BarDefaultStyle))
97 srcRwidth := make([]int, 0, len(BarDefaultStyle))
98 gr := uniseg.NewGraphemes(style)
99 for gr.Next() {
100 srcFormat = append(srcFormat, gr.Bytes())
101 srcRwidth = append(srcRwidth, runewidth.StringWidth(gr.Str()))
103102 }
104103 copy(s.format, srcFormat)
105104 copy(s.rwidth, srcRwidth)