Codebase list golang-github-vbauerster-mpb / bbce49c
expose Filler interface Vladimir Bauer 7 years ago
2 changed file(s) with 24 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
3131 shutdown chan struct{}
3232 }
3333
34 type filler interface {
34 type Filler interface {
3535 fill(w io.Writer, width int, s *decor.Statistics)
3636 }
3737
3838 type (
3939 bState struct {
40 filler filler
40 filler Filler
4141 id int
4242 width int
4343 alignment int
7474 }
7575 )
7676
77 func newBar(wg *sync.WaitGroup, id, width int, total int64, cancel <-chan struct{}, options ...BarOption) *Bar {
77 func newBar(
78 wg *sync.WaitGroup,
79 filler Filler,
80 id, width int,
81 total int64,
82 cancel <-chan struct{},
83 options ...BarOption,
84 ) *Bar {
7885 if total <= 0 {
7986 total = time.Now().Unix()
8087 }
8188
8289 s := &bState{
90 filler: filler,
8391 id: id,
8492 priority: id,
8593 width: width,
8080
8181 // AddBar creates a new progress bar and adds to the container.
8282 func (p *Progress) AddBar(total int64, options ...BarOption) *Bar {
83 // make sure filler is initialized first
84 args := []BarOption{
85 func(s *bState) {
86 s.filler = &barFiller{
87 format: defaultBarStyle,
88 }
89 },
90 }
91 args = append(args, options...)
92 return p.add(total, args...)
83 filler := &barFiller{
84 format: defaultBarStyle,
85 }
86 return p.Add(total, filler, options...)
9387 }
9488
9589 // AddSpinner creates a new spinner bar and adds to the container.
9690 func (p *Progress) AddSpinner(total int64, alignment SpinnerAlignment, options ...BarOption) *Bar {
97 // make sure filler is initialized first
98 args := []BarOption{
99 func(s *bState) {
100 s.filler = &spinnerFiller{
101 frames: defaultSpinnerStyle,
102 alignment: alignment,
103 }
104 },
105 }
106 args = append(args, options...)
107 return p.add(total, args...)
108 }
109
110 func (p *Progress) add(total int64, options ...BarOption) *Bar {
91 filler := &spinnerFiller{
92 frames: defaultSpinnerStyle,
93 alignment: alignment,
94 }
95 return p.Add(total, filler, options...)
96 }
97
98 func (p *Progress) Add(total int64, filler Filler, options ...BarOption) *Bar {
11199 p.wg.Add(1)
112100 result := make(chan *Bar)
113101 select {
114102 case p.operateState <- func(s *pState) {
115 b := newBar(p.wg, s.idCounter, s.width, total, s.cancel, options...)
103 b := newBar(p.wg, filler, s.idCounter, s.width, total, s.cancel, options...)
116104 if b.runningBar != nil {
117105 s.waitBars[b.runningBar] = b
118106 } else {