Skip to content

Commit 533e284

Browse files
authored
Merge pull request #225 from schollz/fix/describe
fix: describe after
2 parents 1a5d483 + 914e511 commit 533e284

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

progressbar.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,13 @@ func (p *ProgressBar) Describe(description string) {
803803
if p.config.invisible {
804804
return
805805
}
806+
// if already finished, re-render with the new description
807+
if p.state.finished && !p.config.clearOnFinish && !p.config.useANSICodes {
808+
clearProgressBar(p.config, p.state)
809+
io.Copy(p.config.writer, &p.config.stdBuffer)
810+
renderProgressBar(p.config, &p.state)
811+
return
812+
}
806813
p.render()
807814
}
808815

progressbar_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,22 @@ func TestProgressBar_Describe(t *testing.T) {
853853
}
854854
}
855855

856+
func TestProgressBar_DescribeAfterFinish(t *testing.T) {
857+
buf := strings.Builder{}
858+
bar := NewOptions(100,
859+
OptionSetDescription("Uploading files"),
860+
OptionShowCount(),
861+
OptionSetWriter(&buf),
862+
OptionSetWidth(10),
863+
)
864+
for i := 0; i < 100; i++ {
865+
bar.Add(1)
866+
}
867+
bar.Describe("Upload complete")
868+
result := buf.String()
869+
assert.Contains(t, result, "Upload complete")
870+
}
871+
856872
func TestRenderBlankStateWithThrottle(t *testing.T) {
857873
buf := strings.Builder{}
858874
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(true), OptionThrottle(time.Millisecond), OptionSetWriter(&buf))

0 commit comments

Comments
 (0)