From 8dbe4d990278593a8e4d1d551782dfe1c5852539 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 23 Oct 2023 02:11:20 -0500 Subject: [PATCH] fix(log): Fix occasional log indent --- internal/progressbar/logger.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/progressbar/logger.go b/internal/progressbar/logger.go index 2e47342b..e259f769 100644 --- a/internal/progressbar/logger.go +++ b/internal/progressbar/logger.go @@ -13,9 +13,10 @@ func NewBarSafeLogger(w io.Writer, bar *ProgressBar) *BarSafeLogger { } type BarSafeLogger struct { - out io.Writer - bar *ProgressBar - buf bytes.Buffer + out io.Writer + bar *ProgressBar + buf bytes.Buffer + atStart bool } func (l *BarSafeLogger) Write(p []byte) (int, error) { @@ -23,10 +24,15 @@ func (l *BarSafeLogger) Write(p []byte) (int, error) { return l.out.Write(p) } - l.buf.Write([]byte("\r\x1B[K")) + if !l.atStart { + l.buf.Write([]byte("\r\x1B[K")) + } l.buf.Write(p) if p[len(p)-1] == '\n' { l.buf.WriteString(l.bar.String()) + l.atStart = false + } else { + l.atStart = true } l.bar.mu.Lock() defer l.bar.mu.Unlock()