use super::PromptError;
use super::SEP;
pub struct PromptSelect<T>
where
T: std::fmt::Display,
{
message: String,
options: Vec<T>,
}
impl<T> PromptSelect<T>
where
T: std::fmt::Display,
{
pub fn new<S>(
message: S,
options: Vec<T>,
) -> Self
where
S: AsRef<str>,
{
let inner = |message: &str| {
let message = format!("{message}{SEP}");
Self { message, options }
};
inner(message.as_ref())
}
pub fn prompt(self) -> Result<T, PromptError>
{
let Self { message, options } = self;
let response = inquire::Select::new(
&message, options,
)
.prompt()?;
Ok(response)
}
}