From 535af36bab3ee406c5702471adee9a5812c54bc5 Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Mon, 25 Jul 2022 14:57:01 +1000 Subject: [PATCH] Remove superfluous carriage returns --- progressbar.go | 5 ++++- progressbar_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/progressbar.go b/progressbar.go index b67bb5b..8773acf 100644 --- a/progressbar.go +++ b/progressbar.go @@ -839,6 +839,9 @@ 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") @@ -846,7 +849,7 @@ func clearProgressBar(c config, s state) error { // 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") diff --git a/progressbar_test.go b/progressbar_test.go index af5b315..829af8c 100644 --- a/progressbar_test.go +++ b/progressbar_test.go @@ -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) } }