Borg/pkg/ui/progress_writer.go
2025-11-02 17:56:13 +00:00

23 lines
657 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ui
import "github.com/schollz/progressbar/v3"
// ProgressWriter updates a progress bars description on writes.
type ProgressWriter struct {
bar *progressbar.ProgressBar
}
// NewProgressWriter creates a writer that sets the progress bar description to the last written line.
func NewProgressWriter(bar *progressbar.ProgressBar) *ProgressWriter {
return &ProgressWriter{bar: bar}
}
// Write implements io.Writer by describing the progress with the provided bytes.
func (pw *ProgressWriter) Write(p []byte) (n int, err error) {
if pw == nil || pw.bar == nil {
return len(p), nil
}
s := string(p)
pw.bar.Describe(s)
return len(p), nil
}