From b3c7a6aa083dfa29897231798995a5ba15adcc2b Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 26 Oct 2017 12:37:24 -0600 Subject: [PATCH] Add new dependencies --- .../github.com/schollz/progressbar/README.md | 13 +++ .../schollz/progressbar/examples/main.go | 16 +++ .../schollz/progressbar/progressbar.go | 110 ++++++++++++++++++ .../schollz/progressbar/progressbar_test.go | 9 ++ 4 files changed, 148 insertions(+) create mode 100644 vendor/github.com/schollz/progressbar/README.md create mode 100644 vendor/github.com/schollz/progressbar/examples/main.go create mode 100644 vendor/github.com/schollz/progressbar/progressbar.go create mode 100644 vendor/github.com/schollz/progressbar/progressbar_test.go diff --git a/vendor/github.com/schollz/progressbar/README.md b/vendor/github.com/schollz/progressbar/README.md new file mode 100644 index 0000000..fdffa70 --- /dev/null +++ b/vendor/github.com/schollz/progressbar/README.md @@ -0,0 +1,13 @@ +

+progressbar +
+Build Status +Go Report Card +GoDoc +

+ +

A very simple progress bar.

+ +See the godocs for more info. diff --git a/vendor/github.com/schollz/progressbar/examples/main.go b/vendor/github.com/schollz/progressbar/examples/main.go new file mode 100644 index 0000000..b7df7d2 --- /dev/null +++ b/vendor/github.com/schollz/progressbar/examples/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "time" + + "github.com/schollz/progressbar" +) + +func main() { + bar := progressbar.New(100) + bar.Reset() + for i := 0; i < 100; 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 new file mode 100644 index 0000000..62361e4 --- /dev/null +++ b/vendor/github.com/schollz/progressbar/progressbar.go @@ -0,0 +1,110 @@ +package progressbar + +import ( + "errors" + "fmt" + "io" + "os" + "strings" + "sync" + "time" +) + +// ProgressBar is a thread-safe, simple +// progress bar +type ProgressBar struct { + max int // max number of the counter + size int // size of the saucer + currentNum int + currentPercent int + lastPercent int + currentSaucerSize int + + lastShown time.Time + startTime time.Time + w io.Writer + + // symbols + symbolFinished string + symbolLeft string + leftBookend string + rightBookend string + sync.RWMutex +} + +// 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 +} + +// Reset will reset the clock +func (p *ProgressBar) Reset() { + p.Lock() + defer p.Unlock() + p.lastShown = time.Now() + p.startTime = time.Now() +} + +// Set the max of the progress bar +func (p *ProgressBar) SetMax(num int) { + p.Lock() + defer p.Unlock() + p.max = num +} + +// Add a certain amount to the progress bar +func (p *ProgressBar) Add(num int) error { + p.Lock() + p.currentNum += num + percent := float64(p.currentNum) / float64(p.max) + p.currentSaucerSize = int(percent * float64(p.size)) + p.currentPercent = int(percent * 100) + updateBar := p.currentPercent != p.lastPercent && p.currentPercent > 0 + p.lastPercent = p.currentPercent + p.Unlock() + if updateBar { + return p.Show() + } + return nil +} + +// Show will print the current progress bar +func (p *ProgressBar) Show() error { + p.RLock() + defer p.RUnlock() + if p.currentNum > p.max { + return errors.New("current number exceeds max") + } + secondsLeft := time.Since(p.startTime).Seconds() / float64(p.currentNum) * (float64(p.max) - float64(p.currentNum)) + s := fmt.Sprintf("\r%3d%% %s%s%s%s [%s:%s] ", + p.currentPercent, + p.leftBookend, + 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(secondsLeft) * time.Second).String(), + ) + + _, err := io.WriteString(p.w, s) + if err != nil { + return err + } + if f, ok := p.w.(*os.File); ok { + f.Sync() + } + return nil +} diff --git a/vendor/github.com/schollz/progressbar/progressbar_test.go b/vendor/github.com/schollz/progressbar/progressbar_test.go new file mode 100644 index 0000000..b8c0b31 --- /dev/null +++ b/vendor/github.com/schollz/progressbar/progressbar_test.go @@ -0,0 +1,9 @@ +package progressbar + +func ExampleBar() { + bar := New(10) + bar.Add(1) + + // Output: + // 10% |████ | [0s:0s] +}