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

Closed
smasher164 opened this issue Aug 4, 2018 · 2 comments
Closed

dl: download has noisy terminal output #26810

smasher164 opened this issue Aug 4, 2018 · 2 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@smasher164
Copy link
Member

smasher164 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
Copy link
Contributor

agnivade commented Aug 5, 2018

/cc @bradfitz

@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 5, 2018
@FiloSottile FiloSottile added this to the Unreleased milestone Aug 6, 2018
@smasher164
Copy link
Member Author

I don't believe this to be a necessary step anymore. Closing.

@golang golang locked and limited conversation to collaborators Dec 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants