@@ -618,8 +618,34 @@ impl Terminal {
term.resize(new_size);
}
InternalEvent::Clear => {
- self.write_to_pty("\x0c".to_string());
+ // Clear back buffer
term.clear_screen(ClearMode::Saved);
+
+ let cursor = term.grid().cursor.point;
+
+ // Clear the lines above
+ term.grid_mut().reset_region(..cursor.line);
+
+ // Copy the current line up
+ let line = term.grid()[cursor.line][..cursor.column]
+ .iter()
+ .cloned()
+ .enumerate()
+ .collect::<Vec<(usize, Cell)>>();
+
+ for (i, cell) in line {
+ term.grid_mut()[Line(0)][Column(i)] = cell;
+ }
+
+ // Reset the cursor
+ term.grid_mut().cursor.point =
+ Point::new(Line(0), term.grid_mut().cursor.point.column);
+ let new_cursor = term.grid().cursor.point;
+
+ // Clear the lines below the new cursor
+ if (new_cursor.line.0 as usize) < term.screen_lines() - 1 {
+ term.grid_mut().reset_region((new_cursor.line + 1)..);
+ }
}
InternalEvent::Scroll(scroll) => {
term.scroll_display(*scroll);
@@ -680,12 +680,12 @@ impl Element for TerminalElement {
let focused = self.focused;
TerminalElement::shape_cursor(cursor_point, dimensions, &cursor_text).map(
move |(cursor_position, block_width)| {
- let shape = match cursor.shape {
- AlacCursorShape::Block if !focused => CursorShape::Hollow,
- AlacCursorShape::Block => CursorShape::Block,
- AlacCursorShape::Underline => CursorShape::Underscore,
- AlacCursorShape::Beam => CursorShape::Bar,
- AlacCursorShape::HollowBlock => CursorShape::Hollow,
+ let (shape, text) = match cursor.shape {
+ AlacCursorShape::Block if !focused => (CursorShape::Hollow, None),
+ AlacCursorShape::Block => (CursorShape::Block, Some(cursor_text)),
+ AlacCursorShape::Underline => (CursorShape::Underscore, None),
+ AlacCursorShape::Beam => (CursorShape::Bar, None),
+ AlacCursorShape::HollowBlock => (CursorShape::Hollow, None),
//This case is handled in the if wrapping the whole cursor layout
AlacCursorShape::Hidden => unreachable!(),
};
@@ -696,7 +696,7 @@ impl Element for TerminalElement {
dimensions.line_height,
terminal_theme.colors.cursor,
shape,
- Some(cursor_text),
+ text,
)
},
)