pub trait Prompt {
type Return;
// Required methods
fn initialize<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 mut self,
event: &'life1 Event,
) -> Pin<Box<dyn Future<Output = Result<Signal>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn finalize(&mut self) -> Result<Self::Return>;
// Provided method
fn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Return>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}Expand description
A trait for rendering components within a prompt.
This trait defines the essential functions required for rendering custom UI components in a prompt. Implementors of this trait can define how panes are created, how events are evaluated, and how the final result is produced.
Required Associated Types§
Required Methods§
Sourcefn initialize<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Initializes the handler, preparing it for use. This method is called before the prompt starts running.
§Returns
Returns a Result indicating success or failure of the initialization.
If successful, the renderer is ready to handle events and render the prompt.
Sourcefn evaluate<'life0, 'life1, 'async_trait>(
&'life0 mut self,
event: &'life1 Event,
) -> Pin<Box<dyn Future<Output = Result<Signal>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 mut self,
event: &'life1 Event,
) -> Pin<Box<dyn Future<Output = Result<Signal>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Evaluates an event and determines the next action for the prompt.
This method is called whenever an event occurs (e.g., user input). It allows the renderer to react to the event and decide whether the prompt should continue running or quit.
§Parameters
event: A reference to the event that occurred.
§Returns
Returns a Result containing a Signal. Signal::Continue indicates
that the prompt should continue running, while Signal::Quit indicates that
the prompt should terminate its execution.
Sourcefn finalize(&mut self) -> Result<Self::Return>
fn finalize(&mut self) -> Result<Self::Return>
Finalizes the prompt and produces a result.
This method is called after the prompt has been instructed to quit. It allows the renderer to perform any necessary cleanup and produce a final result.
§Returns
Returns a Result containing the final result of the prompt. The type of the result
is defined by the Return associated type.
Provided Methods§
Sourcefn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Return>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Return>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
Runs the prompt, handling events and producing a result.
This method initializes the terminal, and enters a loop to handle events until a quit signal is received. After exiting the loop, it produces and returns the result.
§Returns
Returns a Result containing the produced result or an error.