aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetter Rasmussen2016-01-24 17:56:12 +0100
committerPetter Rasmussen2016-01-24 17:56:12 +0100
commitf40d90416c5ee30babdd3ecfbd76edcbf8fa385a (patch)
tree65d3ef29977a840564c91f560a1da697fab28e8c
parent5bacd6be45dfb961c78f6e89698f8c03ca2dea43 (diff)
downloadgdrive-f40d90416c5ee30babdd3ecfbd76edcbf8fa385a.tar.bz2
Clear indicator when done, 3 second rate update
-rw-r--r--drive/progress.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/drive/progress.go b/drive/progress.go
index 915526c..0560704 100644
--- a/drive/progress.go
+++ b/drive/progress.go
@@ -8,7 +8,7 @@ import (
)
const MaxDrawInterval = time.Second * 1
-const MaxRateInterval = time.Second * 5
+const MaxRateInterval = time.Second * 3
func getProgressReader(r io.Reader, w io.Writer, size int64) io.Reader {
// Don't wrap reader if output is discarded or size is too small
@@ -61,7 +61,7 @@ func (self *Progress) Read(p []byte) (int, error) {
// Draw progress every x seconds
if self.updated.Add(MaxDrawInterval).Before(now) || isLast {
- self.Draw(isLast)
+ self.draw(isLast)
}
// Update last draw time
@@ -73,16 +73,15 @@ func (self *Progress) Read(p []byte) (int, error) {
return n, err
}
-func (self *Progress) Draw(isLast bool) {
+func (self *Progress) draw(isLast bool) {
if self.done {
return
}
- // Clear line
- fmt.Fprintf(self.Writer, "\r%50s", "")
+ self.clear()
// Print progress
- fmt.Fprintf(self.Writer, "\r%s/%s", formatSize(self.progress, false), formatSize(self.Size, false))
+ fmt.Fprintf(self.Writer, "%s/%s", formatSize(self.progress, false), formatSize(self.Size, false))
// Print rate
if self.rate > 0 {
@@ -90,6 +89,10 @@ func (self *Progress) Draw(isLast bool) {
}
if isLast {
- fmt.Fprintf(self.Writer, "\n")
+ self.clear()
}
}
+
+func (self *Progress) clear() {
+ fmt.Fprintf(self.Writer, "\r%50s\r", "")
+}