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 24, 2023
1 parent 351394f commit 8e8b702
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 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,23 +14,19 @@ func NewBarSafeLogger(w io.Writer, bar *ProgressBar) *BarSafeLogger {
type BarSafeLogger struct {
out io.Writer
bar *ProgressBar
buf bytes.Buffer
}

func (l *BarSafeLogger) Write(p []byte) (int, error) {
if l.bar.IsFinished() {
return l.out.Write(p)
}

l.buf.Write([]byte("\r\x1B[K"))
l.buf.Write(p)
if p[len(p)-1] == '\n' {
l.buf.WriteString(l.bar.String())
}
l.bar.mu.Lock()
defer l.bar.mu.Unlock()
if n, err := io.Copy(l.out, &l.buf); err != nil {
return int(n), err
}
return len(p), nil

_, _ = l.out.Write([]byte("\r\x1B[K"))
n, _ := l.out.Write(p)
_, _ = l.out.Write([]byte(l.bar.String()))

return n, nil
}

0 comments on commit 8e8b702

Please sign in to comment.