Trait promptuity::Prompt

source ·
pub trait Prompt {
    type Output;

    // Required methods
    fn handle(&mut self, code: KeyCode, modifiers: KeyModifiers) -> PromptState;
    fn submit(&mut self) -> Self::Output;
    fn render(&mut self, state: &PromptState) -> Result<RenderPayload, String>;

    // Provided methods
    fn setup(&mut self) -> Result<(), Error> { ... }
    fn validate(&self) -> Result<(), String> { ... }
}
Expand description

A trait representing the behavior of a prompt.

Required Associated Types§

source

type Output

The type returned as a result by the prompt.

Required Methods§

source

fn handle(&mut self, code: KeyCode, modifiers: KeyModifiers) -> PromptState

Handles key presses.
Allows changing the internal state of the prompt in response to key inputs.

source

fn submit(&mut self) -> Self::Output

Submits the prompt.
Called as a result of Prompt::handle returning PromptState::Submit, it returns the final value.

source

fn render(&mut self, state: &PromptState) -> Result<RenderPayload, String>

Renders the prompt.
Performs rendering based on the value of PromptState.
If returning an error, please return the error message as a String.

Provided Methods§

source

fn setup(&mut self) -> Result<(), Error>

Sets up the prompt.
A lifecycle method for validating and initializing settings.

source

fn validate(&self) -> Result<(), String>

Validates the prompt.
If returning an error, please return the error message as a String.

Implementors§