Prompt

Trait Prompt 

Source
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§

Source

type Return

The type of the result produced by the renderer.

Required Methods§

Source

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.

Source

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.

Source

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§

Source

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.

Implementors§

Source§

impl Prompt for Checkbox

Available on crate feature checkbox only.
Source§

impl Prompt for Form

Available on crate feature form only.
Source§

impl Prompt for Json

Available on crate feature json only.
Source§

impl Prompt for Listbox

Available on crate feature listbox only.
Source§

impl Prompt for QuerySelector

Available on crate feature query-selector only.
Source§

impl Prompt for Readline

Available on crate feature readline only.
Source§

impl Prompt for Text

Available on crate feature text only.
Source§

impl Prompt for Tree

Available on crate feature tree only.