From bbce2369b42849cbcc689f473fa95ba4808421f8 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Tue, 2 Apr 2019 00:42:25 +0400 Subject: [PATCH] Update progressbar library, use it's option to clear progress after finish --- domains/yandex/v1/requests.go | 1 + domains/yandex/v1/structs.go | 4 ---- go.mod | 6 +----- go.sum | 2 ++ .../schollz/progressbar/v2/README.md | 2 +- .../github.com/schollz/progressbar/v2/go.mod | 7 ++++++- .../schollz/progressbar/v2/progressbar.go | 21 +++++++++++++++++++ vendor/modules.txt | 2 +- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/domains/yandex/v1/requests.go b/domains/yandex/v1/requests.go index 057bf48..7b97582 100644 --- a/domains/yandex/v1/requests.go +++ b/domains/yandex/v1/requests.go @@ -124,6 +124,7 @@ func uploadFile(uploadPath string, filePath string, overwriteFile bool) { int(fileInfo.Size()), progressbar.OptionSetBytes(int(fileInfo.Size())), progressbar.OptionSetRenderBlankState(true), + progressbar.OptionClearOnFinish(), ) progressReader := &progressReader{ diff --git a/domains/yandex/v1/structs.go b/domains/yandex/v1/structs.go index b1d4960..0e05392 100644 --- a/domains/yandex/v1/structs.go +++ b/domains/yandex/v1/structs.go @@ -4,7 +4,6 @@ package yandexv1 import ( - "fmt" "github.com/schollz/progressbar/v2" "io" ) @@ -26,9 +25,6 @@ func (pr *progressReader) Read(p []byte) (int, error) { func (pr *progressReader) report(n int64) { _ = pr.progressbar.Add64(n) - if pr.atEOF { - fmt.Print("\n\n") - } } type TokenError struct { diff --git a/go.mod b/go.mod index c40fe41..ebf2a39 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,10 @@ module github.com/fat0troll/yapusher go 1.12 require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f - github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/rs/zerolog v1.13.0 github.com/schollz/progressbar v1.0.0 // indirect - github.com/schollz/progressbar/v2 v2.10.0 - github.com/stretchr/objx v0.1.1 // indirect - github.com/stretchr/testify v1.3.0 // indirect + github.com/schollz/progressbar/v2 v2.11.0 gitlab.com/pztrn/flagger v0.0.0-20190122123836-d429d7149cc9 gitlab.com/pztrn/go-uuid v0.0.0-20190208164458-d6cc46783d2b ) diff --git a/go.sum b/go.sum index 6451af6..57e7b9b 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqa github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs= github.com/schollz/progressbar/v2 v2.10.0 h1:AxYYUjr5fOPlA0Pcqc3R3kDBrqyLFWk2P7LRLdXb3yE= github.com/schollz/progressbar/v2 v2.10.0/go.mod h1:l6tn6yU6ZdQoF8lwX/VoAUQ3FjhCbrcZDnl9xeWZzYw= +github.com/schollz/progressbar/v2 v2.11.0 h1:lQZYMKqH/kSSOc9rjL+9sa4bZavGS6EkBAZKKYdOjz4= +github.com/schollz/progressbar/v2 v2.11.0/go.mod h1:fBI3onORwtNtwCWJHsrXtjE3QnJOtqIZrvr3rDaF7L0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= diff --git a/vendor/github.com/schollz/progressbar/v2/README.md b/vendor/github.com/schollz/progressbar/v2/README.md index b59f467..28f5a38 100644 --- a/vendor/github.com/schollz/progressbar/v2/README.md +++ b/vendor/github.com/schollz/progressbar/v2/README.md @@ -12,7 +12,7 @@ A very simple thread-safe progress bar which should work on every OS without pro ## Install ``` -go get -u github.com/schollz/progressbar +go get -u github.com/schollz/progressbar/v2 ``` ## Usage diff --git a/vendor/github.com/schollz/progressbar/v2/go.mod b/vendor/github.com/schollz/progressbar/v2/go.mod index 0fad234..c6ab49b 100644 --- a/vendor/github.com/schollz/progressbar/v2/go.mod +++ b/vendor/github.com/schollz/progressbar/v2/go.mod @@ -1,3 +1,8 @@ module github.com/schollz/progressbar/v2 -require github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286 +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db + github.com/stretchr/objx v0.1.1 // indirect + github.com/stretchr/testify v1.3.0 +) diff --git a/vendor/github.com/schollz/progressbar/v2/progressbar.go b/vendor/github.com/schollz/progressbar/v2/progressbar.go index b66199b..044482d 100644 --- a/vendor/github.com/schollz/progressbar/v2/progressbar.go +++ b/vendor/github.com/schollz/progressbar/v2/progressbar.go @@ -43,6 +43,8 @@ type state struct { maxLineWidth int currentBytes float64 + + finished bool } type config struct { @@ -61,6 +63,9 @@ type config struct { // minimum time to wait in between updates throttleDuration time.Duration + + // clear bar once finished + clearOnFinish bool } // Theme defines the elements of the bar @@ -152,6 +157,13 @@ func OptionThrottle(duration time.Duration) Option { } } +// OptionClearOnFinish will clear the bar once its finished +func OptionClearOnFinish() Option { + return func(p *ProgressBar) { + p.config.clearOnFinish = true + } +} + var defaultTheme = Theme{Saucer: "█", SaucerPadding: " ", BarStart: "|", BarEnd: "|"} // NewOptions constructs a new instance of ProgressBar, with any options you specify @@ -288,6 +300,15 @@ func (p *ProgressBar) render() error { return err } + // check if the progress bar is finished + if p.state.finished || p.state.currentNum >= p.config.max { + p.state.finished = true + if p.config.clearOnFinish { + // if the progressbar is finished, return + return nil + } + } + // then, re-render the current progress bar w, err := renderProgressBar(p.config, p.state) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index cc5e846..d179582 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -6,7 +6,7 @@ github.com/mitchellh/colorstring github.com/rs/zerolog github.com/rs/zerolog/internal/cbor github.com/rs/zerolog/internal/json -# github.com/schollz/progressbar/v2 v2.10.0 +# github.com/schollz/progressbar/v2 v2.11.0 github.com/schollz/progressbar/v2 # gitlab.com/pztrn/flagger v0.0.0-20190122123836-d429d7149cc9 gitlab.com/pztrn/flagger