From f4bedf56f65ab3121f83f4104d58ca20fda31d05 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Thu, 30 May 2024 11:05:21 -0500 Subject: [PATCH] cli: clear line after writing Clear the rest of the cursor line (from the cursor to the end of the row) after drawing the progress bar rather than clearing the entire line before drawing. This reduces flickering on terminal emulators which are able to redraw rapidly. --- CHANGELOG.md | 4 ++++ cli/src/progress.rs | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cde4f35b..bfd9ce82a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,10 @@ to avoid letting the user edit the immutable one. * Files with conflicts are now checked out as executable if all sides of the conflict are executable. +* The progress bar (visible when using e.g. `jj git clone`) clears the + remainder of the cursor row after drawing rather than clearing the entire row + before drawing, eliminating the "flicker" effect seen on some terminals. + ## [0.17.1] - 2024-05-07 ### Fixed bugs diff --git a/cli/src/progress.rs b/cli/src/progress.rs index 476a6c931..e67b5e88a 100644 --- a/cli/src/progress.rs +++ b/cli/src/progress.rs @@ -60,7 +60,7 @@ impl Progress { self.next_print = now.min(self.next_print + Duration::from_secs(1) / UPDATE_HZ); self.buffer.clear(); - write!(self.buffer, "\r{}", Clear(ClearType::CurrentLine)).unwrap(); + write!(self.buffer, "\r").unwrap(); let control_chars = self.buffer.len(); write!(self.buffer, "{: >3.0}% ", 100.0 * progress.overall).unwrap(); if let Some(total) = progress.bytes_downloaded { @@ -81,6 +81,7 @@ impl Progress { draw_progress(progress.overall, &mut self.buffer, bar_width); self.buffer.push(']'); + write!(self.buffer, "{}", Clear(ClearType::UntilNewLine)).unwrap(); write!(output, "{}", self.buffer)?; output.flush()?; Ok(())