Codebase list golang-github-vbauerster-mpb / 6cdbbd7
better handling of double width symbols Vladimir Bauer 4 years ago
1 changed file(s) with 27 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
174174 var padding [][]byte
175175 var tip *component
176176 var filled int
177 var refWidth int
177178 curWidth := int(internal.PercentageRound(stat.Total, stat.Current, uint(width)))
178179
179180 if stat.Current >= stat.Total {
188189 s.tip.count++
189190 }
190191
191 for filled < curWidth && curWidth-filled >= s.components[iFiller].width {
192 filling = append(filling, s.components[iFiller].bytes)
193 if s.components[iFiller].width == 0 {
194 break
195 }
196 filled += s.components[iFiller].width
197 }
198
199192 if stat.Refill > 0 {
200 refWidth := int(internal.PercentageRound(stat.Total, stat.Refill, uint(width)))
201 if refWidth == curWidth {
202 refWidth -= tip.width
203 }
204 for i := len(filling) - 1; i >= 0; i-- {
205 if refWidth < s.components[iRefiller].width {
193 refWidth = int(internal.PercentageRound(stat.Total, stat.Refill, uint(width)))
194 curWidth -= refWidth
195 refWidth += curWidth
196 }
197
198 for filled < curWidth {
199 if curWidth-filled >= s.components[iFiller].width {
200 filling = append(filling, s.components[iFiller].bytes)
201 if s.components[iFiller].width == 0 {
206202 break
207203 }
208 filling[i] = s.components[iRefiller].bytes
209 refWidth -= s.components[iRefiller].width
204 filled += s.components[iFiller].width
205 } else {
206 filling = append(filling, []byte("…"))
207 filled++
208 }
209 }
210
211 for filled < refWidth {
212 if refWidth-filled >= s.components[iRefiller].width {
213 filling = append(filling, s.components[iRefiller].bytes)
214 if s.components[iRefiller].width == 0 {
215 break
216 }
217 filled += s.components[iRefiller].width
218 } else {
219 filling = append(filling, []byte("…"))
220 filled++
210221 }
211222 }
212223