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

Code before:
        trace!("Clearing line: {:?}", mode);

        let cursor = self.grid.cursor;
        match mode {
            ansi::LineClearMode::Right => {
                let row = &mut self.grid[cursor.point.line];
                for cell in &mut row[cursor.point.col..] {
                    cell.reset(&cursor.template);
                }
            },
            ansi::LineClearMode::Left => {
                let row = &mut self.grid[cursor.point.line];
                for cell in &mut row[..=cursor.point.col] {
                    cell.reset(&cursor.template);
                }
            },
            ansi::LineClearMode::All => {
                let row = &mut self.grid[cursor.point.line];
                for cell in &mut row[..] {
                    cell.reset(&cursor.template);
                }
            },
        }

        let buffer_cursor = self.grid.buffer_cursor().line;
        if let Some(true) = self.selection.as_ref().map(|s| s.contains_line(buffer_cursor)) {
            self.selection = None;
        }
    }

    /// Set the indexed color value.
    #[inline]
    fn set_color(&mut self, index: usize, color: Rgb) {
        trace!("Setting color[{}] = {:?}", index, color);
        self.colors[index] = color;
        self.color_modified[index] = true;
    }

    /// Write a foreground/background color escape sequence with the current color.
    #[inline]
    fn dynamic_color_sequence<W: io::Write>(
        &mut self,
        writer: &mut W,
        code: u8,
        index: usize,
        terminator: &str,
    ) {
        trace!("Writing escape sequence for dynamic color code {}: color[{}]", code, index);
        let color = self.colors[index];
        let response = format!(
            "\x1b]{};rgb:{1:02x}{1:02x}/{2:02x}{2:02x}/{3:02x}{3:02x}{4}",

Review comment (suggestion):
```suggestion
        if self.selection.as_ref().map(|s| s.contains_line(buffer_cursor)) == Some(true) {
```

Just a good bit shorter than using `if let`.

The following is probably even better though:

```suggestion
self.selection = self.selection.take().filter(|s| !s.contains_line(buffer_cursor));
```

This applies to all the `if let` blocks in this PR, I think that would significantly clean things up.

Code after:
        trace!("Clearing line: {:?}", mode);

        let cursor = self.grid.cursor;
        match mode {
            ansi::LineClearMode::Right => {
                let row = &mut self.grid[cursor.point.line];
                for cell in &mut row[cursor.point.col..] {
                    cell.reset(&cursor.template);
                }
            },
            ansi::LineClearMode::Left => {
                let row = &mut self.grid[cursor.point.line];
                for cell in &mut row[..=cursor.point.col] {
                    cell.reset(&cursor.template);
                }
            },
            ansi::LineClearMode::All => {
                let row = &mut self.grid[cursor.point.line];
                for cell in &mut row[..] {
                    cell.reset(&cursor.template);
                }
            },
        }

        let cursor_buffer_line = self.grid.cursor_buffer_point().line;
        self.selection = self
            .selection
            .take()
            .filter(|s| !s.intersects_range(cursor_buffer_line..=cursor_buffer_line));
    }

    /// Set the indexed color value.
    #[inline]
    fn set_color(&mut self, index: usize, color: Rgb) {
        trace!("Setting color[{}] = {:?}", index, color);
        self.colors[index] = color;
        self.color_modified[index] = true;
    }

    /// Write a foreground/background color escape sequence with the current color.
    #[inline]
    fn dynamic_color_sequence<W: io::Write>(
        &mut self,
        writer: &mut W,
        code: u8,
        index: usize,
        terminator: &str,
    ) {
        trace!("Writing escape sequence for dynamic color code {}: color[{}]", code, index);
        let color = self.colors[index];
        let response = format!(