1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Minor formatting changes to ProgressReader. Newlines when complete

This commit is contained in:
Charles Hooper 2013-03-14 01:37:47 +00:00
parent e614690f07
commit 3686feaccc

View file

@ -113,13 +113,17 @@ func (r *progressReader) Read(p []byte) (n int, err error) {
// Only update progress for every 1% read // Only update progress for every 1% read
update_every := int(0.01 * float64(r.read_total)) update_every := int(0.01 * float64(r.read_total))
if r.read_progress - r.last_update > update_every { if r.read_progress - r.last_update > update_every || r.read_progress == r.read_total {
fmt.Fprintf(r.output, "%d/%d (%.0f%%)\r", fmt.Fprintf(r.output, "%d/%d (%.0f%%)\r",
r.read_progress, r.read_progress,
r.read_total, r.read_total,
float64(r.read_progress) / float64(r.read_total) * 100) float64(r.read_progress) / float64(r.read_total) * 100)
r.last_update = r.read_progress r.last_update = r.read_progress
} }
// Send newline when complete
if err == io.EOF {
fmt.Fprintf(r.output, "\n")
}
return read, err return read, err
} }