Codebase list golang-github-vbauerster-mpb / 3a9c91e
Filler Wrapper interface Vladimir Bauer 6 years ago
2 changed file(s) with 14 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2828 f(w, width, stat)
2929 }
3030
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
3737 }
3838
3939 // Bar represents a progress Bar.
331331 func (s *pState) makeBarState(total int64, filler Filler, options ...BarOption) *bState {
332332 bs := &bState{
333333 total: total,
334 baseF: filler,
334 baseF: extractBaseFiller(filler),
335335 filler: filler,
336336 priority: s.idCount,
337337 id: s.idCount,
340340 extender: func(r io.Reader, _ int, _ *decor.Statistics) (io.Reader, int) {
341341 return r, 0
342342 },
343 }
344
345 if f, ok := filler.(BaseFiller); ok {
346 bs.baseF = f.BaseFiller()
347343 }
348344
349345 for _, opt := range options {
411407
412408 return multiplexedStream
413409 }
410
411 func extractBaseFiller(f Filler) Filler {
412 if f, ok := f.(Wrapper); ok {
413 return extractBaseFiller(f.Base())
414 }
415 return f
416 }