ok/jj
1
0
Fork 0
forked from mirrors/jj

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.
This commit is contained in:
Gregory Anders 2024-05-30 11:05:21 -05:00 committed by Gregory Anders
parent ec5914c830
commit f4bedf56f6
2 changed files with 6 additions and 1 deletions

View file

@ -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

View file

@ -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(())