Skip to content

Commit

Permalink
chore(log): Remove log buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 23, 2023
1 parent 8dbe4d9 commit 053eb4b
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions internal/progressbar/logger.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package progressbar

import (
"bytes"
"io"
)

Expand All @@ -15,7 +14,6 @@ func NewBarSafeLogger(w io.Writer, bar *ProgressBar) *BarSafeLogger {
type BarSafeLogger struct {
out io.Writer
bar *ProgressBar
buf bytes.Buffer
atStart bool
}

Expand All @@ -24,20 +22,18 @@ func (l *BarSafeLogger) Write(p []byte) (int, error) {
return l.out.Write(p)
}

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()
if n, err := io.Copy(l.out, &l.buf); err != nil {
return int(n), err

if !l.atStart {
_, _ = l.out.Write([]byte("\r\x1B[K"))
}
return len(p), nil

n, _ := l.out.Write(p)

if l.atStart = p[len(p)-1] == '\n'; !l.atStart {
_, _ = l.out.Write([]byte(l.bar.String()))
}

return n, nil
}

0 comments on commit 053eb4b

Please sign in to comment.