Skip to content

Commit

Permalink
Inline single-use function
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Feb 3, 2022
1 parent b0d5aad commit 8b1a481
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/draw_target.rs
Expand Up @@ -464,7 +464,16 @@ impl ProgressDrawState {
if !self.lines.is_empty() && self.move_cursor {
term.move_cursor_up(*last_line_count)?;
} else {
clear_last_lines(term, *last_line_count)?;
// Fork of console::clear_last_lines that assumes that the last line doesn't contain a '\n'
let n = *last_line_count;
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))?;
}

let shift = match self.alignment {
Expand Down Expand Up @@ -533,16 +542,3 @@ 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 8b1a481

Please sign in to comment.