Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: console-rs/console
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1315cebeae7237e802118944059ec1a24cea456e
Choose a base ref
..
head repository: console-rs/console
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: edc64e615e7b68dd94ad7159548625ad2b5dacb4
Choose a head ref
Showing with 5 additions and 7 deletions.
  1. +5 −7 src/term.rs
12 changes: 5 additions & 7 deletions src/term.rs
Original file line number Diff line number Diff line change
@@ -434,16 +434,14 @@ impl Term {
clear_line(self)
}

/// Clear the last `n` lines before the current line, if possible.
/// Clear the last `n` lines before the current line.
///
/// Position the cursor at the beginning of the first line that was cleared.
/// Error when `n` is larger than the number of lines before the current cursor.
///
/// **Caution.** When `n` is larger than the number of lines above the
/// current cursor, the top `n` lines are cleared --- including some lines
/// below the cursor.
pub fn clear_last_lines(&self, n: usize) -> io::Result<()> {
let (current_row, _) = get_cursor_position(self)?;
if usize::from(current_row) < n {
// We cannot move up n lines, only current_row ones.
return Err(io::Error::new(io::ErrorKind::Other, format!("can only move up {} lines, not {}", current_row, n)));
}
self.move_cursor_up(n)?;
for _ in 0..n {
self.clear_line()?;