Skip to content

Commit

Permalink
deal with case when label < labelLength
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantmonkey committed Oct 16, 2015
1 parent a4a177b commit e33b607
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 @@ -9,8 +9,8 @@ import (
)

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

Expand Down Expand Up @@ -61,7 +61,11 @@ func (pr *ProgressReader) clearProgress() {
func (pr *ProgressReader) printProgress(n int64) {
percent := float64(n*100) / float64(pr.total)
formatStr := fmt.Sprintf("\r%%-%dv %%7.2f%%%%", labelLength)
fmt.Fprintf(pr.output, formatStr, pr.label[:labelLength], percent)
if len(pr.label) > labelLength {
fmt.Fprintf(pr.output, formatStr, pr.label[:labelLength], percent)
} else {
fmt.Fprintf(pr.output, formatStr, pr.label, percent)
}
}

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

0 comments on commit e33b607

Please sign in to comment.