Skip to content

Commit

Permalink
Merge pull request #127 from NathanBaulch/superfluous-carriage-returns
Browse files Browse the repository at this point in the history
Remove superfluous carriage returns
  • Loading branch information
schollz committed Jul 31, 2022
2 parents 4ded600 + 535af36 commit 134ade7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion progressbar.go
Expand Up @@ -839,14 +839,17 @@ func renderProgressBar(c config, s *state) (int, error) {
}

func clearProgressBar(c config, s state) error {
if s.maxLineWidth == 0 {
return nil
}
if c.useANSICodes {
// write the "clear current line" ANSI escape sequence
return writeString(c, "\033[2K\r")
}
// fill the empty content
// to overwrite the progress bar and jump
// back to the beginning of the line
str := fmt.Sprintf("\r%s\r", strings.Repeat(" ", s.maxLineWidth))
str := fmt.Sprintf("\r%s", strings.Repeat(" ", s.maxLineWidth))
return writeString(c, str)
// the following does not show correctly if the previous line is longer than subsequent line
// return writeString(c, "\r")
Expand Down
2 changes: 1 addition & 1 deletion progressbar_test.go
Expand Up @@ -579,7 +579,7 @@ func TestProgressBar_Describe(t *testing.T) {
bar.Describe("performing axial adjustments")
bar.Add(10)
rawBuf := strconv.QuoteToASCII(buf.String())
if rawBuf != `"\r\r\rperforming axial adjustments 0% | | [0s:0s]\r \r\rperforming axial adjustments 10% |\u2588 | [0s:0s]"` {
if rawBuf != `"\rperforming axial adjustments 0% | | [0s:0s]\r \rperforming axial adjustments 10% |\u2588 | [0s:0s]"` {
t.Errorf("wrong string: %s", rawBuf)
}
}

0 comments on commit 134ade7

Please sign in to comment.