From c4fdc9c055f807fc0104350a7594dca3748e43ec Mon Sep 17 00:00:00 2001 From: Mike Grunweg Date: Mon, 14 Feb 2022 19:44:08 +0100 Subject: [PATCH 1/3] theme.clear(): also clear the current line. This was a simple oversight in the code. Make sure to preserve the cursor at the beginning of the current line. --- src/theme.rs | 7 +++++++ 1 file changed, 7 insertions(+) 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(()) } From c0575d171111c09dbf26194a39bd926c5c3f201f Mon Sep 17 00:00:00 2001 From: Mike Grunweg Date: Mon, 14 Feb 2022 19:44:43 +0100 Subject: [PATCH 2/3] confirm: properly clear the terminal in case of a multi-line prompt string. --- src/prompts/confirm.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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)?; } From 1be630ad77b33a43796ff695e4f135cf349b09f0 Mon Sep 17 00:00:00 2001 From: Mike Grunweg Date: Fri, 6 May 2022 10:25:25 +0200 Subject: [PATCH 3/3] Remove clear_line() calls preceding TermThemeRenderer.clear() in the input prompt. With TermThemeRenderer.clear() also clearing the current line, they have become superfluous. --- src/prompts/input.rs | 2 -- 1 file changed, 2 deletions(-) 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() {