Codebase list golang-github-vbauerster-mpb / 205274e
fix bug with SetRefill Vladimir Bauer 7 years ago
2 changed file(s) with 11 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
192192 }
193193
194194 // SetRefill sets refill, if supported by underlying Filler.
195 func (b *Bar) SetRefill(upto int) {
195 func (b *Bar) SetRefill(amount int64) {
196196 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)
199199 }
200200 }
201201 }
2020 var defaultBarStyle = "[=>-]<+"
2121
2222 type barFiller struct {
23 format [][]byte
24 refillCount int
25 reverse bool
23 format [][]byte
24 refillAmount int64
25 reverse bool
2626 }
2727
2828 func newDefaultBarFiller() Filler {
4848 s.reverse = true
4949 }
5050
51 func (s *barFiller) SetRefill(count int) {
52 s.refillCount = count
51 func (s *barFiller) SetRefill(amount int64) {
52 s.refillAmount = amount
5353 }
5454
5555 func (s *barFiller) Fill(w io.Writer, width int, stat *decor.Statistics) {
7474 bb[i] = s.format[rFill]
7575 }
7676
77 if s.refillCount > 0 {
77 if s.refillAmount > 0 {
7878 var rwidth int
79 if s.refillCount > cwidth {
79 if s.refillAmount > stat.Current {
8080 rwidth = cwidth
8181 } 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)))
8383 }
8484 for i := 0; i < rwidth; i++ {
8585 bb[i] = s.format[rRefill]