diff --git a/Gopkg.lock b/Gopkg.lock index 31d8443..2238e1e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -28,8 +28,8 @@ [[projects]] name = "github.com/schollz/progressbar" packages = ["."] - revision = "b8e001516e13bd132ed253bf1b175dbfb5cdf308" - version = "v0.2.0" + revision = "98649a7575ca56014cb102885f09f05bb2cccb49" + version = "v0.3.1" [[projects]] name = "github.com/sirupsen/logrus" diff --git a/vendor/github.com/schollz/progressbar/README.md b/vendor/github.com/schollz/progressbar/README.md index 7b77bf8..c2c1ae4 100644 --- a/vendor/github.com/schollz/progressbar/README.md +++ b/vendor/github.com/schollz/progressbar/README.md @@ -1,15 +1,21 @@ -

-progressbar -
-Build Status -Code Coverage -Go Report Card -GoDoc -

+# progressbar -

A very simple progress bar.

+[![travis](https://travis-ci.org/schollz/progressbar.svg?branch=master)](https://travis-ci.org/schollz/progressbar) +[![go report card](https://goreportcard.com/badge/github.com/schollz/progressbar)](https://goreportcard.com/report/github.com/schollz/progressbar) +![coverage](https://img.shields.io/badge/coverage-94%25-brightgreen.svg) +[![godocs](https://godoc.org/github.com/schollz/progressbar?status.svg)](https://godoc.org/github.com/schollz/progressbar) + +A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar for [croc](https://github.com/schollz/croc) and everything I tried had problems, so I made another one. + +![Example of progress bar](https://user-images.githubusercontent.com/6550035/32120326-5f420d42-bb15-11e7-89d4-c502864e78eb.gif) + +## Install + +``` +go get -u github.com/schollz/progressbar +``` + +## Usage **Basic usage:** @@ -26,3 +32,18 @@ which looks like: ```bash 100% |████████████████████████████████████████| [1s:0s] ``` + +The times at the end show the elapsed time and the remaining time, respectively. + +## Contributing + +Pull requests are welcome. Feel free to... + +- Revise documentation +- Add new features +- Fix bugs +- Suggest improvements + +## License + +MIT diff --git a/vendor/github.com/schollz/progressbar/examples/main.go b/vendor/github.com/schollz/progressbar/examples/main.go index a93f8d8..4291383 100644 --- a/vendor/github.com/schollz/progressbar/examples/main.go +++ b/vendor/github.com/schollz/progressbar/examples/main.go @@ -7,9 +7,9 @@ import ( ) func main() { - bar := progressbar.New(100) + bar := progressbar.New(1000) bar.Reset() - for i := 0; i < 100; i++ { + for i := 0; i < 1000; i++ { bar.Add(1) time.Sleep(10 * time.Millisecond) } diff --git a/vendor/github.com/schollz/progressbar/progressbar.go b/vendor/github.com/schollz/progressbar/progressbar.go index 42536cc..12555b7 100644 --- a/vendor/github.com/schollz/progressbar/progressbar.go +++ b/vendor/github.com/schollz/progressbar/progressbar.go @@ -35,19 +35,17 @@ type ProgressBar struct { // New returns a new ProgressBar // with the specified maximum func New(max int) *ProgressBar { - p := new(ProgressBar) - p.Lock() - defer p.Unlock() - p.max = max - p.size = 40 - p.symbolFinished = "█" - p.symbolLeft = " " - p.leftBookend = "|" - p.rightBookend = "|" - p.w = os.Stdout - p.lastShown = time.Now() - p.startTime = time.Now() - return p + return &ProgressBar{ + max: max, + size: 40, + symbolFinished: "█", + symbolLeft: " ", + leftBookend: "|", + rightBookend: "|", + w: os.Stdout, + lastShown: time.Now(), + startTime: time.Now(), + } } // Reset will reset the clock that is used @@ -85,6 +83,10 @@ func (p *ProgressBar) Add(num int) error { // Set will change the current count on the progress bar func (p *ProgressBar) Set(num int) error { p.Lock() + if p.max == 0 { + p.Unlock() + return errors.New("max must be greater than 0") + } p.currentNum = num percent := float64(p.currentNum) / float64(p.max) p.currentSaucerSize = int(percent * float64(p.size)) @@ -112,7 +114,7 @@ func (p *ProgressBar) Show() error { strings.Repeat(p.symbolFinished, p.currentSaucerSize), strings.Repeat(p.symbolLeft, p.size-p.currentSaucerSize), p.rightBookend, - time.Since(p.startTime).Round(time.Second).String(), + (time.Duration(time.Since(p.startTime).Seconds()) * time.Second).String(), (time.Duration(secondsLeft) * time.Second).String(), ) diff --git a/vendor/github.com/schollz/progressbar/progressbar_test.go b/vendor/github.com/schollz/progressbar/progressbar_test.go index 92c7d11..0687e54 100644 --- a/vendor/github.com/schollz/progressbar/progressbar_test.go +++ b/vendor/github.com/schollz/progressbar/progressbar_test.go @@ -1,6 +1,9 @@ package progressbar -import "time" +import ( + "testing" + "time" +) func ExampleBar() { bar := New(10) @@ -12,3 +15,14 @@ func ExampleBar() { // Output: // 10% |█ | [1s:9s] } + +func TestBar(t *testing.T) { + bar := New(0) + if err := bar.Add(1); err == nil { + t.Error("should have an error for 0 bar") + } + bar = New(10) + if err := bar.Add(11); err == nil { + t.Error("should have an error for adding > bar") + } +}