From 8140335eb7b7b39f235dbd6559f52cbe7b163591 Mon Sep 17 00:00:00 2001 From: Omer Tuchfeld Date: Sat, 22 Feb 2025 13:16:39 +0100 Subject: [PATCH] Confirmation prompt terminal width The confirmation prompt should take into account the terminal's width in relation to the prompt width when clearing the last line(s). See recording showing before and after: https://asciinema.org/a/wW9IyNYeOT22m9iIH5OPmTki9 --- src/prompts/confirm.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/prompts/confirm.rs b/src/prompts/confirm.rs index 8ff126f..7d6ce65 100644 --- a/src/prompts/confirm.rs +++ b/src/prompts/confirm.rs @@ -163,7 +163,7 @@ impl Confirm<'_> { None }; - render.confirm_prompt(&self.prompt, default_if_show)?; + let mut prompt_width = render.confirm_prompt(&self.prompt, default_if_show)?; term.hide_cursor()?; term.flush()?; @@ -204,8 +204,15 @@ impl Confirm<'_> { } }; - term.clear_line()?; - render.confirm_prompt(&self.prompt, value)?; + let term_width = term.size().1 as usize; + if prompt_width > term_width { + let lines = prompt_width / term_width; + term.clear_last_lines(lines)?; + } else { + term.clear_line()?; + } + + prompt_width = render.confirm_prompt(&self.prompt, value)?; } } else { // Default behavior: matches continuously on every keystroke,