author | Alberto Bertogli
<albertito@blitiri.com.ar> 2025-03-15 18:17:21 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2025-03-16 11:41:36 UTC |
parent | c87601c4637a8752394a20c3b3047f8697a1cbe5 |
test/tty.t | +1 | -1 |
ui.go | +13 | -2 |
diff --git a/test/tty.t b/test/tty.t index 8803e3d..5969132 100644 --- a/test/tty.t +++ b/test/tty.t @@ -12,4 +12,4 @@ In this test we force tty output, and check the output is as expected. $ summer -forcetty -n generate . \r (no-eol) (esc) - 0s: 0 matched, 0 modified, 3 new, 0 corrupted + 0s: 0 matched, 0 modified, 3 new, 0 corrupted diff --git a/ui.go b/ui.go index d7f0958..72d228e 100644 --- a/ui.go +++ b/ui.go @@ -101,10 +101,21 @@ func (p *Progress) print(last bool) { p.mu.Lock() defer p.mu.Unlock() + // When outputting to a TTY (where we do \r), we add two spaces at the end + // of each line, as a workaround for when the duration is shorter than the + // previous one, the old characters are still visible. + // + // This can happen in the following situations: + // + // 1m59s: 0 matched, 0 modified, 0 new, 0 corrupted + // 2m0s: 0 matched, 0 modified, 0 new, 0 corruptedd <-- extra 'd' + // 1h59m59s: 0 matched, 0 modified, 0 new, 0 corrupted + // 2h0m0s: 0 matched, 0 modified, 0 new, 0 corrupteded <-- extra 'ed' + prefix := "\r" - suffix := "" + suffix := " " if last { - suffix = "\n" + suffix = " \n" } // Usually we just overwrite the previous line.