Filler Wrapper interface
Vladimir Bauer
6 years ago
| 28 | 28 |
f(w, width, stat)
|
| 29 | 29 |
}
|
| 30 | 30 |
|
| 31 | |
// BaseFiller interface.
|
| 32 | |
// If you ever need to implement a custom Filler based on mpb.NewBarFiller,
|
| 33 | |
// then you may need to implement this one as well, in order to retain
|
| 34 | |
// functionality of some `BarOption`s and method like *Bar.SetRefill.
|
| 35 | |
type BaseFiller interface {
|
| 36 | |
BaseFiller() Filler
|
|
31 |
// Wrapper interface.
|
|
32 |
// If you're implementing custom Filler by wrapping a built-in one,
|
|
33 |
// it is necessary to implement this interface to retain functionality
|
|
34 |
// of built-in Filler.
|
|
35 |
type Wrapper interface {
|
|
36 |
Base() Filler
|
| 37 | 37 |
}
|
| 38 | 38 |
|
| 39 | 39 |
// Bar represents a progress Bar.
|
| 331 | 331 |
func (s *pState) makeBarState(total int64, filler Filler, options ...BarOption) *bState {
|
| 332 | 332 |
bs := &bState{
|
| 333 | 333 |
total: total,
|
| 334 | |
baseF: filler,
|
|
334 |
baseF: extractBaseFiller(filler),
|
| 335 | 335 |
filler: filler,
|
| 336 | 336 |
priority: s.idCount,
|
| 337 | 337 |
id: s.idCount,
|
|
| 340 | 340 |
extender: func(r io.Reader, _ int, _ *decor.Statistics) (io.Reader, int) {
|
| 341 | 341 |
return r, 0
|
| 342 | 342 |
},
|
| 343 | |
}
|
| 344 | |
|
| 345 | |
if f, ok := filler.(BaseFiller); ok {
|
| 346 | |
bs.baseF = f.BaseFiller()
|
| 347 | 343 |
}
|
| 348 | 344 |
|
| 349 | 345 |
for _, opt := range options {
|
|
| 411 | 407 |
|
| 412 | 408 |
return multiplexedStream
|
| 413 | 409 |
}
|
|
410 |
|
|
411 |
func extractBaseFiller(f Filler) Filler {
|
|
412 |
if f, ok := f.(Wrapper); ok {
|
|
413 |
return extractBaseFiller(f.Base())
|
|
414 |
}
|
|
415 |
return f
|
|
416 |
}
|