Skip to content

Commit 3f16c44

Browse files
committed
theme: preserve cursor when clearing multiple lines of input.
After clearing, we want to have the cursor at the beginning of the current line.
1 parent 29da763 commit 3f16c44

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/theme.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,13 @@ impl<'a> TermThemeRenderer<'a> {
839839
})
840840
}
841841

842+
/// Clear the current theme.
843+
///
844+
/// Position the cursor at the beginning of the current line.
842845
pub fn clear(&mut self) -> io::Result<()> {
846+
// We must clear the current line first: `clear_last_lines` places the cursor on the first deleted line,
847+
// whereas we want to have it on the current line.
848+
self.term.clear_line()?;
843849
self.term
844850
.clear_last_lines(self.height + self.prompt_height)?;
845851
self.height = 0;

0 commit comments

Comments
 (0)