diff --git a/builder/source/simple.go b/builder/source/simple.go index 0789a31..181eb47 100644 --- a/builder/source/simple.go +++ b/builder/source/simple.go @@ -190,13 +190,35 @@ func (s *SimpleSource) download(destination string) error { }, }, } - resp := client.Do(req) - // Setup our progress bar + // Show our progress bar + s.showProgress(resp) + + if err := resp.Err(); err != nil { + slog.Error("Error downloading", "uri", s.URI, "err", err) + + return err + } + + return nil +} + +func onTTY() bool { + s, _ := os.Stdout.Stat() + + return s.Mode()&os.ModeCharDevice > 0 +} + +func (s *SimpleSource) showProgress(resp *grab.Response) { + if !onTTY() { + slog.Info("Downloading source", "uri", s.URI) + } + pbar := pb.Start64(resp.Size()) pbar.Set(pb.Bytes, true) pbar.SetTemplateString(progressBarTemplate) + pbar.SetWriter(os.Stdout) defer pbar.Finish() @@ -212,12 +234,7 @@ func (s *SimpleSource) download(destination string) error { // Ensure progressbar completes to 100% pbar.SetCurrent(resp.BytesComplete()) - if err := resp.Err(); err != nil { - slog.Error("Error downloading", "uri", s.URI, "err", err) - return err - } - - return nil + return } } } diff --git a/cli/log/log.go b/cli/log/log.go index 955e64b..6a41755 100644 --- a/cli/log/log.go +++ b/cli/log/log.go @@ -38,20 +38,20 @@ func setLogger(h slog.Handler) { } func onTTY() bool { - s, _ := os.Stdout.Stat() + s, _ := os.Stderr.Stat() return s.Mode()&os.ModeCharDevice > 0 } func SetColoredLogger() { - setLogger(powerline.NewHandler(os.Stdout, &powerline.HandlerOptions{ + setLogger(powerline.NewHandler(os.Stderr, &powerline.HandlerOptions{ Level: &Level, Colors: colors, })) } func SetUncoloredLogger() { - setLogger(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + setLogger(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ Level: &Level, })) }