diff --git a/vendor/github.com/cheggaaa/pb/pb.go b/vendor/github.com/cheggaaa/pb/pb.go index 19eb4d1a9..eddc807b1 100644 --- a/vendor/github.com/cheggaaa/pb/pb.go +++ b/vendor/github.com/cheggaaa/pb/pb.go @@ -13,7 +13,7 @@ import ( ) // Current version -const Version = "1.0.19" +const Version = "1.0.22" const ( // Default refresh rate - 200ms @@ -37,16 +37,17 @@ func New(total int) *ProgressBar { // Create new progress bar object using int64 as total func New64(total int64) *ProgressBar { pb := &ProgressBar{ - Total: total, - RefreshRate: DEFAULT_REFRESH_RATE, - ShowPercent: true, - ShowCounters: true, - ShowBar: true, - ShowTimeLeft: true, - ShowFinalTime: true, - Units: U_NO, - ManualUpdate: false, - finish: make(chan struct{}), + Total: total, + RefreshRate: DEFAULT_REFRESH_RATE, + ShowPercent: true, + ShowCounters: true, + ShowBar: true, + ShowTimeLeft: true, + ShowElapsedTime: false, + ShowFinalTime: true, + Units: U_NO, + ManualUpdate: false, + finish: make(chan struct{}), } return pb.Format(FORMAT) } @@ -72,7 +73,7 @@ type ProgressBar struct { RefreshRate time.Duration ShowPercent, ShowCounters bool ShowSpeed, ShowTimeLeft, ShowBar bool - ShowFinalTime bool + ShowFinalTime, ShowElapsedTime bool Output io.Writer Callback Callback NotPrint bool @@ -274,7 +275,7 @@ func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader { func (pb *ProgressBar) write(current int64) { width := pb.GetWidth() - var percentBox, countersBox, timeLeftBox, speedBox, barBox, end, out string + var percentBox, countersBox, timeLeftBox, timeSpentBox, speedBox, barBox, end, out string // percents if pb.ShowPercent { @@ -305,6 +306,11 @@ func (pb *ProgressBar) write(current int64) { lastChangeTime := pb.changeTime fromChange := lastChangeTime.Sub(pb.startTime) pb.mu.Unlock() + + if pb.ShowElapsedTime { + timeSpentBox = fmt.Sprintf(" %s ", (fromStart/time.Second)*time.Second) + } + select { case <-pb.finish: if pb.ShowFinalTime { @@ -342,7 +348,7 @@ func (pb *ProgressBar) write(current int64) { speedBox = " " + Format(int64(speed)).To(pb.Units).Width(pb.UnitsWidth).PerSec().String() } - barWidth := escapeAwareRuneCountInString(countersBox + pb.BarStart + pb.BarEnd + percentBox + timeLeftBox + speedBox + pb.prefix + pb.postfix) + barWidth := escapeAwareRuneCountInString(countersBox + pb.BarStart + pb.BarEnd + percentBox + timeSpentBox + timeLeftBox + speedBox + pb.prefix + pb.postfix) // bar if pb.ShowBar { size := width - barWidth @@ -387,7 +393,7 @@ func (pb *ProgressBar) write(current int64) { } // check len - out = pb.prefix + countersBox + barBox + percentBox + speedBox + timeLeftBox + pb.postfix + out = pb.prefix + timeSpentBox + countersBox + barBox + percentBox + speedBox + timeLeftBox + pb.postfix if cl := escapeAwareRuneCountInString(out); cl < width { end = strings.Repeat(" ", width-cl) } diff --git a/vendor/github.com/cheggaaa/pb/pb_win.go b/vendor/github.com/cheggaaa/pb/pb_win.go index 72f682835..2c67e1947 100644 --- a/vendor/github.com/cheggaaa/pb/pb_win.go +++ b/vendor/github.com/cheggaaa/pb/pb_win.go @@ -102,7 +102,7 @@ var echoLockMutex sync.Mutex var oldState word -func lockEcho() (quit chan int, err error) { +func lockEcho() (shutdownCh chan struct{}, err error) { echoLockMutex.Lock() defer echoLockMutex.Unlock() if echoLocked { diff --git a/vendor/github.com/cheggaaa/pb/pb_x.go b/vendor/github.com/cheggaaa/pb/pb_x.go index bbbe7c2d6..8e05770ce 100644 --- a/vendor/github.com/cheggaaa/pb/pb_x.go +++ b/vendor/github.com/cheggaaa/pb/pb_x.go @@ -48,21 +48,21 @@ func terminalWidth() (int, error) { return int(ws.Col), nil } -func lockEcho() (quit chan int, err error) { +func lockEcho() (shutdownCh chan struct{}, err error) { echoLockMutex.Lock() defer echoLockMutex.Unlock() if origTermStatePtr != nil { - return quit, ErrPoolWasStarted + return shutdownCh, ErrPoolWasStarted } fd := int(tty.Fd()) - oldTermStatePtr, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + origTermStatePtr, err = unix.IoctlGetTermios(fd, ioctlReadTermios) if err != nil { return nil, fmt.Errorf("Can't get terminal settings: %v", err) } - oldTermios := *oldTermStatePtr + oldTermios := *origTermStatePtr newTermios := oldTermios newTermios.Lflag &^= syscall.ECHO newTermios.Lflag |= syscall.ICANON | syscall.ISIG @@ -71,8 +71,8 @@ func lockEcho() (quit chan int, err error) { return nil, fmt.Errorf("Can't set terminal settings: %v", err) } - quit = make(chan int, 1) - go catchTerminate(quit) + shutdownCh = make(chan struct{}) + go catchTerminate(shutdownCh) return } @@ -95,12 +95,12 @@ func unlockEcho() error { } // listen exit signals and restore terminal state -func catchTerminate(quit chan int) { +func catchTerminate(shutdownCh chan struct{}) { sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL) defer signal.Stop(sig) select { - case <-quit: + case <-shutdownCh: unlockEcho() case <-sig: unlockEcho() diff --git a/vendor/github.com/cheggaaa/pb/pool.go b/vendor/github.com/cheggaaa/pb/pool.go index bc1a13886..f44baa01f 100644 --- a/vendor/github.com/cheggaaa/pb/pool.go +++ b/vendor/github.com/cheggaaa/pb/pool.go @@ -12,19 +12,28 @@ import ( // You need call pool.Stop() after work func StartPool(pbs ...*ProgressBar) (pool *Pool, err error) { pool = new(Pool) - if err = pool.start(); err != nil { + if err = pool.Start(); err != nil { return } pool.Add(pbs...) return } +// NewPool initialises a pool with progress bars, but +// doesn't start it. You need to call Start manually +func NewPool(pbs ...*ProgressBar) (pool *Pool) { + pool = new(Pool) + pool.Add(pbs...) + return +} + type Pool struct { Output io.Writer RefreshRate time.Duration bars []*ProgressBar lastBarsCount int - quit chan int + shutdownCh chan struct{} + workerCh chan struct{} m sync.Mutex finishOnce sync.Once } @@ -41,30 +50,38 @@ func (p *Pool) Add(pbs ...*ProgressBar) { } } -func (p *Pool) start() (err error) { +func (p *Pool) Start() (err error) { p.RefreshRate = DefaultRefreshRate - quit, err := lockEcho() + p.shutdownCh, err = lockEcho() if err != nil { return } - p.quit = make(chan int) - go p.writer(quit) + p.workerCh = make(chan struct{}) + go p.writer() return } -func (p *Pool) writer(finish chan int) { +func (p *Pool) writer() { var first = true + defer func() { + if first == false { + p.print(false) + } else { + p.print(true) + p.print(false) + } + close(p.workerCh) + }() + for { select { case <-time.After(p.RefreshRate): if p.print(first) { p.print(false) - finish <- 1 return } first = false - case <-p.quit: - finish <- 1 + case <-p.shutdownCh: return } } @@ -72,11 +89,14 @@ func (p *Pool) writer(finish chan int) { // Restore terminal state and close pool func (p *Pool) Stop() error { - // Wait until one final refresh has passed. - time.Sleep(p.RefreshRate) - p.finishOnce.Do(func() { - close(p.quit) + close(p.shutdownCh) }) + + // Wait for the worker to complete + select { + case <-p.workerCh: + } + return unlockEcho() } diff --git a/vendor/vendor.json b/vendor/vendor.json index 93f044f93..afdefca3c 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -585,18 +585,20 @@ "path": "github.com/biogo/hts/bgzf", "revision": "50da7d4131a3b5c9d063932461cab4d1fafb20b0" }, + { + "checksumSHA1": "A/OK8uWTeJYUL6XXFwOLWw1IZLQ=", + "path": "github.com/cheggaaa/pb", + "revision": "72b964305fba1230d3d818711138195f22b9ceea", + "revisionTime": "2018-02-18T15:37:33Z", + "version": "v1.0.22", + "versionExact": "v1.0.22" + }, { "checksumSHA1": "X2/71FBrn4pA3WcA620ySVO0uHU=", "path": "github.com/creack/goselect", "revision": "528c74964609a58f7c17471525659c9b71cd499b", "revisionTime": "2018-02-10T03:43:46Z" }, - { - "checksumSHA1": "ymc5+iJ+1ipls3ihqPdzMjFYCqo=", - "path": "github.com/cheggaaa/pb", - "revision": "18d384da9bdc1e5a08fc2a62a494c321d9ae74ea", - "revisionTime": "2017-12-14T13:20:59Z" - }, { "checksumSHA1": "/5cvgU+J4l7EhMXTK76KaCAfOuU=", "comment": "v1.0.0-3-g6d21280",