better handling of double width symbols
Vladimir Bauer
4 years ago
| 174 | 174 | var padding [][]byte |
| 175 | 175 | var tip *component |
| 176 | 176 | var filled int |
| 177 | var refWidth int | |
| 177 | 178 | curWidth := int(internal.PercentageRound(stat.Total, stat.Current, uint(width))) |
| 178 | 179 | |
| 179 | 180 | if stat.Current >= stat.Total { |
| 188 | 189 | s.tip.count++ |
| 189 | 190 | } |
| 190 | 191 | |
| 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 | ||
| 199 | 192 | 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 { | |
| 206 | 202 | break |
| 207 | 203 | } |
| 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++ | |
| 210 | 221 | } |
| 211 | 222 | } |
| 212 | 223 | |