Repository: alacritty/alacritty
File: alacritty_terminal/src/term/mod.rs (Rust)

Code before:
    /// Load data from clipboard.
    #[inline]
    fn clipboard_load(&mut self, clipboard: u8, terminator: &str) {
        let clipboard_type = match clipboard {
            b'c' => ClipboardType::Clipboard,
            b'p' | b's' => ClipboardType::Selection,
            _ => return,
        };

        let terminator = terminator.to_owned();

        self.event_proxy.send_event(Event::ClipboardLoad(
            clipboard_type,
            Arc::new(move |text| {
                let base64 = base64::encode(&text);
                format!("\x1b]52;{};{}{}", clipboard as char, base64, terminator)
            }),
        ));
    }

    #[inline]
    fn clear_screen(&mut self, mode: ansi::ClearMode) {
        trace!("Clearing screen: {:?}", mode);
        let template = self.grid.cursor.template;

        let num_lines = self.grid.num_lines().0 - 1;
        let buffer_cursor_line = self.grid.buffer_cursor_point().line;

        match mode {
            ansi::ClearMode::Above => {
                let cursor = self.grid.cursor.point;

                // If clearing more than one line.
                if cursor.line > Line(1) {
                    // Fully clear all lines before the current line.
                    self.grid.region_mut(..cursor.line).each(|cell| cell.reset(&template));
                }

                // Clear up to the current column in the current line.
                let end = min(cursor.col + 1, self.grid.num_cols());
                for cell in &mut self.grid[cursor.line][..end] {
                    cell.reset(&template);
                }

                self.selection = self
                    .selection
                    .take()
                    .filter(|s| !s.intersects_range(buffer_cursor_line..=num_lines));
            },
            ansi::ClearMode::Below => {
                let cursor = self.grid.cursor.point;

Review comment (suggestion):
```suggestion
        let last_line = self.num_lines().0 - 1;
```

We shouldn't name things `num_lines` when we subtract one to represent the last line.

Alternatively `last_visible_line` would be even more clear.

Code after:
            b'c' => ClipboardType::Clipboard,
            b'p' | b's' => ClipboardType::Selection,
            _ => return,
        };

        let terminator = terminator.to_owned();

        self.event_proxy.send_event(Event::ClipboardLoad(
            clipboard_type,
            Arc::new(move |text| {
                let base64 = base64::encode(&text);
                format!("\x1b]52;{};{}{}", clipboard as char, base64, terminator)
            }),
        ));
    }

    #[inline]
    fn clear_screen(&mut self, mode: ansi::ClearMode) {
        trace!("Clearing screen: {:?}", mode);
        let template = self.grid.cursor.template;

        let num_lines = self.grid.num_lines().0;
        let cursor_buffer_line = self.grid.cursor_buffer_point().line;

        match mode {
            ansi::ClearMode::Above => {
                let cursor = self.grid.cursor.point;

                // If clearing more than one line.
                if cursor.line > Line(1) {
                    // Fully clear all lines before the current line.
                    self.grid.region_mut(..cursor.line).each(|cell| cell.reset(&template));
                }

                // Clear up to the current column in the current line.
                let end = min(cursor.col + 1, self.grid.num_cols());
                for cell in &mut self.grid[cursor.line][..end] {
                    cell.reset(&template);
                }

                self.selection = self
                    .selection
                    .take()
                    .filter(|s| !s.intersects_range(cursor_buffer_line..num_lines));
            },
            ansi::ClearMode::Below => {
                let cursor = self.grid.cursor.point;
                for cell in &mut self.grid[cursor.line][cursor.col..] {
                    cell.reset(&template);
                }