Codebase list golang-github-vbauerster-mpb / 2f368a5
add Refill to decor.Statistics Vladimir Bauer 6 years ago
3 changed file(s) with 10 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
4949 reqWidth int
5050 total int64
5151 current int64
52 refill int64
5253 lastN int64
5354 iterated bool
5455 trimSpace bool
131132 // Given default bar style is "[=>-]<+", refill rune is '+'.
132133 // To set bar style use mpb.BarStyle(string) BarOption.
133134 func (b *Bar) SetRefill(amount int64) {
134 type refiller interface {
135 SetRefill(int64)
136 }
137135 b.operateState <- func(s *bState) {
138 if f, ok := s.baseF.(refiller); ok {
139 f.SetRefill(amount)
140 }
136 s.refill = amount
141137 }
142138 }
143139
445441 func newStatistics(tw int, s *bState) decor.Statistics {
446442 return decor.Statistics{
447443 ID: s.id,
448 Completed: s.completeFlushed,
444 AvailableWidth: tw,
449445 Total: s.total,
450446 Current: s.current,
451 AvailableWidth: tw,
447 Refill: s.refill,
448 Completed: s.completeFlushed,
452449 }
453450 }
454451
9393 s.reverse = reverse
9494 }
9595
96 func (s *barFiller) SetRefill(amount int64) {
97 s.refill = amount
98 }
99
10096 func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
10197 width := internal.WidthForBarFiller(reqWidth, stat.AvailableWidth)
10298
125121 index++
126122 }
127123
128 if s.refill > 0 {
129 refill = int(internal.PercentageRound(stat.Total, int64(s.refill), width)) - index
124 if stat.Refill > 0 {
125 refill = int(internal.PercentageRound(stat.Total, int64(stat.Refill), width)) - index
130126 if refill > cwidth {
131127 refill = cwidth
132128 }
4747 // may need.
4848 type Statistics struct {
4949 ID int
50 Completed bool
50 AvailableWidth int
5151 Total int64
5252 Current int64
53 AvailableWidth int
53 Refill int64
54 Completed bool
5455 }
5556
5657 // Decorator interface.