Skip to content

Commit

Permalink
Merge pull request #110 from flowchartsman/immediate_describe
Browse files Browse the repository at this point in the history
Force redraw on Describe()
  • Loading branch information
schollz committed Dec 20, 2021
2 parents eaf664f + e56687f commit c869815
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion progressbar.go
Expand Up @@ -517,6 +517,7 @@ func (p *ProgressBar) Clear() error {
// can be changed on the fly (as for a slow running process).
func (p *ProgressBar) Describe(description string) {
p.config.description = description
p.RenderBlank()
}

// New64 returns a new ProgressBar
Expand Down Expand Up @@ -687,7 +688,6 @@ func renderProgressBar(c config, s *state) (int, error) {
bytesString += fmt.Sprintf("%s/%s%s", currentHumanize, c.maxHumanized, c.maxHumanizedSuffix)
} else {
bytesString += fmt.Sprintf("%s%s/%s%s", currentHumanize, currentSuffix, c.maxHumanized, c.maxHumanizedSuffix)

}
} else {
bytesString += fmt.Sprintf("%.0f/%d", s.currentBytes, c.max)
Expand Down
18 changes: 10 additions & 8 deletions progressbar_test.go
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"net/http"
"os"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -87,6 +88,7 @@ func ExampleOptionClearOnFinish() {
// Output:
// Finished
}

func ExampleProgressBar_Finish() {
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false))
bar.Finish()
Expand Down Expand Up @@ -502,7 +504,6 @@ func TestConcurrency(t *testing.T) {
}

func TestIterationNames(t *testing.T) {

b := Default(20)
tc := b.config

Expand All @@ -526,12 +527,13 @@ func md5sum(r io.Reader) (string, error) {
return hex.EncodeToString(hash.Sum(nil)), err
}

func ExampleProgressBar_Describe() {
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false))
bar.Reset()
time.Sleep(1 * time.Second)
bar.Describe("performing axial adjustements")
func TestProgressBar_Describe(t *testing.T) {
buf := strings.Builder{}
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false), OptionSetWriter(&buf))
bar.Describe("performing axial adjustments")
bar.Add(10)
// Output:
// performing axial adjustements 10% |█ | [1s:9s]
rawBuf := strconv.QuoteToASCII(buf.String())
if rawBuf != `"\r\r\rperforming axial adjustments 0% | | [0s:0s]\r \r\rperforming axial adjustments 10% |\u2588 | [0s:0s]"` {
t.Errorf("wrong string: %s", rawBuf)
}
}

0 comments on commit c869815

Please sign in to comment.