Codebase list golang-github-vbauerster-mpb / daa2bd2
make default Fillers public Vladimir Bauer 6 years ago
3 changed file(s) with 17 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2626 noBrackets bool
2727 }
2828
29 func newDefaultBarFiller() Filler {
30 bf := &barFiller{
29 // NewBarFiller bar Filler used with *Progress.AddBar
30 func NewBarFiller() Filler {
31 filler := &barFiller{
3132 format: make([][]byte, utf8.RuneCountInString(defaultBarStyle)),
3233 }
33 bf.setStyle(defaultBarStyle)
34 return bf
34 filler.setStyle(defaultBarStyle)
35 return filler
3536 }
3637
3738 func (s *barFiller) setStyle(style string) {
9797
9898 // AddBar creates a new progress bar and adds to the container.
9999 func (p *Progress) AddBar(total int64, options ...BarOption) *Bar {
100 return p.Add(total, newDefaultBarFiller(), options...)
100 return p.Add(total, NewBarFiller(), options...)
101101 }
102102
103103 // AddSpinner creates a new spinner bar and adds to the container.
104104 func (p *Progress) AddSpinner(total int64, alignment SpinnerAlignment, options ...BarOption) *Bar {
105 filler := &spinnerFiller{
106 frames: defaultSpinnerStyle,
107 alignment: alignment,
108 }
109 return p.Add(total, filler, options...)
105 return p.Add(total, NewSpinnerFiller(alignment), options...)
110106 }
111107
112108 // Add creates a bar which renders itself by provided filler.
113109 // Set total to 0, if you plan to update it later.
114110 func (p *Progress) Add(total int64, filler Filler, options ...BarOption) *Bar {
115111 if filler == nil {
116 filler = newDefaultBarFiller()
112 filler = NewBarFiller()
117113 }
118114 p.bwg.Add(1)
119115 result := make(chan *Bar)
2525 alignment SpinnerAlignment
2626 }
2727
28 // NewSpinnerFiller spinner Filler used with *Progress.AddSpinner
29 func NewSpinnerFiller(alignment SpinnerAlignment) Filler {
30 filler := &spinnerFiller{
31 frames: defaultSpinnerStyle,
32 alignment: alignment,
33 }
34 return filler
35 }
36
2837 func (s *spinnerFiller) Fill(w io.Writer, width int, stat *decor.Statistics) {
2938
3039 frame := s.frames[s.count%uint(len(s.frames))]