diff --git a/src/prompts/confirm.rs b/src/prompts/confirm.rs index 328f792f..7cebfaf4 100644 --- a/src/prompts/confirm.rs +++ b/src/prompts/confirm.rs @@ -210,8 +210,8 @@ impl Confirm<'_> { continue; } }; - - term.clear_line()?; + // Since `prompt` may be a multi-line string, we clear the entire prompt and not just the current line. + render.clear()?; render.confirm_prompt(&self.prompt, value)?; } } else { @@ -234,7 +234,8 @@ impl Confirm<'_> { } } - term.clear_line()?; + // Since `prompt` may be a multi-line string, we clear the entire prompt and not just the current line. + render.clear()?; if self.report { render.confirm_prompt_selection(&self.prompt, rv)?; } diff --git a/src/prompts/input.rs b/src/prompts/input.rs index 3c85469b..d2ebc945 100644 --- a/src/prompts/input.rs +++ b/src/prompts/input.rs @@ -401,7 +401,6 @@ where } let input = chars.iter().collect::(); - term.clear_line()?; render.clear()?; if chars.is_empty() { @@ -494,7 +493,6 @@ where }; render.add_line(); - term.clear_line()?; render.clear()?; if input.is_empty() { diff --git a/src/theme.rs b/src/theme.rs index 43ea7a01..b3917902 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -839,9 +839,16 @@ impl<'a> TermThemeRenderer<'a> { }) } + /// Clear the current theme. + /// + /// Position the cursor at the beginning of the current line. pub fn clear(&mut self) -> io::Result<()> { + // clear the current line first, so the cursor ends at the beginning of the current line. + self.term.clear_line()?; self.term .clear_last_lines(self.height + self.prompt_height)?; + // self.term now contains self.height + self.prompt_height empty lines after + // the current line. That doesn't really matter, as these are empty. self.height = 0; Ok(()) }