Yes/NO defaults to "no" when just enter is pressed (#1948)

* yes/NO in interface

* Implement No as default (when only Enter is pressed)

* Update README.md

Mark the default as [yes]

Signed-off-by: pepa65 <pepa65@passchier.net>

* Update ui.rs

Mark the default as [yes]

Signed-off-by: pepa65 <pepa65@passchier.net>

* Update ui.rs

Do not break on yes/y/YES/Y/"", break on no/n/NO/N, and keep asking otherwise

Signed-off-by: pepa65 <pepa65@passchier.net>

* Update ui.rs

After testing empty didn't work correctly

Signed-off-by: pepa65 <pepa65@passchier.net>

---------

Signed-off-by: pepa65 <pepa65@passchier.net>
This commit is contained in:
pepa65 2024-10-30 20:00:56 +07:00 committed by GitHub
parent e704abe7ac
commit 81a8218794
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -10,7 +10,7 @@ fn ask_for_confirm(stdin: &mut StdinLock, input: &mut String) -> io::Result<()>
{
let mut stdout = io::stdout().lock();
write!(&mut stdout, "Do you wish to continue? yes/[no]\n? ")?;
write!(&mut stdout, "Do you wish to continue? [yes]/no\n? ")?;
stdout.flush()?;
}
@ -34,8 +34,8 @@ pub async fn confirm() -> Result<(), BinstallError> {
}
match input.as_str().trim() {
"yes" | "y" | "YES" | "Y" => break true,
"no" | "n" | "NO" | "N" | "" => break false,
"yes" | "y" | "YES" | "Y" | "" => break true,
"no" | "n" | "NO" | "N" => break false,
_ => {
input.clear();
continue;