Verified Commit bbce2369 authored by Vladimir Hodakov's avatar Vladimir Hodakov 🔥
Browse files

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

parent 984f5097
......@@ -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{
......
......@@ -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 {
......
......@@ -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
)
......@@ -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
......
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
)
......@@ -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 {
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment