Update progressbar library, use it's option to clear progress after finish

master
Vladimir Hodakov 2019-04-02 00:42:25 +04:00
parent 984f509780
commit bbce2369b4
Signed by: Vladimir Hodakov
GPG Key ID: 673980B6882F82C6
8 changed files with 33 additions and 12 deletions

View File

@ -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{

View File

@ -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 {

6
go.mod
View File

@ -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
)

2
go.sum
View File

@ -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=

View File

@ -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

View File

@ -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
)

View File

@ -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 {

2
vendor/modules.txt vendored
View File

@ -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