| 80 | 80 |
|
| 81 | 81 |
// AddBar creates a new progress bar and adds to the container.
|
| 82 | 82 |
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...)
|
| 93 | 87 |
}
|
| 94 | 88 |
|
| 95 | 89 |
// AddSpinner creates a new spinner bar and adds to the container.
|
| 96 | 90 |
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 {
|
| 111 | 99 |
p.wg.Add(1)
|
| 112 | 100 |
result := make(chan *Bar)
|
| 113 | 101 |
select {
|
| 114 | 102 |
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...)
|
| 116 | 104 |
if b.runningBar != nil {
|
| 117 | 105 |
s.waitBars[b.runningBar] = b
|
| 118 | 106 |
} else {
|