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§
Required Methods§
sourcefn handle(&mut self, code: KeyCode, modifiers: KeyModifiers) -> PromptState
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.
sourcefn submit(&mut self) -> Self::Output
fn submit(&mut self) -> Self::Output
Submits the prompt.
Called as a result of Prompt::handle
returning PromptState::Submit
, it returns the final value.
sourcefn render(&mut self, state: &PromptState) -> Result<RenderPayload, String>
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
.