Codebase list golang-github-vbauerster-mpb / f866536
Remove unnecessary if termWidth > s.Width clause Vladimir Bauer 8 years ago
1 changed file(s) with 11 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
9898 }
9999 }
100100
101 s.bufP = bytes.NewBuffer(make([]byte, 0, s.width/2))
101 s.bufP = bytes.NewBuffer(make([]byte, 0, s.width))
102102 s.bufB = bytes.NewBuffer(make([]byte, 0, s.width))
103 s.bufA = bytes.NewBuffer(make([]byte, 0, s.width/2))
103 s.bufA = bytes.NewBuffer(make([]byte, 0, s.width))
104104
105105 b := &Bar{
106106 priority: id,
324324 stat := newStatistics(s)
325325
326326 // render prepend functions to the left of the bar
327 s.bufP.Reset()
328327 for i, f := range s.pDecorators {
329328 s.bufP.WriteString(f(stat, pSyncer.Accumulator[i], pSyncer.Distributor[i]))
330329 }
334333 }
335334
336335 // render append functions to the right of the bar
337 s.bufA.Reset()
338336 if !s.trimRightSpace {
339337 s.bufA.WriteByte(' ')
340338 }
346344 prependCount := utf8.RuneCount(s.bufP.Bytes())
347345 appendCount := utf8.RuneCount(s.bufA.Bytes())
348346
349 if termWidth > s.width {
350 s.fillBar(s.width)
351 } else {
352 s.fillBar(termWidth - prependCount - appendCount)
353 }
347 s.fillBar(s.width)
354348 barCount := utf8.RuneCount(s.bufB.Bytes())
355349 totalCount := prependCount + barCount + appendCount
356350 if totalCount > termWidth {
357351 s.fillBar(termWidth - prependCount - appendCount)
358352 }
353
359354 s.bufA.WriteByte('\n')
360
361355 return io.MultiReader(s.bufP, s.bufB, s.bufA)
362 }
363
364 func (s *bState) updateTimePerItemEstimate(amount int, now, next time.Time) {
365 lastBlockTime := now.Sub(s.blockStartTime)
366 lastItemEstimate := float64(lastBlockTime) / float64(amount)
367 s.timePerItem = time.Duration((s.etaAlpha * lastItemEstimate) + (1-s.etaAlpha)*float64(s.timePerItem))
368 s.blockStartTime = next
369356 }
370357
371358 func (s *bState) fillBar(width int) {
409396 }
410397
411398 s.bufB.WriteRune(s.format[rRight])
399 }
400
401 func (s *bState) updateTimePerItemEstimate(amount int, now, next time.Time) {
402 lastBlockTime := now.Sub(s.blockStartTime)
403 lastItemEstimate := float64(lastBlockTime) / float64(amount)
404 s.timePerItem = time.Duration((s.etaAlpha * lastItemEstimate) + (1-s.etaAlpha)*float64(s.timePerItem))
405 s.blockStartTime = next
412406 }
413407
414408 func newStatistics(s *bState) *decor.Statistics {