Skip to content

Commit

Permalink
fix(log): Fix occasional log indent
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 23, 2023
1 parent 351394f commit 8dbe4d9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/progressbar/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@ 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) {
if l.bar.IsFinished() {
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()
Expand Down

0 comments on commit 8dbe4d9

Please sign in to comment.