pub trait Prompt {
type Output;
// Required methods
fn handle(&mut self, key: Key) -> Step<Self::Output>;
fn render(&self, ctx: RenderCtx<'_>) -> Frame;
fn render_answered(&self, value: &Self::Output) -> Frame;
// Provided method
fn run_fallback(self) -> Result<Self::Output>
where Self: Sized { ... }
}Expand description
The contract every interactive prompt implements.
Required Associated Types§
Required Methods§
Sourcefn handle(&mut self, key: Key) -> Step<Self::Output>
fn handle(&mut self, key: Key) -> Step<Self::Output>
Apply a key press to the prompt’s internal state. Return:
Step::Continue— state changed, but we’re not done.Step::Submit(v)— done, handvback to the caller.Step::Reject(msg)— block submission, showmsgas an error below the input. The runner clears the error when the next key arrives.Step::Cancel— user asked to abort (Esc / Ctrl-C).
Sourcefn render(&self, ctx: RenderCtx<'_>) -> Frame
fn render(&self, ctx: RenderCtx<'_>) -> Frame
Render the prompt’s current state as one frame (a Vec<String>,
one entry per terminal row). The runner takes care of writing the
frame and clearing it on the next iteration — prompts never call
eprintln! themselves.
Sourcefn render_answered(&self, value: &Self::Output) -> Frame
fn render_answered(&self, value: &Self::Output) -> Frame
Render the prompt’s post-submission display. Typically the
◇ question / │ value / │ triple from theme::answered.
Provided Methods§
Sourcefn run_fallback(self) -> Result<Self::Output>where
Self: Sized,
fn run_fallback(self) -> Result<Self::Output>where
Self: Sized,
Optional non-interactive fallback for piped/CI environments. The default is to refuse — most prompts override this with a numeric or line-buffered alternative.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".