Skip to content

Commit

Permalink
add describe
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Mar 7, 2019
1 parent 361d2c6 commit 7e454dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

0 comments on commit 7e454dc

Please sign in to comment.