diff --git a/progressbar.go b/progressbar.go index ce63afc..b66199b 100644 --- a/progressbar.go +++ b/progressbar.go @@ -265,6 +265,12 @@ func (p *ProgressBar) Clear() error { return clearProgressBar(p.config, p.state) } +// Describe will change the description shown before the progress, which +// can be changed on the fly (as for a slow running process). +func (p *ProgressBar) Describe(description string) { + p.config.description = description +} + // render renders the progress bar, updating the maximum // rendered line width. this function is not thread-safe, // so it must be called with an acquired lock. diff --git a/progressbar_test.go b/progressbar_test.go index cdfbcb8..21f390b 100644 --- a/progressbar_test.go +++ b/progressbar_test.go @@ -216,3 +216,13 @@ func md5sum(filePath string) (result string, err error) { result = hex.EncodeToString(hash.Sum(nil)) return } + +func ExampleDescribe() { + bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false)) + bar.Reset() + time.Sleep(1 * time.Second) + bar.Describe("performing axial adjustements") + bar.Add(10) + // Output: + // performing axial adjustements 10% |█ | [1s:9s] +}