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

@ -19,7 +19,7 @@ $ cargo binstall radio-sx128x@0.14.1-alpha.5
WARN The package radio-sx128x v0.14.1-alpha.5 (x86_64-unknown-linux-gnu) has been downloaded from github.com WARN The package radio-sx128x v0.14.1-alpha.5 (x86_64-unknown-linux-gnu) has been downloaded from github.com
INFO This will install the following binaries: INFO This will install the following binaries:
INFO - sx128x-util (sx128x-util-x86_64-unknown-linux-gnu -> /home/.cargo/bin/sx128x-util) INFO - sx128x-util (sx128x-util-x86_64-unknown-linux-gnu -> /home/.cargo/bin/sx128x-util)
Do you wish to continue? yes/[no] Do you wish to continue? [yes]/no
? yes ? yes
INFO Installing binaries... INFO Installing binaries...
INFO Done in 2.838798298s INFO Done in 2.838798298s

View file

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