10000 fix: also reset self.prompt_height in `TermThemeRenderer::clear`. by grunweg · Pull Request #191 · console-rs/dialoguer · GitHub
[go: up one dir, main page]

Skip to content

fix: also reset self.prompt_height in TermThemeRenderer::clear. #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2023

Conversation

grunweg
Copy link
Contributor
@grunweg grunweg commented May 6, 2022

This appears like an oversight: we clear the last self.height+self.prompt_height lines from the output; we set height to 0, but not prompt_height. We should also reset prompt_height.

This can cause issues if we were to call clear() twice in a row: we would clear prompt_height lines more than we should.

Otherwise, calling clear the next time will call prompt_height lines too many.
@grunweg
Copy link
Contributor Author
grunweg commented May 6, 2022

There's a simple "manual test case": apply the following patch on top of the change and execute any confirmation prompt.

diff --git a/src/prompts/confirm.rs b/src/prompts/confirm.rs
--- a/src/prompts/confirm.rs
+++ b/src/prompts/confirm.rs
@@ -237,6 +237,10 @@ impl Confirm<'_> {
         term.clear_line()?;
         if self.report {
             render.confirm_prompt_selection(&self.prompt, rv)?;
+            render.clear()?;
+            render.clear()?;
+            render.confirm_prompt_selection(&self.prompt, rv)?;
+
         }
         term.show_cursor()?;
         term.flush()?;
diff --git a/src/theme.rs b/src/theme.rs
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -843,7 +843,7 @@ impl<'a> TermThemeRenderer<'a> {
         self.term
             .clear_last_lines(self.height + self.prompt_height)?;
         self.height = 0;
-        self.prompt_height = 0;
+        //self.prompt_height = 0;
         Ok(())
     }

Run a simple prompt, e.g. the following (in a crate with dialoguer as dependency)

fn main() -> std::io::Result<()> {
    dialoguer::Confirm::new().with_prompt("prompt string").interact()?;
}

Actual behaviour. The prompt string and lines before it are cleared. Making the prompt string longer exerbates this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0