Common/UserInterface/
ShowInputBox.rs

1//! # ShowInputBox Effect
2//!
3//! Defines the `ActionEffect` for showing an input box to the user.
4
5use std::sync::Arc;
6
7use super::{DTO::InputBoxOptionsDTO::InputBoxOptionsDTO, UserInterfaceProvider::UserInterfaceProvider};
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will display an input box to solicit
11/// a string input from the user.
12///
13/// It uses the `UserInterfaceProvider` capability from the environment to
14/// orchestrate the interaction with the frontend UI.
15///
16/// # Parameters
17/// * `Options`: An `Option<InputBoxOptionsDTO>` containing settings for the
18///   input box, such as a title, placeholder text, and initial value.
19///
20/// # Returns
21/// An `ActionEffect` that resolves with an `Option<String>`, containing the
22/// text entered by the user, or `None` if the input box was cancelled.
23pub fn ShowInputBox(
24	Options:Option<InputBoxOptionsDTO>,
25) -> ActionEffect<Arc<dyn UserInterfaceProvider>, CommonError, Option<String>> {
26	ActionEffect::New(Arc::new(move |Provider:Arc<dyn UserInterfaceProvider>| {
27		let OptionsClone = Options.clone();
28
29		Box::pin(async move { Provider.ShowInputBox(OptionsClone).await })
30	}))
31}