Skip to content

Commit

Permalink
cli: clear line after writing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gpanders committed May 30, 2024
1 parent ec5914c commit f4bedf5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cli/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(())
Expand Down

0 comments on commit f4bedf5

Please sign in to comment.