use anyhow::Result; use forge_app::UserInfra; use forge_select::ForgeWidget; pub struct ForgeInquire; impl Default for ForgeInquire { fn default() -> Self { Self::new() } } impl ForgeInquire { pub fn new() -> Self { Self } async fn prompt(&self, f: F) -> Result> where F: FnOnce() -> Result> + Send + 'static, T: Send + 'static, { tokio::task::spawn_blocking(f).await? } } #[async_trait::async_trait] impl UserInfra for ForgeInquire { async fn prompt_question(&self, question: &str) -> Result> { let question = question.to_string(); self.prompt(move || ForgeWidget::input(&question).allow_empty(true).prompt()) .await } async fn select_one( &self, message: &str, options: Vec, ) -> Result> { if options.is_empty() { return Ok(None); } let message = message.to_string(); self.prompt(move || ForgeWidget::select(&message, options).prompt()) .await } async fn select_many( &self, message: &str, options: Vec, ) -> Result>> { if options.is_empty() { return Ok(None); } let message = message.to_string(); self.prompt(move || ForgeWidget::multi_select(&message, options).prompt()) .await } }