Skip to content

Commit

Permalink
progress: cap label length
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantmonkey committed Oct 16, 2015
1 parent 2728673 commit 3456be7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"time"
)

const termWidth = 80
const updateInterval = time.Second / 10
const (
labelLength = 40
termWidth = 80
updateInterval = time.Second / 10
)

var clearBuf = bytes.Repeat([]byte{' '}, termWidth)

Expand Down Expand Up @@ -57,7 +60,8 @@ func (pr *ProgressReader) clearProgress() {

func (pr *ProgressReader) printProgress(n int64) {
percent := float64(n*100) / float64(pr.total)
fmt.Fprintf(pr.output, "\r%-40v %7.2f%%", pr.label, percent)
formatStr := fmt.Sprintf("\r%%-%dv %%7.2f%%%%", labelLength)
fmt.Fprintf(pr.output, formatStr, pr.label[:labelLength], percent)
}

func (pr *ProgressReader) update() {
Expand Down

0 comments on commit 3456be7

Please sign in to comment.