console-rs / dialoguer

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

Idea: if prompt is unchanged from `with_initial_text`, then use `default` #225

Closed alpha-tango-kilo closed 1 year ago

alpha-tango-kilo commented 1 year ago

Sample code:

let answer = Input::<String>::new()
    .with_prompt("What are you getting paid?")
    .with_initial_text("£")
    .default(Default::default())
    .interact_text()?;

Input: press enter as soon as the prompt appears

Actual outcome:

assert_eq!("£", answer.as_str());

Suggested outcome:

assert_eq!("", answer.as_str());

Should be possible with a check for the input (before any type conversion) is equal to the initial text

Would you be open to a PR for this? I appreciate it's a behaviour change so could be considered breaking

pksunkara commented 1 year ago

It's intentional. Documentation has this line:

Sets initial text that user can accept or erase.