Updated vendor package github.com/cheggaaa/pb to v1.0.25.
This commit is contained in:
parent
0f10032b3d
commit
dc2088318e
|
@ -173,7 +173,7 @@ The result will be as follows:
|
|||
|
||||
```
|
||||
$ go run example/multiple.go
|
||||
First 141 / 1000 [===============>---------------------------------------] 14.10 % 44s
|
||||
Second 139 / 1000 [==============>---------------------------------------] 13.90 % 44s
|
||||
Third 152 / 1000 [================>--------------------------------------] 15.20 % 40s
|
||||
First 34 / 200 [=========>---------------------------------------------] 17.00% 00m08s
|
||||
Second 42 / 200 [===========>------------------------------------------] 21.00% 00m06s
|
||||
Third 36 / 200 [=========>---------------------------------------------] 18.00% 00m08s
|
||||
```
|
||||
|
|
|
@ -113,6 +113,13 @@ func formatDuration(n int64) (result string) {
|
|||
result = fmt.Sprintf("%dd", d/24/time.Hour)
|
||||
d -= (d / time.Hour / 24) * (time.Hour * 24)
|
||||
}
|
||||
result = fmt.Sprintf("%s%v", result, d)
|
||||
if d > time.Hour {
|
||||
result = fmt.Sprintf("%s%dh", result, d/time.Hour)
|
||||
d -= d / time.Hour * time.Hour
|
||||
}
|
||||
m := d / time.Minute
|
||||
d -= m * time.Minute
|
||||
s := d / time.Second
|
||||
result = fmt.Sprintf("%s%02dm%02ds", result, m, s)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
// Current version
|
||||
const Version = "1.0.22"
|
||||
const Version = "1.0.25"
|
||||
|
||||
const (
|
||||
// Default refresh rate - 200ms
|
||||
|
@ -114,7 +114,7 @@ type ProgressBar struct {
|
|||
func (pb *ProgressBar) Start() *ProgressBar {
|
||||
pb.startTime = time.Now()
|
||||
pb.startValue = atomic.LoadInt64(&pb.current)
|
||||
if pb.Total == 0 {
|
||||
if atomic.LoadInt64(&pb.Total) == 0 {
|
||||
pb.ShowTimeLeft = false
|
||||
pb.ShowPercent = false
|
||||
pb.AutoStat = false
|
||||
|
@ -222,7 +222,7 @@ func (pb *ProgressBar) Finish() {
|
|||
//Protect multiple calls
|
||||
pb.finishOnce.Do(func() {
|
||||
close(pb.finish)
|
||||
pb.write(atomic.LoadInt64(&pb.current))
|
||||
pb.write(atomic.LoadInt64(&pb.Total), atomic.LoadInt64(&pb.current))
|
||||
pb.mu.Lock()
|
||||
defer pb.mu.Unlock()
|
||||
switch {
|
||||
|
@ -272,7 +272,7 @@ func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader {
|
|||
return &Reader{r, pb}
|
||||
}
|
||||
|
||||
func (pb *ProgressBar) write(current int64) {
|
||||
func (pb *ProgressBar) write(total, current int64) {
|
||||
width := pb.GetWidth()
|
||||
|
||||
var percentBox, countersBox, timeLeftBox, timeSpentBox, speedBox, barBox, end, out string
|
||||
|
@ -280,8 +280,8 @@ func (pb *ProgressBar) write(current int64) {
|
|||
// percents
|
||||
if pb.ShowPercent {
|
||||
var percent float64
|
||||
if pb.Total > 0 {
|
||||
percent = float64(current) / (float64(pb.Total) / float64(100))
|
||||
if total > 0 {
|
||||
percent = float64(current) / (float64(total) / float64(100))
|
||||
} else {
|
||||
percent = float64(current) / float64(100)
|
||||
}
|
||||
|
@ -291,9 +291,9 @@ func (pb *ProgressBar) write(current int64) {
|
|||
// counters
|
||||
if pb.ShowCounters {
|
||||
current := Format(current).To(pb.Units).Width(pb.UnitsWidth)
|
||||
if pb.Total > 0 {
|
||||
total := Format(pb.Total).To(pb.Units).Width(pb.UnitsWidth)
|
||||
countersBox = fmt.Sprintf(" %s / %s ", current, total)
|
||||
if total > 0 {
|
||||
totalS := Format(total).To(pb.Units).Width(pb.UnitsWidth)
|
||||
countersBox = fmt.Sprintf(" %s / %s ", current, totalS)
|
||||
} else {
|
||||
countersBox = fmt.Sprintf(" %s / ? ", current)
|
||||
}
|
||||
|
@ -322,8 +322,8 @@ func (pb *ProgressBar) write(current int64) {
|
|||
if pb.ShowTimeLeft && currentFromStart > 0 {
|
||||
perEntry := fromChange / time.Duration(currentFromStart)
|
||||
var left time.Duration
|
||||
if pb.Total > 0 {
|
||||
left = time.Duration(pb.Total-currentFromStart) * perEntry
|
||||
if total > 0 {
|
||||
left = time.Duration(total-currentFromStart) * perEntry
|
||||
left -= time.Since(lastChangeTime)
|
||||
left = (left / time.Second) * time.Second
|
||||
} else {
|
||||
|
@ -353,8 +353,8 @@ func (pb *ProgressBar) write(current int64) {
|
|||
if pb.ShowBar {
|
||||
size := width - barWidth
|
||||
if size > 0 {
|
||||
if pb.Total > 0 {
|
||||
curSize := int(math.Ceil((float64(current) / float64(pb.Total)) * float64(size)))
|
||||
if total > 0 {
|
||||
curSize := int(math.Ceil((float64(current) / float64(total)) * float64(size)))
|
||||
emptySize := size - curSize
|
||||
barBox = pb.BarStart
|
||||
if emptySize < 0 {
|
||||
|
@ -400,9 +400,10 @@ func (pb *ProgressBar) write(current int64) {
|
|||
|
||||
// and print!
|
||||
pb.mu.Lock()
|
||||
defer pb.mu.Unlock()
|
||||
pb.lastPrint = out + end
|
||||
isFinish := pb.isFinish
|
||||
pb.mu.Unlock()
|
||||
|
||||
switch {
|
||||
case isFinish:
|
||||
return
|
||||
|
@ -438,18 +439,19 @@ func (pb *ProgressBar) GetWidth() int {
|
|||
func (pb *ProgressBar) Update() {
|
||||
c := atomic.LoadInt64(&pb.current)
|
||||
p := atomic.LoadInt64(&pb.previous)
|
||||
t := atomic.LoadInt64(&pb.Total)
|
||||
if p != c {
|
||||
pb.mu.Lock()
|
||||
pb.changeTime = time.Now()
|
||||
pb.mu.Unlock()
|
||||
atomic.StoreInt64(&pb.previous, c)
|
||||
}
|
||||
pb.write(c)
|
||||
pb.write(t, c)
|
||||
if pb.AutoStat {
|
||||
if c == 0 {
|
||||
pb.startTime = time.Now()
|
||||
pb.startValue = 0
|
||||
} else if c >= pb.Total && pb.isFinish != true {
|
||||
} else if c >= t && pb.isFinish != true {
|
||||
pb.Finish()
|
||||
}
|
||||
}
|
||||
|
@ -462,6 +464,29 @@ func (pb *ProgressBar) String() string {
|
|||
return pb.lastPrint
|
||||
}
|
||||
|
||||
// SetTotal atomically sets new total count
|
||||
func (pb *ProgressBar) SetTotal(total int) *ProgressBar {
|
||||
return pb.SetTotal64(int64(total))
|
||||
}
|
||||
|
||||
// SetTotal64 atomically sets new total count
|
||||
func (pb *ProgressBar) SetTotal64(total int64) *ProgressBar {
|
||||
atomic.StoreInt64(&pb.Total, total)
|
||||
return pb
|
||||
}
|
||||
|
||||
// Reset bar and set new total count
|
||||
// Does effect only on finished bar
|
||||
func (pb *ProgressBar) Reset(total int) *ProgressBar {
|
||||
pb.mu.Lock()
|
||||
defer pb.mu.Unlock()
|
||||
if pb.isFinish {
|
||||
pb.SetTotal(total).Set(0)
|
||||
atomic.StoreInt64(&pb.previous, 0)
|
||||
}
|
||||
return pb
|
||||
}
|
||||
|
||||
// Internal loop for refreshing the progressbar
|
||||
func (pb *ProgressBar) refresher() {
|
||||
for {
|
||||
|
|
|
@ -124,6 +124,8 @@ func lockEcho() (shutdownCh chan struct{}, err error) {
|
|||
err = fmt.Errorf("Can't set terminal settings: %v", e)
|
||||
return
|
||||
}
|
||||
|
||||
shutdownCh = make(chan struct{})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -586,12 +586,12 @@
|
|||
"revision": "50da7d4131a3b5c9d063932461cab4d1fafb20b0"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "A/OK8uWTeJYUL6XXFwOLWw1IZLQ=",
|
||||
"checksumSHA1": "7GMQgpfoSQv4QcaREE2GzSZvlQI=",
|
||||
"path": "github.com/cheggaaa/pb",
|
||||
"revision": "72b964305fba1230d3d818711138195f22b9ceea",
|
||||
"revisionTime": "2018-02-18T15:37:33Z",
|
||||
"version": "v1.0.22",
|
||||
"versionExact": "v1.0.22"
|
||||
"revision": "2af8bbdea9e99e83b3ac400d8f6b6d1b8cbbf338",
|
||||
"revisionTime": "2018-05-21T09:56:06Z",
|
||||
"version": "v1.0.25",
|
||||
"versionExact": "v1.0.25"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "X2/71FBrn4pA3WcA620ySVO0uHU=",
|
||||
|
|
Loading…
Reference in New Issue