Codebase list golang-github-vbauerster-mpb / aa91ade
bar filler: calc filled one time Vladimir Bauer 5 years ago
1 changed file(s) with 5 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
152152 w.Write(s.components[iLbound].bytes)
153153 defer w.Write(s.components[iRbound].bytes)
154154
155 refWidth, filled := 0, 0
156155 curWidth := int(internal.PercentageRound(stat.Total, stat.Current, width))
156 refWidth, filled := 0, curWidth
157157 filling := make([][]byte, 0, curWidth)
158158
159159 if curWidth > 0 && curWidth != width {
160160 tipFrame := s.tip.frames[s.tip.count%uint(len(s.tip.frames))]
161161 filling = append(filling, tipFrame.bytes)
162 filled += tipFrame.width
163162 curWidth -= tipFrame.width
164163 s.tip.count++
165164 }
166165
167 if stat.Refill > 0 {
166 if stat.Refill > 0 && curWidth > 0 {
168167 refWidth = int(internal.PercentageRound(stat.Total, int64(stat.Refill), width))
169168 if refWidth > curWidth {
170169 refWidth = curWidth
174173
175174 for curWidth > 0 && curWidth >= s.components[iFiller].width {
176175 filling = append(filling, s.components[iFiller].bytes)
177 filled += s.components[iFiller].width
178176 curWidth -= s.components[iFiller].width
179177 if s.components[iFiller].width == 0 {
180178 break
183181
184182 for refWidth > 0 && refWidth >= s.components[iRefiller].width {
185183 filling = append(filling, s.components[iRefiller].bytes)
186 filled += s.components[iRefiller].width
187184 refWidth -= s.components[iRefiller].width
188185 if s.components[iRefiller].width == 0 {
189186 break
190187 }
191188 }
192189
190 filled -= curWidth + refWidth
193191 padWidth := width - filled
194192 padding := make([][]byte, 0, padWidth)
195193 for padWidth > 0 && padWidth >= s.components[iPadding].width {
196194 padding = append(padding, s.components[iPadding].bytes)
197 filled += s.components[iPadding].width
198195 padWidth -= s.components[iPadding].width
199196 if s.components[iPadding].width == 0 {
200197 break
201198 }
202199 }
203200
204 truncWidth := width - filled
205 for truncWidth > 0 {
201 for padWidth > 0 {
206202 padding = append(padding, []byte("…"))
207 truncWidth--
203 padWidth--
208204 }
209205
210206 s.flush(w, filling, padding)