Skip to content

Commit

Permalink
use inquire for one set of prompts
Browse files Browse the repository at this point in the history
Considering that "dialoguer" uses "console" backend library, and the
future of himalaya is reliant on "crossterm", we are moving from
dialoguer, to inquire.

This commit is going to include some experimental changes to one file.

Signed-off-by: Perma Alesheikh <[email protected]>
  • Loading branch information
prmadev authored and soywod committed May 4, 2024
1 parent ccddfeb commit c779081
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 31 deletions.
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ email-lib = { version = "=0.24.1", default-features = false, features = ["derive
email_address = "0.2.4"
erased-serde = "0.3"
indicatif = "0.17"
inquire = "0.7.4"
mail-builder = "0.3"
md5 = "0.7"
mml-lib = { version = "=1.0.12", default-features = false, features = ["derive"] }
Expand Down
65 changes: 34 additions & 31 deletions src/account/wizard.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[cfg(feature = "account-sync")]
use crate::account::config::SyncConfig;
use color_eyre::{eyre::bail, Result};
use color_eyre::{eyre::OptionExt, Result};
#[cfg(feature = "account-sync")]
use dialoguer::Confirm;
use dialoguer::Input;
use email_address::EmailAddress;
use std::str::FromStr;
use inquire::validator::{ErrorMessage, Validation};
use std::{path::PathBuf, str::FromStr};

#[cfg(feature = "account-sync")]
use crate::wizard_prompt;
Expand All @@ -14,24 +14,26 @@ use crate::wizard_warn;
use crate::{
backend::{self, config::BackendConfig, BackendKind},
message::config::{MessageConfig, MessageSendConfig},
ui::THEME,
};

use super::TomlAccountConfig;

pub(crate) async fn configure() -> Result<Option<(String, TomlAccountConfig)>> {
let mut config = TomlAccountConfig::default();

config.email = Input::with_theme(&*THEME)
.with_prompt("Email address")
.validate_with(|email: &String| {
if EmailAddress::is_valid(email) {
Ok(())
} else {
bail!("Invalid email address: {email}")
}
})
.interact()?;
let mut config = TomlAccountConfig {
email: inquire::Text::new("Email address: ")
.with_validator(|email: &_| {
if EmailAddress::is_valid(email) {
Ok(Validation::Valid)
} else {
Ok(Validation::Invalid(ErrorMessage::Custom(format!(
"Invalid email address: {email}"
))))
}
})
.prompt()?,

..Default::default()
};

let addr = EmailAddress::from_str(&config.email).unwrap();

Expand All @@ -44,25 +46,26 @@ pub(crate) async fn configure() -> Result<Option<(String, TomlAccountConfig)>> {
.ok()
});

let account_name = Input::with_theme(&*THEME)
.with_prompt("Account name")
.default(addr.domain().split_once('.').unwrap().0.to_owned())
.interact()?;
let account_name = inquire::Text::new("Account name: ")
.with_default(
addr.domain()
.split_once('.')
.ok_or_eyre("not a valid domain, without any .")?
.0,
)
.prompt()?;

config.display_name = Some(
Input::with_theme(&*THEME)
.with_prompt("Full display name")
.default(addr.local_part().to_owned())
.interact()?,
inquire::Text::new("Full display name: ")
.with_default(addr.local_part())
.prompt()?,
);

config.downloads_dir = Some(
Input::with_theme(&*THEME)
.with_prompt("Downloads directory")
.default(String::from("~/Downloads"))
.interact()?
.into(),
);
config.downloads_dir = Some(PathBuf::from(
inquire::Text::new("Downloads directory: ")
.with_default("~/Downloads")
.prompt()?,
));

let email = &config.email;
#[cfg(feature = "account-discovery")]
Expand Down

0 comments on commit c779081

Please sign in to comment.