Skip to content

Commit

Permalink
Improve login (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
Milo123459 authored Nov 17, 2023
1 parent 1e7d13e commit 0bd1444
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/commands/login.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{net::SocketAddr, time::Duration};

use crate::{consts::TICK_STRING, interact_or, util::prompt::prompt_confirm_with_default};
use crate::{
consts::TICK_STRING, interact_or, util::prompt::prompt_confirm_with_default_with_cancel,
};

use super::*;

Expand Down Expand Up @@ -29,9 +31,13 @@ pub async fn command(args: Args, _json: bool) -> Result<()> {
return browserless_login().await;
}

let confirm = prompt_confirm_with_default("Open the browser?", true)?;
let confirm = prompt_confirm_with_default_with_cancel("Open the browser?", true)?;

if !confirm {
if let Some(confirm) = confirm {
if !confirm {
return browserless_login().await;
}
} else {
return Ok(());
}

Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ impl Configs {
.with_attr(Attributes::BOLD),
),
)
.with_canceled_prompt_indicator(
Styled::new("<cancelled>").with_fg(inquire::ui::Color::DarkRed),
)
}

pub fn write(&self) -> Result<()> {
Expand Down
12 changes: 12 additions & 0 deletions src/util/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ pub fn prompt_confirm_with_default(message: &str, default: bool) -> Result<bool>
.context("Failed to prompt for confirm")
}

pub fn prompt_confirm_with_default_with_cancel(
message: &str,
default: bool,
) -> Result<Option<bool>> {
let confirm = inquire::Confirm::new(message);
confirm
.with_default(default)
.with_render_config(Configs::get_render_config())
.prompt_skippable()
.context("Failed to prompt for confirm")
}

pub fn prompt_multi_options<T: Display>(message: &str, options: Vec<T>) -> Result<Vec<T>> {
let multi_select = inquire::MultiSelect::new(message, options);
multi_select
Expand Down

0 comments on commit 0bd1444

Please sign in to comment.