Skip to content

Commit

Permalink
Don't add an extra line after the progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd authored and djc committed Dec 30, 2021
1 parent 0626585 commit e46ca83
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/draw_target.rs
Expand Up @@ -173,7 +173,7 @@ impl ProgressDrawTarget {
if !draw_state.lines.is_empty() && draw_state.move_cursor {
term.move_cursor_up(*last_line_count)?;
} else {
term.clear_last_lines(*last_line_count)?;
clear_last_lines(term, *last_line_count)?;
}

let shift = match draw_state.alignment {
Expand Down Expand Up @@ -389,8 +389,14 @@ impl ProgressDrawState {
}

pub fn draw_to_term(&self, term: &Term) -> io::Result<()> {
for line in &self.lines {
term.write_line(line)?;
let len = self.lines.len();
for (idx, line) in self.lines.iter().enumerate() {
if idx + 1 != len {
term.write_line(line)?;
} else {
// Don't append a '\n' if this is the last line
term.write_str(line)?;
}
}
Ok(())
}
Expand Down Expand Up @@ -423,3 +429,16 @@ impl Default for MultiProgressAlignment {
Self::Top
}
}

/// Fork of console::clear_last_lines that assumes that the last line doesn't contain a '\n'
fn clear_last_lines(term: &Term, n: usize) -> io::Result<()> {
term.move_cursor_up(n.saturating_sub(1))?;
for i in 0..n {
term.clear_line()?;
if i + 1 != n {
term.move_cursor_down(1)?;
}
}
term.move_cursor_up(n.saturating_sub(1))?;
Ok(())
}

0 comments on commit e46ca83

Please sign in to comment.