Borg/pkg/ui/progress_writer.go
google-labs-jules[bot] 38fafbf639 feat: Add comprehensive docstrings and refactor matrix to tim
Add comprehensive Go docstrings with examples to all packages to achieve 100% coverage.

Refactor the `matrix` package to `tim` (Terminal Isolation Matrix). Update all references to the old package and terminology across the codebase, including commands, tests, and examples.

Fix inconsistencies in command-line flags and help text related to the refactoring.
2025-11-14 21:23:11 +00:00

28 lines
833 B
Go

package ui
import "github.com/schollz/progressbar/v3"
// progressWriter is an io.Writer that updates a progress bar's description
// with the written data. This is useful for showing the progress of operations
// that produce streaming text output, like git cloning.
type progressWriter struct {
bar *progressbar.ProgressBar
}
// NewProgressWriter creates a new progressWriter that wraps the given
// progress bar.
func NewProgressWriter(bar *progressbar.ProgressBar) *progressWriter {
return &progressWriter{bar: bar}
}
// Write implements the io.Writer interface. It updates the progress bar's
// description with the contents of the byte slice.
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
}