fix bug with SetRefill
Vladimir Bauer
7 years ago
| 192 | 192 |
}
|
| 193 | 193 |
|
| 194 | 194 |
// SetRefill sets refill, if supported by underlying Filler.
|
| 195 | |
func (b *Bar) SetRefill(upto int) {
|
|
195 |
func (b *Bar) SetRefill(amount int64) {
|
| 196 | 196 |
b.operateState <- func(s *bState) {
|
| 197 | |
if f, ok := s.filler.(interface{ SetRefill(int) }); ok {
|
| 198 | |
f.SetRefill(upto)
|
|
197 |
if f, ok := s.filler.(interface{ SetRefill(int64) }); ok {
|
|
198 |
f.SetRefill(amount)
|
| 199 | 199 |
}
|
| 200 | 200 |
}
|
| 201 | 201 |
}
|
| 20 | 20 |
var defaultBarStyle = "[=>-]<+"
|
| 21 | 21 |
|
| 22 | 22 |
type barFiller struct {
|
| 23 | |
format [][]byte
|
| 24 | |
refillCount int
|
| 25 | |
reverse bool
|
|
23 |
format [][]byte
|
|
24 |
refillAmount int64
|
|
25 |
reverse bool
|
| 26 | 26 |
}
|
| 27 | 27 |
|
| 28 | 28 |
func newDefaultBarFiller() Filler {
|
|
| 48 | 48 |
s.reverse = true
|
| 49 | 49 |
}
|
| 50 | 50 |
|
| 51 | |
func (s *barFiller) SetRefill(count int) {
|
| 52 | |
s.refillCount = count
|
|
51 |
func (s *barFiller) SetRefill(amount int64) {
|
|
52 |
s.refillAmount = amount
|
| 53 | 53 |
}
|
| 54 | 54 |
|
| 55 | 55 |
func (s *barFiller) Fill(w io.Writer, width int, stat *decor.Statistics) {
|
|
| 74 | 74 |
bb[i] = s.format[rFill]
|
| 75 | 75 |
}
|
| 76 | 76 |
|
| 77 | |
if s.refillCount > 0 {
|
|
77 |
if s.refillAmount > 0 {
|
| 78 | 78 |
var rwidth int
|
| 79 | |
if s.refillCount > cwidth {
|
|
79 |
if s.refillAmount > stat.Current {
|
| 80 | 80 |
rwidth = cwidth
|
| 81 | 81 |
} else {
|
| 82 | |
rwidth = int(internal.Percentage(stat.Total, int64(s.refillCount), int64(width)))
|
|
82 |
rwidth = int(internal.Percentage(stat.Total, int64(s.refillAmount), int64(width)))
|
| 83 | 83 |
}
|
| 84 | 84 |
for i := 0; i < rwidth; i++ {
|
| 85 | 85 |
bb[i] = s.format[rRefill]
|