Codebase list golang-github-vbauerster-mpb / eaea603
truncate if space rune is double width Vladimir Bauer 6 years ago
1 changed file(s) with 9 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
4848 }
4949
5050 type space struct {
51 space []byte
52 width int
53 count int
51 space []byte
52 rwidth int
53 count int
5454 }
5555
5656 // NewBarFiller constucts mpb.BarFiller, to be used with *Progress.Add(...) *Bar method.
112112 cwidth := int(internal.PercentageRound(stat.Total, stat.Current, width))
113113 bb := make([][]byte, cwidth)
114114 space := &space{
115 space: s.format[rSpace],
116 width: s.rwidth[rSpace],
117 count: width - cwidth,
115 space: s.format[rSpace],
116 rwidth: s.rwidth[rSpace],
117 count: width - cwidth,
118118 }
119119 if cwidth == 0 {
120120 s.flush(w, space, bb)
152152 index++
153153 }
154154
155 if index != len(bb) {
155 if index != len(bb) || space.rwidth > 1 {
156156 buf := new(bytes.Buffer)
157157 s.flush(buf, space, bb[:index])
158158 io.WriteString(w, runewidth.Truncate(buf.String(), width, "…"))
168168 }
169169 for space.count > 0 {
170170 w.Write(space.space)
171 space.count -= space.width
171 space.count -= space.rwidth
172172 }
173173 }
174174
175175 func reverseFlush(w io.Writer, space *space, bb [][]byte) {
176176 for space.count > 0 {
177177 w.Write(space.space)
178 space.count -= space.width
178 space.count -= space.rwidth
179179 }
180180 for i := 0; i < len(bb); i++ {
181181 w.Write(bb[i])