add Refill to decor.Statistics
Vladimir Bauer
6 years ago
| 49 | 49 |
reqWidth int
|
| 50 | 50 |
total int64
|
| 51 | 51 |
current int64
|
|
52 |
refill int64
|
| 52 | 53 |
lastN int64
|
| 53 | 54 |
iterated bool
|
| 54 | 55 |
trimSpace bool
|
|
| 131 | 132 |
// Given default bar style is "[=>-]<+", refill rune is '+'.
|
| 132 | 133 |
// To set bar style use mpb.BarStyle(string) BarOption.
|
| 133 | 134 |
func (b *Bar) SetRefill(amount int64) {
|
| 134 | |
type refiller interface {
|
| 135 | |
SetRefill(int64)
|
| 136 | |
}
|
| 137 | 135 |
b.operateState <- func(s *bState) {
|
| 138 | |
if f, ok := s.baseF.(refiller); ok {
|
| 139 | |
f.SetRefill(amount)
|
| 140 | |
}
|
|
136 |
s.refill = amount
|
| 141 | 137 |
}
|
| 142 | 138 |
}
|
| 143 | 139 |
|
|
| 445 | 441 |
func newStatistics(tw int, s *bState) decor.Statistics {
|
| 446 | 442 |
return decor.Statistics{
|
| 447 | 443 |
ID: s.id,
|
| 448 | |
Completed: s.completeFlushed,
|
|
444 |
AvailableWidth: tw,
|
| 449 | 445 |
Total: s.total,
|
| 450 | 446 |
Current: s.current,
|
| 451 | |
AvailableWidth: tw,
|
|
447 |
Refill: s.refill,
|
|
448 |
Completed: s.completeFlushed,
|
| 452 | 449 |
}
|
| 453 | 450 |
}
|
| 454 | 451 |
|
| 93 | 93 |
s.reverse = reverse
|
| 94 | 94 |
}
|
| 95 | 95 |
|
| 96 | |
func (s *barFiller) SetRefill(amount int64) {
|
| 97 | |
s.refill = amount
|
| 98 | |
}
|
| 99 | |
|
| 100 | 96 |
func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
|
| 101 | 97 |
width := internal.WidthForBarFiller(reqWidth, stat.AvailableWidth)
|
| 102 | 98 |
|
|
| 125 | 121 |
index++
|
| 126 | 122 |
}
|
| 127 | 123 |
|
| 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
|
| 130 | 126 |
if refill > cwidth {
|
| 131 | 127 |
refill = cwidth
|
| 132 | 128 |
}
|
| 47 | 47 |
// may need.
|
| 48 | 48 |
type Statistics struct {
|
| 49 | 49 |
ID int
|
| 50 | |
Completed bool
|
|
50 |
AvailableWidth int
|
| 51 | 51 |
Total int64
|
| 52 | 52 |
Current int64
|
| 53 | |
AvailableWidth int
|
|
53 |
Refill int64
|
|
54 |
Completed bool
|
| 54 | 55 |
}
|
| 55 | 56 |
|
| 56 | 57 |
// Decorator interface.
|