disableAutoRefresh
Vladimir Bauer
3 years ago
| 41 | 41 |
func WithManualRefresh(ch <-chan interface{}) ContainerOption {
|
| 42 | 42 |
return func(s *pState) {
|
| 43 | 43 |
s.externalRefresh = ch
|
|
44 |
s.disableAutoRefresh = true
|
| 44 | 45 |
}
|
| 45 | 46 |
}
|
| 46 | 47 |
|
| 29 | 29 |
operateState chan func(*pState)
|
| 30 | 30 |
interceptIo chan func(io.Writer)
|
| 31 | 31 |
done chan struct{}
|
| 32 | |
refreshCh chan time.Time
|
| 33 | 32 |
once sync.Once
|
| 34 | 33 |
cancel func()
|
| 35 | 34 |
}
|
|
| 46 | 45 |
pool []*Bar
|
| 47 | 46 |
|
| 48 | 47 |
// following are provided/overrided by user
|
| 49 | |
idCount int
|
| 50 | |
reqWidth int
|
| 51 | |
popPriority int
|
| 52 | |
popCompleted bool
|
| 53 | |
outputDiscarded bool
|
| 54 | |
rr time.Duration
|
| 55 | |
uwg *sync.WaitGroup
|
| 56 | |
externalRefresh <-chan interface{}
|
| 57 | |
renderDelay <-chan struct{}
|
| 58 | |
shutdownNotifier chan struct{}
|
| 59 | |
queueBars map[*Bar]*Bar
|
| 60 | |
output io.Writer
|
| 61 | |
debugOut io.Writer
|
|
48 |
idCount int
|
|
49 |
reqWidth int
|
|
50 |
popPriority int
|
|
51 |
popCompleted bool
|
|
52 |
outputDiscarded bool
|
|
53 |
disableAutoRefresh bool
|
|
54 |
rr time.Duration
|
|
55 |
uwg *sync.WaitGroup
|
|
56 |
externalRefresh <-chan interface{}
|
|
57 |
renderDelay <-chan struct{}
|
|
58 |
shutdownNotifier chan struct{}
|
|
59 |
queueBars map[*Bar]*Bar
|
|
60 |
output io.Writer
|
|
61 |
debugOut io.Writer
|
| 62 | 62 |
}
|
| 63 | 63 |
|
| 64 | 64 |
// New creates new Progress container instance. It's not possible to
|
|
| 374 | 374 |
s.shutdownNotifier = make(chan struct{})
|
| 375 | 375 |
}
|
| 376 | 376 |
go func() {
|
| 377 | |
if s.renderDelay != nil {
|
| 378 | |
<-s.renderDelay
|
| 379 | |
}
|
| 380 | |
var internalRefresh <-chan time.Time
|
| 381 | |
if !s.outputDiscarded {
|
| 382 | |
if s.externalRefresh == nil {
|
|
377 |
var autoRefresh <-chan time.Time
|
|
378 |
if !s.disableAutoRefresh {
|
|
379 |
if !s.outputDiscarded {
|
|
380 |
if s.renderDelay != nil {
|
|
381 |
<-s.renderDelay
|
|
382 |
}
|
| 383 | 383 |
ticker := time.NewTicker(s.rr)
|
| 384 | 384 |
defer ticker.Stop()
|
| 385 | |
internalRefresh = ticker.C
|
| 386 | |
}
|
| 387 | |
} else {
|
| 388 | |
s.externalRefresh = nil
|
|
385 |
autoRefresh = ticker.C
|
|
386 |
}
|
| 389 | 387 |
}
|
| 390 | 388 |
for {
|
| 391 | 389 |
select {
|
| 392 | |
case t := <-internalRefresh:
|
|
390 |
case t := <-autoRefresh:
|
| 393 | 391 |
ch <- t
|
| 394 | 392 |
case x := <-s.externalRefresh:
|
| 395 | 393 |
if t, ok := x.(time.Time); ok {
|