shared(prompts): wait for newline on confirmations

pull/92/head
Jake McGinty 2021-05-21 13:02:11 +09:00
parent a140786d53
commit 911a2d8f00
2 changed files with 11 additions and 0 deletions

View File

@ -282,6 +282,7 @@ fn install(
if opts.delete_invite if opts.delete_invite
|| Confirm::with_theme(&*prompts::THEME) || Confirm::with_theme(&*prompts::THEME)
.wait_for_newline(true)
.with_prompt(&format!( .with_prompt(&format!(
"Delete invitation file \"{}\" now? (It's no longer needed)", "Delete invitation file \"{}\" now? (It's no longer needed)",
invite.to_string_lossy().yellow() invite.to_string_lossy().yellow()

View File

@ -47,6 +47,7 @@ pub fn add_cidr(cidrs: &[Cidr], request: &AddCidrOpts) -> Result<Option<CidrCont
Ok( Ok(
if request.yes if request.yes
|| Confirm::with_theme(&*THEME) || Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt(&format!("Create CIDR \"{}\"?", cidr_request.name)) .with_prompt(&format!("Create CIDR \"{}\"?", cidr_request.name))
.default(false) .default(false)
.interact()? .interact()?
@ -84,6 +85,7 @@ pub fn delete_cidr(cidrs: &[Cidr], peers: &[Peer], request: &DeleteCidrOpts) ->
if request.yes if request.yes
|| Confirm::with_theme(&*THEME) || Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt(&format!("Delete CIDR \"{}\"?", cidr.name)) .with_prompt(&format!("Delete CIDR \"{}\"?", cidr.name))
.default(false) .default(false)
.interact()? .interact()?
@ -143,6 +145,7 @@ pub fn add_association(cidrs: &[Cidr]) -> Result<Option<(&Cidr, &Cidr)>, Error>
Ok( Ok(
if Confirm::with_theme(&*THEME) if Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt(&format!( .with_prompt(&format!(
"Add association: {} <=> {}?", "Add association: {} <=> {}?",
cidr1.name.yellow().bold(), cidr1.name.yellow().bold(),
@ -166,6 +169,7 @@ pub fn delete_association<'a>(
Ok( Ok(
if Confirm::with_theme(&*THEME) if Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt(&format!("Delete association #{}?", association.id)) .with_prompt(&format!("Delete association #{}?", association.id))
.default(false) .default(false)
.interact()? .interact()?
@ -226,6 +230,7 @@ pub fn add_peer(
is_admin is_admin
} else { } else {
Confirm::with_theme(&*THEME) Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt(&format!("Make {} an admin?", name)) .with_prompt(&format!("Make {} an admin?", name))
.default(false) .default(false)
.interact()? .interact()?
@ -257,6 +262,7 @@ pub fn add_peer(
Ok( Ok(
if args.yes if args.yes
|| Confirm::with_theme(&*THEME) || Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt(&format!("Create peer {}?", peer_request.name.yellow())) .with_prompt(&format!("Create peer {}?", peer_request.name.yellow()))
.default(false) .default(false)
.interact()? .interact()?
@ -291,6 +297,7 @@ pub fn enable_or_disable_peer(peers: &[Peer], enable: bool) -> Result<Option<Pee
Ok( Ok(
if Confirm::with_theme(&*THEME) if Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt(&format!( .with_prompt(&format!(
"{}able peer {}?", "{}able peer {}?",
if enable { "En" } else { "Dis" }, if enable { "En" } else { "Dis" },
@ -371,6 +378,7 @@ pub fn set_listen_port(
let mut confirmation = Confirm::with_theme(&*THEME); let mut confirmation = Confirm::with_theme(&*THEME);
confirmation confirmation
.wait_for_newline(true)
.with_prompt( .with_prompt(
&(if let Some(port) = &listen_port { &(if let Some(port) = &listen_port {
format!("Set listen port to {}?", port) format!("Set listen port to {}?", port)
@ -394,6 +402,7 @@ pub fn ask_endpoint() -> Result<Endpoint, Error> {
println!("getting external IP address."); println!("getting external IP address.");
let external_ip = if Confirm::with_theme(&*THEME) let external_ip = if Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt("Auto-fill public IP address (using a DNS query to 1.1.1.1)?") .with_prompt("Auto-fill public IP address (using a DNS query to 1.1.1.1)?")
.interact()? .interact()?
{ {
@ -417,6 +426,7 @@ pub fn override_endpoint(unset: bool) -> Result<Option<Option<Endpoint>>, Error>
Ok( Ok(
if Confirm::with_theme(&*THEME) if Confirm::with_theme(&*THEME)
.wait_for_newline(true)
.with_prompt( .with_prompt(
&(if let Some(endpoint) = &endpoint { &(if let Some(endpoint) = &endpoint {
format!("Set external endpoint to {}?", endpoint) format!("Set external endpoint to {}?", endpoint)