Skip to content

Commit

Permalink
don't show so many parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Apr 3, 2020
1 parent a3f8305 commit 77e36af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
31 changes: 24 additions & 7 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,32 +453,49 @@ func renderProgressBar(c config, s state) (int, error) {

// show rolling average rate in kB/sec or MB/sec
if c.showBytes {
if bytesString == "" {
bytesString += "("
} else {
bytesString += ", "
}
kbPerSecond := averageRate / 1024.0

if kbPerSecond > 1024.0 {
bytesString += fmt.Sprintf("(%2.3f MB/s)", kbPerSecond/1024.0)
bytesString += fmt.Sprintf("%0.3f MB/s", kbPerSecond/1024.0)
} else if kbPerSecond > 0 {
bytesString += fmt.Sprintf("(%2.3f kB/s)", kbPerSecond)
bytesString += fmt.Sprintf("%0.3f kB/s", kbPerSecond)
}
}

// show iteration count in "current/total" iterations format
if c.showIterationsCount {
if bytesString == "" {
bytesString += "("
} else {
bytesString += ", "
}
if !c.ignoreLength {
bytesString += fmt.Sprintf("(%.0f/%d)", s.currentBytes, c.max)
bytesString += fmt.Sprintf("%.0f/%d", s.currentBytes, c.max)
} else {
bytesString += fmt.Sprintf("(%.0f/%s)", s.currentBytes, "-")
bytesString += fmt.Sprintf("%.0f/%s", s.currentBytes, "-")
}
}

// show iterations rate
if c.showIterationsPerSecond {
if bytesString == "" {
bytesString += "("
} else {
bytesString += ", "
}
if averageRate > 1 {
bytesString += fmt.Sprintf("(%2.0f it/s)", averageRate)
bytesString += fmt.Sprintf("%0.0f it/s", averageRate)
} else {
bytesString += fmt.Sprintf("(%2.0f it/min)", 60*averageRate)
bytesString += fmt.Sprintf("%0.0f it/min", 60*averageRate)
}
}
if bytesString != "" {
bytesString += ")"
}

// show time prediction in "current/total" seconds format
if c.predictTime {
Expand Down
4 changes: 2 additions & 2 deletions progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func ExampleOptionShowIts_count() {
time.Sleep(1 * time.Second)
bar.Add(10)
// Output:
// 10% |█ | (10/100)(10 it/s) [1s:9s]
// 10% |█ | (10/100, 10 it/s) [1s:9s]
}

func ExampleOptionShowIts() {
Expand Down Expand Up @@ -140,7 +140,7 @@ func ExampleIgnoreLength_WithIteration() {
bar.Add(5)

// Output:
// 50% | █ | (5/-)( 5 it/s)
// 50% | █ | (5/-, 5 it/s)
}

func ExampleIgnoreLength_WithSpeed() {
Expand Down

0 comments on commit 77e36af

Please sign in to comment.