replace dialoguer with inquire

In order to reduce our dependencies, we are replacing the dependencies
that use console_rs with those that use crossterm.

This commit will completely replace dialoguer with inquire.

Signed-off-by: Perma Alesheikh <me@prma.dev>
This commit is contained in:
Perma Alesheikh
2024-05-06 15:49:58 +03:30
committed by Clément DOUIN
parent d54dd6429e
commit 1e448e56eb
17 changed files with 441 additions and 543 deletions
+23 -21
View File
@@ -1,9 +1,9 @@
pub mod config;
pub(crate) mod wizard;
use color_eyre::Result;
use async_trait::async_trait;
use std::{ops::Deref, sync::Arc};
use color_eyre::Result;
use std::{fmt::Display, ops::Deref, sync::Arc};
#[cfg(feature = "imap")]
use email::imap::{ImapContextBuilder, ImapContextSync};
@@ -70,30 +70,32 @@ pub enum BackendKind {
Sendmail,
}
impl ToString for BackendKind {
fn to_string(&self) -> String {
let kind = match self {
Self::None => "None",
impl Display for BackendKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::None => "None",
#[cfg(feature = "imap")]
Self::Imap => "IMAP",
#[cfg(all(feature = "imap", feature = "account-sync"))]
Self::ImapCache => "IMAP cache",
#[cfg(feature = "imap")]
Self::Imap => "IMAP",
#[cfg(all(feature = "imap", feature = "account-sync"))]
Self::ImapCache => "IMAP cache",
#[cfg(feature = "maildir")]
Self::Maildir => "Maildir",
#[cfg(feature = "maildir")]
Self::Maildir => "Maildir",
#[cfg(feature = "notmuch")]
Self::Notmuch => "Notmuch",
#[cfg(feature = "notmuch")]
Self::Notmuch => "Notmuch",
#[cfg(feature = "smtp")]
Self::Smtp => "SMTP",
#[cfg(feature = "smtp")]
Self::Smtp => "SMTP",
#[cfg(feature = "sendmail")]
Self::Sendmail => "Sendmail",
};
kind.to_string()
#[cfg(feature = "sendmail")]
Self::Sendmail => "Sendmail",
}
)
}
}
+10 -14
View File
@@ -1,7 +1,7 @@
use color_eyre::Result;
use dialoguer::Select;
#[cfg(feature = "account-discovery")]
use email::account::discover::config::AutoConfig;
use inquire::Select;
#[cfg(feature = "imap")]
use crate::imap;
@@ -13,7 +13,6 @@ use crate::notmuch;
use crate::sendmail;
#[cfg(feature = "smtp")]
use crate::smtp;
use crate::ui::THEME;
use super::{config::BackendConfig, BackendKind};
@@ -38,12 +37,9 @@ pub(crate) async fn configure(
email: &str,
#[cfg(feature = "account-discovery")] autoconfig: Option<&AutoConfig>,
) -> Result<Option<BackendConfig>> {
let kind = Select::with_theme(&*THEME)
.with_prompt("Default email backend")
.items(DEFAULT_BACKEND_KINDS)
.default(0)
.interact_opt()?
.and_then(|idx| DEFAULT_BACKEND_KINDS.get(idx).map(Clone::clone));
let kind = Select::new("Default email backend", DEFAULT_BACKEND_KINDS.to_vec())
.with_starting_cursor(0)
.prompt_skippable()?;
let config = match kind {
#[cfg(feature = "imap")]
@@ -71,12 +67,12 @@ pub(crate) async fn configure_sender(
email: &str,
#[cfg(feature = "account-discovery")] autoconfig: Option<&AutoConfig>,
) -> Result<Option<BackendConfig>> {
let kind = Select::with_theme(&*THEME)
.with_prompt("Backend for sending messages")
.items(SEND_MESSAGE_BACKEND_KINDS)
.default(0)
.interact_opt()?
.and_then(|idx| SEND_MESSAGE_BACKEND_KINDS.get(idx).map(Clone::clone));
let kind = Select::new(
"Backend for sending messages",
SEND_MESSAGE_BACKEND_KINDS.to_vec(),
)
.with_starting_cursor(0)
.prompt_skippable()?;
let config = match kind {
#[cfg(feature = "smtp")]