make sure BarStyle, BarReverse doesn't depend on order if BarFillerMiddleware used
Vladimir Bauer
6 years ago
| 43 | 43 |
type extFunc func(in io.Reader, reqWidth int, st decor.Statistics) (out io.Reader, lines int)
|
| 44 | 44 |
|
| 45 | 45 |
type bState struct {
|
| 46 | |
filler BarFiller
|
| 47 | 46 |
id int
|
|
47 |
priority int
|
| 48 | 48 |
reqWidth int
|
| 49 | 49 |
total int64
|
| 50 | 50 |
current int64
|
|
| 55 | 55 |
toComplete bool
|
| 56 | 56 |
completeFlushed bool
|
| 57 | 57 |
ignoreComplete bool
|
|
58 |
dropOnComplete bool
|
| 58 | 59 |
noPop bool
|
| 59 | 60 |
aDecorators []decor.Decorator
|
| 60 | 61 |
pDecorators []decor.Decorator
|
|
| 62 | 63 |
ewmaDecorators []decor.EwmaDecorator
|
| 63 | 64 |
shutdownListeners []decor.ShutdownListener
|
| 64 | 65 |
bufP, bufB, bufA *bytes.Buffer
|
|
66 |
filler BarFiller
|
|
67 |
middleware func(BarFiller) BarFiller
|
| 65 | 68 |
extender extFunc
|
| 66 | 69 |
|
| 67 | |
// priority overrides *Bar's priority, if set
|
| 68 | |
priority int
|
| 69 | |
// dropOnComplete propagates to *Bar
|
| 70 | |
dropOnComplete bool
|
| 71 | 70 |
// runningBar is a key for *pState.parkedBars
|
| 72 | 71 |
runningBar *Bar
|
| 73 | 72 |
|
| 90 | 90 |
// BarFillerMiddleware provides a way to augment default BarFiller.
|
| 91 | 91 |
func BarFillerMiddleware(middle func(BarFiller) BarFiller) BarOption {
|
| 92 | 92 |
return func(s *bState) {
|
| 93 | |
s.filler = middle(s.filler)
|
|
93 |
s.middleware = middle
|
| 94 | 94 |
}
|
| 95 | 95 |
}
|
| 96 | 96 |
|
| 338 | 338 |
|
| 339 | 339 |
func (s *pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState {
|
| 340 | 340 |
bs := &bState{
|
|
341 |
id: s.idCount,
|
|
342 |
priority: s.idCount,
|
|
343 |
reqWidth: s.reqWidth,
|
| 341 | 344 |
total: total,
|
| 342 | 345 |
filler: filler,
|
| 343 | |
priority: s.idCount,
|
| 344 | |
id: s.idCount,
|
| 345 | |
reqWidth: s.reqWidth,
|
|
346 |
extender: func(r io.Reader, _ int, _ decor.Statistics) (io.Reader, int) { return r, 0 },
|
| 346 | 347 |
debugOut: s.debugOut,
|
| 347 | |
extender: func(r io.Reader, _ int, _ decor.Statistics) (io.Reader, int) {
|
| 348 | |
return r, 0
|
| 349 | |
},
|
| 350 | 348 |
}
|
| 351 | 349 |
|
| 352 | 350 |
for _, opt := range options {
|
| 353 | 351 |
if opt != nil {
|
| 354 | 352 |
opt(bs)
|
| 355 | 353 |
}
|
|
354 |
}
|
|
355 |
|
|
356 |
if bs.middleware != nil {
|
|
357 |
bs.filler = bs.middleware(filler)
|
| 356 | 358 |
}
|
| 357 | 359 |
|
| 358 | 360 |
if s.popCompleted && !bs.noPop {
|