console-rs / dialoguer

Rust utility library for nice command line prompts and similar things
MIT License
1.33k stars 142 forks source link

Confirmation prompt: non-last line of multiline strings get printed twice #165

Open grunweg opened 2 years ago

grunweg commented 2 years ago

Thanks for this crate, by the way. I could insert a simple terminal prompt without knowing too much about terminals!

Steps to reproduce. Take this small test programm.

[package]
name = "dialoguer-bug"
version = "0.1.0"
edition = "2021"
[dependencies]
dialoguer = "0.9.0"

$ cat src/main.rs
fn main() {
    let _ = dialoguer::Confirm::new().with_prompt("Prompt string with multiple lines:\nLine two?").interact().map_err(|e| e.to_string());
}
  1. Build and run the programm: cargo r
  2. A confirmation prompt appears:

    Prompt string with multiple lines: Line two?

  3. Answer either yes or no (doesn't matter which).
  4. My answer is displayed in the terminal.

Expected result The terminal output looks like this:

Prompt string with multiple lines: Line two yes

Actual result The prompt is printed twice, resulting in output like this.

Prompt string with multiple lines: Prompt string with multiple lines: Line two yes

Meta. Tested on both version 0.9 and 0.8 of dialoguer.

grunweg commented 2 years ago

I've played with this a bit and have a theory for the bug. I think the issue is that my prompt string has multiple lines: All lines but the first line get printed to the terminal. Taking a string with three lines results in the last two lines being printed twice.