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

Code before:
        let size = SizeInfo::new(21.0, 51.0, 3.0, 3.0, 0.0, 0.0, false);
        let mut term = Term::new(&MockConfig::default(), size, ());
        let cursor = Point::new(Line(0), Column(0));
        term.configure_charset(CharsetIndex::G0, StandardCharset::SpecialCharacterAndLineDrawing);
        term.input('a');

        assert_eq!(term.grid()[cursor].c, '▒');
    }

    #[test]
    fn clear_viewport_updates_vi_mode_cursor_pos() {
        let size = SizeInfo::new(10.0, 20.0, 1.0, 1.0, 0.0, 0.0, false);
        let mut term = Term::new(&MockConfig::default(), size, ());

        // Create 10 lines of scrollback.
        for _ in 0..29 {
            term.newline();
        }

        // Emulate vi cursor motions on default configurations.
        // gg
        term.scroll_display(Scroll::Top);
        term.vi_mode_cursor = term.vi_mode_cursor.scroll(&term, 10);
        // jjjjj
        for _ in 0..5 {
            term.vi_mode_cursor = term.vi_mode_cursor.motion(&mut term, ViMotion::Down);
        }
        // lll
        for _ in 0..3 {
            term.vi_mode_cursor = term.vi_mode_cursor.motion(&mut term, ViMotion::Right);
        }

        // Clear the viewport.
        term.clear_screen(ansi::ClearMode::All);

        assert_eq!(term.vi_mode_cursor.point.line.0, 5);
        assert_eq!(term.vi_mode_cursor.point.column.0, 3);
    }

    #[test]
    fn clear_saved_lines() {
        let size = SizeInfo::new(21.0, 51.0, 3.0, 3.0, 0.0, 0.0, false);
        let mut term = Term::new(&MockConfig::default(), size, ());

        // Add one line of scrollback.
        term.grid.scroll_up(&(Line(0)..Line(1)), 1);

        // Clear the history.
        term.clear_screen(ansi::ClearMode::Saved);

        // Make sure that scrolling does not change the grid.

Review comment (suggestion):
```suggestion
        // Clear the viewport and scrollback.
        term.clear_screen(ansi::ClearMode::All);
```

Kinda the point that we're not just clearing the viewport.

Code after:
    fn input_line_drawing_character() {
        let size = SizeInfo::new(21.0, 51.0, 3.0, 3.0, 0.0, 0.0, false);
        let mut term = Term::new(&Config::default(), size, ());
        let cursor = Point::new(Line(0), Column(0));
        term.configure_charset(CharsetIndex::G0, StandardCharset::SpecialCharacterAndLineDrawing);
        term.input('a');

        assert_eq!(term.grid()[cursor].c, '▒');
    }

    #[test]
    fn clear_viewport_set_vi_cursor_into_viewport() {
        let size = SizeInfo::new(10.0, 20.0, 1.0, 1.0, 0.0, 0.0, false);
        let mut term = Term::new(&Config::default(), size, ());

        // Create 10 lines of scrollback.
        for _ in 0..29 {
            term.newline();
        }

        // Change the display area and the vi cursor position.
        term.scroll_display(Scroll::Top);
        term.vi_mode_cursor.point = Point::new(Line(-5), Column(3));

        // Clear the viewport.
        term.clear_screen(ansi::ClearMode::All);

        assert_eq!(term.grid.display_offset(), 0);
        assert_eq!(term.vi_mode_cursor.point.line.0, 0);
        assert_eq!(term.vi_mode_cursor.point.column.0, 3);
    }

    #[test]
    fn clear_scrollback_set_vi_cursor_into_viewport() {
        let size = SizeInfo::new(10.0, 20.0, 1.0, 1.0, 0.0, 0.0, false);
        let mut term = Term::new(&Config::default(), size, ());

        // Create 10 lines of scrollback.
        for _ in 0..29 {
            term.newline();
        }

        // Change the display area and the vi cursor position.
        term.scroll_display(Scroll::Top);
        term.vi_mode_cursor.point = Point::new(Line(-5), Column(3));

        // Clear the scrollback buffer.
        term.clear_screen(ansi::ClearMode::Saved);

        assert_eq!(term.grid.display_offset(), 0);
        assert_eq!(term.vi_mode_cursor.point.line.0, 0);