Skip to content

Commit

Permalink
Merge pull request #17 from CrushedPixel/master
Browse files Browse the repository at this point in the history
Use the color-transformed string for line width detection
  • Loading branch information
schollz authored Jun 11, 2018
2 parents cc61d3b + 9494f61 commit d90b4c1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,16 @@ func renderProgressBar(c config, s state) (int, error) {
(time.Duration(leftTime) * time.Second).String(),
)

if c.colorCodes {
// convert any color codes in the progress bar into the respective ANSI codes
str = colorstring.Color(str)
}

// the width of the string, if printed to the console
// does not include the carriage return character
cleanString := strings.Replace(str, "\r", "", -1)

if c.colorCodes {
// convert any color codes in the progress bar into the respective ANSI codes
str = colorstring.Color(str)

// the ANSI codes for the colors do not take up space in the console output,
// so they do not count towards the output string width
cleanString = ansiRegex.ReplaceAllString(cleanString, "")
Expand Down

0 comments on commit d90b4c1

Please sign in to comment.