Skip to main content

Prompt

Trait Prompt 

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

Source

type Output

The value returned to the caller on successful submission.

Required Methods§

Source

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, hand v back to the caller.
  • Step::Reject(msg) — block submission, show msg as an error below the input. The runner clears the error when the next key arrives.
  • Step::Cancel — user asked to abort (Esc / Ctrl-C).
Source

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.

Source

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§

Source

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".

Implementors§