Remove unnecessary if termWidth > s.Width clause
Vladimir Bauer
8 years ago
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | s.bufP = bytes.NewBuffer(make([]byte, 0, s.width/2)) | |
| 101 | s.bufP = bytes.NewBuffer(make([]byte, 0, s.width)) | |
| 102 | 102 | 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)) | |
| 104 | 104 | |
| 105 | 105 | b := &Bar{ |
| 106 | 106 | priority: id, |
| 324 | 324 | stat := newStatistics(s) |
| 325 | 325 | |
| 326 | 326 | // render prepend functions to the left of the bar |
| 327 | s.bufP.Reset() | |
| 328 | 327 | for i, f := range s.pDecorators { |
| 329 | 328 | s.bufP.WriteString(f(stat, pSyncer.Accumulator[i], pSyncer.Distributor[i])) |
| 330 | 329 | } |
| 334 | 333 | } |
| 335 | 334 | |
| 336 | 335 | // render append functions to the right of the bar |
| 337 | s.bufA.Reset() | |
| 338 | 336 | if !s.trimRightSpace { |
| 339 | 337 | s.bufA.WriteByte(' ') |
| 340 | 338 | } |
| 346 | 344 | prependCount := utf8.RuneCount(s.bufP.Bytes()) |
| 347 | 345 | appendCount := utf8.RuneCount(s.bufA.Bytes()) |
| 348 | 346 | |
| 349 | if termWidth > s.width { | |
| 350 | s.fillBar(s.width) | |
| 351 | } else { | |
| 352 | s.fillBar(termWidth - prependCount - appendCount) | |
| 353 | } | |
| 347 | s.fillBar(s.width) | |
| 354 | 348 | barCount := utf8.RuneCount(s.bufB.Bytes()) |
| 355 | 349 | totalCount := prependCount + barCount + appendCount |
| 356 | 350 | if totalCount > termWidth { |
| 357 | 351 | s.fillBar(termWidth - prependCount - appendCount) |
| 358 | 352 | } |
| 353 | ||
| 359 | 354 | s.bufA.WriteByte('\n') |
| 360 | ||
| 361 | 355 | 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 | |
| 369 | 356 | } |
| 370 | 357 | |
| 371 | 358 | func (s *bState) fillBar(width int) { |
| 409 | 396 | } |
| 410 | 397 | |
| 411 | 398 | 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 | |
| 412 | 406 | } |
| 413 | 407 | |
| 414 | 408 | func newStatistics(s *bState) *decor.Statistics { |