From 188b775fa6a21ec3c91f6e524b1e0990f74b3b56 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 7 Oct 2022 10:03:09 -0700 Subject: [PATCH 1/3] Fixed non-block terminal cursors being displayed incorrectly --- crates/terminal/src/terminal_element.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/terminal/src/terminal_element.rs b/crates/terminal/src/terminal_element.rs index e7fd69fe49bdfff3ebaa462343f2283821cfaa8f..0f037863af38dd50317fd2bf09c315e11a1971e0 100644 --- a/crates/terminal/src/terminal_element.rs +++ b/crates/terminal/src/terminal_element.rs @@ -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, ) }, ) From bf50a8ad8e6d0e01c713e32908036c3404b46ba4 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 7 Oct 2022 11:37:39 -0700 Subject: [PATCH 2/3] Implemented a simplistic version of correct cmd-k behavior --- crates/terminal/src/terminal.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 473bbd4f52aa2ebbf4885830cded6d44252fa75c..b86043b122cfe1d8c593f17ad33882b62ff2c454 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -618,8 +618,11 @@ impl Terminal { term.resize(new_size); } InternalEvent::Clear => { - self.write_to_pty("\x0c".to_string()); term.clear_screen(ClearMode::Saved); + + term.clear_screen(ClearMode::All); + + term.grid_mut().cursor.point = Point::new(Line(0), Column(0)); } InternalEvent::Scroll(scroll) => { term.scroll_display(*scroll); From 15595a67faafd1ca68bd01631d9164c1fc6fba5e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 7 Oct 2022 12:04:26 -0700 Subject: [PATCH 3/3] Added a horrible hacky way of doing cmd-k correctly. --- crates/terminal/src/terminal.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index b86043b122cfe1d8c593f17ad33882b62ff2c454..004815a510a143b74fc32d8f4a953dd390658650 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -618,11 +618,34 @@ impl Terminal { term.resize(new_size); } InternalEvent::Clear => { + // Clear back buffer term.clear_screen(ClearMode::Saved); - term.clear_screen(ClearMode::All); + let cursor = term.grid().cursor.point; - term.grid_mut().cursor.point = Point::new(Line(0), Column(0)); + // 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::>(); + + 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);