limit gr.Next iteration by len of BarDefaultStyle
Vladimir Bauer
5 years ago
| 93 | 93 | if !utf8.ValidString(style) { |
| 94 | 94 | panic("invalid bar style") |
| 95 | 95 | } |
| 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())) | |
| 96 | srcFormat := make([][]byte, len(BarDefaultStyle)) | |
| 97 | srcRwidth := make([]int, len(BarDefaultStyle)) | |
| 98 | i := 0 | |
| 99 | for gr := uniseg.NewGraphemes(style); i < len(BarDefaultStyle) && gr.Next(); i++ { | |
| 100 | srcFormat[i] = gr.Bytes() | |
| 101 | srcRwidth[i] = runewidth.StringWidth(gr.Str()) | |
| 102 | 102 | } |
| 103 | copy(s.format, srcFormat) | |
| 104 | copy(s.rwidth, srcRwidth) | |
| 103 | copy(s.format, srcFormat[:i]) | |
| 104 | copy(s.rwidth, srcRwidth[:i]) | |
| 105 | 105 | if s.reverse { |
| 106 | 106 | s.tip = s.format[rRevTip] |
| 107 | 107 | s.flush = reverseFlush |