refactoring: NewBarFiller and NewBarFillerRev
Vladimir Bauer
5 years ago
| 14 | 14 |
//
|
| 15 | 15 |
// Default implementations can be obtained via:
|
| 16 | 16 |
//
|
| 17 | |
// func NewBarFiller(style string, reverse bool) BarFiller
|
|
17 |
// func NewBarFiller(style string) BarFiller
|
| 18 | 18 |
// func NewSpinnerFiller(style []string, alignment SpinnerAlignment) BarFiller
|
| 19 | 19 |
//
|
| 20 | 20 |
type BarFiller interface {
|
| 53 | 53 |
count int
|
| 54 | 54 |
}
|
| 55 | 55 |
|
| 56 | |
// NewBarFiller constucts mpb.BarFiller, to be used with *Progress.Add(...) *Bar method.
|
| 57 | |
func NewBarFiller(style string, reverse bool) BarFiller {
|
|
56 |
// NewBarFiller returns a BarFiller implementation which renders a
|
|
57 |
// classic progress bar. To be used with *Progress.Add(...) *Bar method.
|
|
58 |
func NewBarFiller(style string) BarFiller {
|
|
59 |
return NewBarFillerRev(style, func() bool { return false })
|
|
60 |
}
|
|
61 |
|
|
62 |
// NewBarFillerRev same as NewBarFiller but with explicit reverse option.
|
|
63 |
func NewBarFillerRev(style string, rev func() bool) BarFiller {
|
| 58 | 64 |
bf := &barFiller{
|
| 59 | 65 |
format: make([][]byte, len(DefaultBarStyle)),
|
| 60 | 66 |
rwidth: make([]int, len(DefaultBarStyle)),
|
| 61 | |
reverse: reverse,
|
|
67 |
reverse: rev(),
|
| 62 | 68 |
}
|
| 63 | 69 |
bf.parse(DefaultBarStyle)
|
| 64 | |
if style != DefaultBarStyle {
|
|
70 |
if style != "" && style != DefaultBarStyle {
|
| 65 | 71 |
bf.parse(style)
|
| 66 | 72 |
}
|
| 67 | 73 |
return bf
|
| 96 | 96 |
|
| 97 | 97 |
// AddBar creates a new progress bar and adds it to the rendering queue.
|
| 98 | 98 |
func (p *Progress) AddBar(total int64, options ...BarOption) *Bar {
|
| 99 | |
return p.Add(total, NewBarFiller(DefaultBarStyle, false), options...)
|
|
99 |
return p.Add(total, NewBarFiller(DefaultBarStyle), options...)
|
| 100 | 100 |
}
|
| 101 | 101 |
|
| 102 | 102 |
// AddSpinner creates a new spinner bar and adds it to the rendering queue.
|