Skip to content

Commit

Permalink
chore: replace custom prompt with 'dialoguer' (#4611)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmih authored Aug 7, 2024
1 parent 1ab228c commit 948da67
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/cli/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ pub(super) fn print_rpc_res_bytes(obj: Vec<u8>) -> anyhow::Result<()> {
Ok(())
}

/// Require user confirmation. Returns `false` when not connected to a terminal.
pub fn prompt_confirm() -> bool {
print!("Do you want to continue? [y/n] ");
std::io::stdout().flush().unwrap();
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
let line = line.trim().to_lowercase();
line == "y" || line == "yes"
let term = dialoguer::console::Term::stderr();

if !term.is_term() {
return false;
}

dialoguer::Confirm::new()
.with_prompt("Do you want to continue?")
.interact_on(&term)
.unwrap_or(false)
}

0 comments on commit 948da67

Please sign in to comment.