Total from int to int64
Vladimir Bauer
9 years ago
| 41 | 41 |
// Refil is a struct for b.IncrWithReFill
|
| 42 | 42 |
type refill struct {
|
| 43 | 43 |
char rune
|
| 44 | |
till int
|
|
44 |
till int64
|
| 45 | 45 |
}
|
| 46 | 46 |
|
| 47 | 47 |
type (
|
|
| 54 | 54 |
width int
|
| 55 | 55 |
format barFmtRunes
|
| 56 | 56 |
etaAlpha float64
|
| 57 | |
total int
|
| 58 | |
current int
|
|
57 |
total int64
|
|
58 |
current int64
|
| 59 | 59 |
trimLeftSpace bool
|
| 60 | 60 |
trimRightSpace bool
|
| 61 | 61 |
completed bool
|
|
| 71 | 71 |
}
|
| 72 | 72 |
)
|
| 73 | 73 |
|
| 74 | |
func newBar(total int, wg *sync.WaitGroup, cancel <-chan struct{}, options ...BarOption) *Bar {
|
|
74 |
func newBar(total int64, wg *sync.WaitGroup, cancel <-chan struct{}, options ...BarOption) *Bar {
|
| 75 | 75 |
s := state{
|
| 76 | 76 |
total: total,
|
| 77 | 77 |
etaAlpha: etaAlpha,
|
|
| 136 | 136 |
s.startTime = time.Now()
|
| 137 | 137 |
s.blockStartTime = s.startTime
|
| 138 | 138 |
}
|
| 139 | |
sum := s.current + n
|
|
139 |
sum := s.current + int64(n)
|
| 140 | 140 |
s.timeElapsed = time.Since(s.startTime)
|
| 141 | 141 |
s.updateTimePerItemEstimate(n)
|
| 142 | 142 |
if s.total > 0 && sum >= s.total {
|
|
| 154 | 154 |
|
| 155 | 155 |
// ResumeFill fills bar with different r rune,
|
| 156 | 156 |
// from 0 to till amount of progress.
|
| 157 | |
func (b *Bar) ResumeFill(r rune, till int) {
|
|
157 |
func (b *Bar) ResumeFill(r rune, till int64) {
|
| 158 | 158 |
if till < 1 {
|
| 159 | 159 |
return
|
| 160 | 160 |
}
|
|
| 369 | 369 |
return buf
|
| 370 | 370 |
}
|
| 371 | 371 |
|
| 372 | |
func fillBar(total, current, width int, fmtBytes barFmtBytes, rf *refill) []byte {
|
|
372 |
func fillBar(total, current int64, width int, fmtBytes barFmtBytes, rf *refill) []byte {
|
| 373 | 373 |
if width < 2 || total <= 0 {
|
| 374 | 374 |
return []byte{}
|
| 375 | 375 |
}
|
| 29 | 29 |
ID int
|
| 30 | 30 |
Completed bool
|
| 31 | 31 |
Aborted bool
|
| 32 | |
Total int
|
| 33 | |
Current int
|
|
32 |
Total int64
|
|
33 |
Current int64
|
| 34 | 34 |
StartTime time.Time
|
| 35 | 35 |
TimeElapsed time.Duration
|
| 36 | 36 |
TimePerItemEstimate time.Duration
|
|
| 145 | 145 |
}
|
| 146 | 146 |
}
|
| 147 | 147 |
|
| 148 | |
func CalcPercentage(total, current, width int) int {
|
|
148 |
func CalcPercentage(total, current int64, width int) int {
|
| 149 | 149 |
if total == 0 || current > total {
|
| 150 | 150 |
return 0
|
| 151 | 151 |
}
|
| 26 | 26 |
|
| 27 | 27 |
type Units uint
|
| 28 | 28 |
|
| 29 | |
func Format(i int) *formatter {
|
|
29 |
func Format(i int64) *formatter {
|
| 30 | 30 |
return &formatter{n: i}
|
| 31 | 31 |
}
|
| 32 | 32 |
|
| 33 | 33 |
type formatter struct {
|
| 34 | |
n int
|
|
34 |
n int64
|
| 35 | 35 |
unit Units
|
| 36 | 36 |
width int
|
| 37 | 37 |
}
|
|
| 57 | 57 |
}
|
| 58 | 58 |
}
|
| 59 | 59 |
|
| 60 | |
func formatKiB(i int) (result string) {
|
|
60 |
func formatKiB(i int64) (result string) {
|
| 61 | 61 |
switch {
|
| 62 | 62 |
case i >= TiB:
|
| 63 | 63 |
result = fmt.Sprintf("%.1fTiB", float64(i)/TiB)
|
|
| 73 | 73 |
return
|
| 74 | 74 |
}
|
| 75 | 75 |
|
| 76 | |
func formatKB(i int) (result string) {
|
|
76 |
func formatKB(i int64) (result string) {
|
| 77 | 77 |
switch {
|
| 78 | 78 |
case i >= TB:
|
| 79 | 79 |
result = fmt.Sprintf("%.1fTB", float64(i)/TB)
|
| 27 | 27 |
if i != 1 {
|
| 28 | 28 |
name = fmt.Sprintf("Bar#%d:", i)
|
| 29 | 29 |
}
|
| 30 | |
b := p.AddBar(total,
|
|
30 |
b := p.AddBar(int64(total),
|
| 31 | 31 |
mpb.PrependDecorators(
|
| 32 | 32 |
decor.Name(name, 0, decor.DwidthSync|decor.DidentRight),
|
| 33 | 33 |
decor.ETA(4, decor.DSyncSpace),
|
| 82 | 82 |
}
|
| 83 | 83 |
|
| 84 | 84 |
// AddBar creates a new progress bar and adds to the container.
|
| 85 | |
func (p *Progress) AddBar(total int, options ...BarOption) *Bar {
|
|
85 |
func (p *Progress) AddBar(total int64, options ...BarOption) *Bar {
|
| 86 | 86 |
result := make(chan *Bar, 1)
|
| 87 | 87 |
op := func(c *pConf) {
|
| 88 | 88 |
options = append(options, barWidth(c.width), barFormat(c.format))
|