| 16 | 16 |
|
| 17 | 17 |
// Bar represents a progress bar.
|
| 18 | 18 |
type Bar struct {
|
| 19 | |
index int // used by heap
|
| 20 | |
priority int // used by heap
|
| 21 | |
hasEwmaDecorators bool
|
| 22 | |
frameCh chan *frame
|
| 23 | |
operateState chan func(*bState)
|
| 24 | |
done chan struct{}
|
| 25 | |
container *Progress
|
| 26 | |
bs *bState
|
| 27 | |
cancel func()
|
| 28 | |
recoveredPanic interface{}
|
|
19 |
index int // used by heap
|
|
20 |
priority int // used by heap
|
|
21 |
hasEwma bool
|
|
22 |
frameCh chan *frame
|
|
23 |
operateState chan func(*bState)
|
|
24 |
done chan struct{}
|
|
25 |
container *Progress
|
|
26 |
bs *bState
|
|
27 |
cancel func()
|
|
28 |
recoveredPanic interface{}
|
| 29 | 29 |
}
|
| 30 | 30 |
|
| 31 | 31 |
type extenderFunc func(in io.Reader, reqWidth int, st decor.Statistics) (out io.Reader, lines int)
|
|
| 88 | 88 |
|
| 89 | 89 |
bar := &Bar{
|
| 90 | 90 |
priority: bs.priority,
|
|
91 |
hasEwma: len(bs.ewmaDecorators) != 0,
|
| 91 | 92 |
frameCh: make(chan *frame, 1),
|
| 92 | 93 |
operateState: operateState,
|
| 93 | 94 |
done: done,
|
|
| 95 | 96 |
bs: bs,
|
| 96 | 97 |
cancel: cancel,
|
| 97 | 98 |
}
|
| 98 | |
|
| 99 | |
bar.subscribeDecorators(bs)
|
| 100 | 99 |
|
| 101 | 100 |
return bar, serve
|
| 102 | 101 |
}
|
|
| 348 | 347 |
}
|
| 349 | 348 |
}
|
| 350 | 349 |
|
| 351 | |
func (b *Bar) subscribeDecorators(bs *bState) {
|
| 352 | |
for _, decorators := range [...][]decor.Decorator{
|
| 353 | |
bs.pDecorators,
|
| 354 | |
bs.aDecorators,
|
| 355 | |
} {
|
| 356 | |
for _, d := range decorators {
|
| 357 | |
d = extractBaseDecorator(d)
|
| 358 | |
if d, ok := d.(decor.AverageDecorator); ok {
|
| 359 | |
bs.averageDecorators = append(bs.averageDecorators, d)
|
| 360 | |
}
|
| 361 | |
if d, ok := d.(decor.EwmaDecorator); ok {
|
| 362 | |
bs.ewmaDecorators = append(bs.ewmaDecorators, d)
|
| 363 | |
}
|
| 364 | |
if d, ok := d.(decor.ShutdownListener); ok {
|
| 365 | |
bs.shutdownListeners = append(bs.shutdownListeners, d)
|
| 366 | |
}
|
| 367 | |
}
|
| 368 | |
}
|
| 369 | |
}
|
| 370 | |
|
| 371 | 350 |
func (b *Bar) forceRefreshIfLastUncompleted() {
|
| 372 | 351 |
var anyOtherUncompleted bool
|
| 373 | 352 |
b.container.traverseBars(func(bar *Bar) bool {
|
|
| 456 | 435 |
return table
|
| 457 | 436 |
}
|
| 458 | 437 |
|
|
438 |
func (s *bState) subscribeDecorators() {
|
|
439 |
for _, decorators := range [...][]decor.Decorator{
|
|
440 |
s.pDecorators,
|
|
441 |
s.aDecorators,
|
|
442 |
} {
|
|
443 |
for _, d := range decorators {
|
|
444 |
d = extractBaseDecorator(d)
|
|
445 |
if d, ok := d.(decor.AverageDecorator); ok {
|
|
446 |
s.averageDecorators = append(s.averageDecorators, d)
|
|
447 |
}
|
|
448 |
if d, ok := d.(decor.EwmaDecorator); ok {
|
|
449 |
s.ewmaDecorators = append(s.ewmaDecorators, d)
|
|
450 |
}
|
|
451 |
if d, ok := d.(decor.ShutdownListener); ok {
|
|
452 |
s.shutdownListeners = append(s.shutdownListeners, d)
|
|
453 |
}
|
|
454 |
}
|
|
455 |
}
|
|
456 |
}
|
|
457 |
|
| 459 | 458 |
func (s bState) decoratorEwmaUpdate(dur time.Duration) {
|
| 460 | 459 |
wg := new(sync.WaitGroup)
|
| 461 | 460 |
for i := 0; i < len(s.ewmaDecorators); i++ {
|