mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Fix panic in ui::confirm
on I/O error (#576)
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
d64710d3a6
commit
d63e001d6f
1 changed files with 16 additions and 8 deletions
|
@ -1,11 +1,24 @@
|
|||
use std::{
|
||||
io::{self, BufRead, Write},
|
||||
io::{self, BufRead, StdinLock, Write},
|
||||
thread,
|
||||
};
|
||||
|
||||
use binstalk::errors::BinstallError;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
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? ")?;
|
||||
stdout.flush()?;
|
||||
}
|
||||
|
||||
stdin.read_line(input)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn confirm() -> Result<(), BinstallError> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
|
@ -16,15 +29,10 @@ pub async fn confirm() -> Result<(), BinstallError> {
|
|||
let mut input = String::with_capacity(16);
|
||||
|
||||
let res = loop {
|
||||
{
|
||||
let mut stdout = io::stdout().lock();
|
||||
|
||||
write!(&mut stdout, "Do you wish to continue? yes/[no]\n? ").unwrap();
|
||||
stdout.flush().unwrap();
|
||||
if ask_for_confirm(&mut stdin, &mut input).is_err() {
|
||||
break false;
|
||||
}
|
||||
|
||||
stdin.read_line(&mut input).unwrap();
|
||||
|
||||
match input.as_str().trim() {
|
||||
"yes" | "y" | "YES" | "Y" => break true,
|
||||
"no" | "n" | "NO" | "N" | "" => break false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue