| 38 | 38 |
current int64
|
| 39 | 39 |
refill int64
|
| 40 | 40 |
trimSpace bool
|
| 41 | |
completed bool
|
| 42 | 41 |
aborted bool
|
| 43 | 42 |
triggerComplete bool
|
| 44 | 43 |
rmOnComplete bool
|
|
| 349 | 348 |
func (b *Bar) Abort(drop bool) {
|
| 350 | 349 |
select {
|
| 351 | 350 |
case b.operateState <- func(s *bState) {
|
| 352 | |
if s.completed || s.aborted {
|
|
351 |
if s.aborted || s.completed() {
|
| 353 | 352 |
return
|
| 354 | 353 |
}
|
| 355 | 354 |
s.aborted = true
|
|
| 375 | 374 |
func (b *Bar) Completed() bool {
|
| 376 | 375 |
result := make(chan bool)
|
| 377 | 376 |
select {
|
| 378 | |
case b.operateState <- func(s *bState) { result <- s.completed }:
|
|
377 |
case b.operateState <- func(s *bState) { result <- s.completed() }:
|
| 379 | 378 |
return <-result
|
| 380 | 379 |
case <-b.bsOk:
|
| 381 | |
return b.bs.completed
|
|
380 |
return b.bs.completed()
|
| 382 | 381 |
}
|
| 383 | 382 |
}
|
| 384 | 383 |
|
|
| 403 | 402 |
case op := <-b.operateState:
|
| 404 | 403 |
op(bs)
|
| 405 | 404 |
case <-b.ctx.Done():
|
| 406 | |
bs.aborted = !bs.completed
|
|
405 |
bs.aborted = !bs.completed()
|
| 407 | 406 |
bs.decoratorShutdownNotify(&b.container.bwg)
|
| 408 | 407 |
b.bs = bs
|
| 409 | 408 |
close(b.bsOk)
|
|
| 430 | 429 |
if s.extender != nil {
|
| 431 | 430 |
frame.rows, frame.err = s.extender(frame.rows, stat)
|
| 432 | 431 |
}
|
| 433 | |
if s.completed || s.aborted {
|
|
432 |
if s.aborted || s.completed() {
|
| 434 | 433 |
frame.shutdown = s.shutdown
|
| 435 | 434 |
frame.rmOnComplete = s.rmOnComplete
|
| 436 | 435 |
frame.noPop = s.noPop
|
|
| 552 | 551 |
}
|
| 553 | 552 |
|
| 554 | 553 |
func (s *bState) triggerCompletion(b *Bar) {
|
| 555 | |
s.completed = s.current == s.total
|
|
554 |
s.triggerComplete = true
|
| 556 | 555 |
if s.autoRefresh {
|
| 557 | 556 |
// Technically this call isn't required, but if refresh rate is set to
|
| 558 | 557 |
// one hour for example and bar completes within a few minutes p.Wait()
|
|
| 561 | 560 |
} else {
|
| 562 | 561 |
b.cancel()
|
| 563 | 562 |
}
|
|
563 |
}
|
|
564 |
|
|
565 |
func (s bState) completed() bool {
|
|
566 |
return s.triggerComplete && s.current == s.total
|
| 564 | 567 |
}
|
| 565 | 568 |
|
| 566 | 569 |
func (s bState) decoratorEwmaUpdate(n int64, dur time.Duration, wg *sync.WaitGroup) {
|
|
| 619 | 622 |
Total: s.total,
|
| 620 | 623 |
Current: s.current,
|
| 621 | 624 |
Refill: s.refill,
|
| 622 | |
Completed: s.completed,
|
|
625 |
Completed: s.completed(),
|
| 623 | 626 |
Aborted: s.aborted,
|
| 624 | 627 |
}
|
| 625 | 628 |
}
|