Skip to content

Commit 01eb321

Browse files
authored
Merge pull request #2582 from nirs/progress-to-file
Show progress only when logging to terminal
2 parents 69151ad + 3fcc54e commit 01eb321

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pkg/downloader/downloader.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ var HideProgress bool
2929

3030
// hideBar is used only for testing.
3131
func hideBar(bar *pb.ProgressBar) {
32-
bar.Set(pb.ReturnSymbol, "")
33-
bar.SetTemplateString("")
32+
bar.Set(pb.Static, true)
3433
}
3534

3635
type Status = string

pkg/progressbar/progressbar.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ func New(size int64) (*pb.ProgressBar, error) {
1212
bar := pb.New64(size)
1313

1414
bar.Set(pb.Bytes, true)
15-
if isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) {
15+
16+
// Both logrous and pb use stderr by default.
17+
logFd := os.Stderr.Fd()
18+
19+
// Show progress only when logging to terminal.
20+
if isatty.IsTerminal(logFd) || isatty.IsCygwinTerminal(logFd) {
1621
bar.SetTemplateString(`{{counters . }} {{bar . | green }} {{percent .}} {{speed . "%s/s"}}`)
1722
bar.SetRefreshRate(200 * time.Millisecond)
1823
} else {
19-
bar.Set(pb.Terminal, false)
20-
bar.Set(pb.ReturnSymbol, "\n")
21-
bar.SetTemplateString(`{{counters . }} ({{percent .}}) {{speed . "%s/s"}}`)
22-
bar.SetRefreshRate(5 * time.Second)
24+
bar.Set(pb.Static, true)
2325
}
26+
2427
bar.SetWidth(80)
2528
if err := bar.Err(); err != nil {
2629
return nil, err

0 commit comments

Comments
 (0)