Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dl: download has noisy terminal output #26810

Open
smasher164 opened this issue Aug 4, 2018 · 1 comment

Comments

@smasher164
Copy link
Member

commented Aug 4, 2018

Running go1.11beta3 download leaves 106 lines of

Downloaded 0.0% (15224 / 174120698 bytes) ...
Downloaded 1.5% (2554732 / 174120698 bytes) ...
Downloaded 4.0% (7011180 / 174120698 bytes) ...
Downloaded 5.8% (10124140 / 174120698 bytes) ...
Downloaded 7.2% (12483436 / 174120698 bytes) ...
...

in my terminal. Responses to #17959, #18388, and #22356 suggest that most of our tools should be quiet by default. Given that goX.Y download insists on indicating download progress, a single-line progress-bar is a good compromise.
In a terminal, it will render an animated bar,

Downloaded [==============================>] 174120698 / 174120698 bytes

but in a file, it will write loggable output.

Downloaded [=>                             ] 15224 / 174120698 bytes
Downloaded [===>                           ] 25820012 / 174120698 bytes
Downloaded [=======>                       ] 40663916 / 174120698 bytes

The required change to version.go:

@@ -335,6 +336,7 @@ func copyFromURL(dstFile, srcURL string) (err error) {
        return fmt.Errorf("copied %v bytes; expected %v", n, res.ContentLength)
    }
    pw.update() // 100%
+   fmt.Fprintln(os.Stderr)
    return f.Close()
 }
 
@@ -346,13 +348,11 @@ type progressWriter struct {
 }
 
 func (p *progressWriter) update() {
-   end := " ..."
-   if p.n == p.total {
-       end = ""
-   }
-   fmt.Fprintf(os.Stderr, "Downloaded %0.1f%% (%d / %d bytes)%s\n",
-       (100.0*float64(p.n))/float64(p.total),
-       p.n, p.total, end)
+   const maxLine = 80
+   eq := int(math.Ceil((30 * float64(p.n)) / float64(p.total)))
+   s := fmt.Sprintf("Downloaded [%-31s] %d / %d bytes",
+       strings.Repeat("=", eq)+">", p.n, p.total)
+   fmt.Fprint(os.Stderr, s, strings.Repeat(" ", maxLine-len(s)), "\r")
 }

@agnivade agnivade changed the title version: download has noisy terminal output dl: download has noisy terminal output Aug 5, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Aug 5, 2018

/cc @bradfitz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.