confirm_prompt

Interactive Yes/No confirmation prompt using crossterm for raw terminal input.

enum Selection

source

enum Selection

The user’s selection in the confirm prompt.

Variant Description
No Decline; the default when the prompt opens.
Yes Accept.

Implements Clone, Copy, Eq, PartialEq.

struct Component

source

pub struct Component

Renders and drives an interactive Yes/No selector.

Left, h and k select Yes; right, l and j select No. y/n act as direct shortcuts. Escape and Ctrl+C decline. The default selection is No.

Field Type Description
description String Question shown above the Yes/No selector, or before [y/N] when stdin is piped.

Component::new

source

pub fn new(description: impl Into<String>) -> Self

Create a confirm prompt with the given description text.

Parameter Type Description
description impl Into<String> the question to ask
returns Self The prompt; nothing is shown until confirm runs.

Component::confirm

source

pub fn confirm(&self) -> io::Result<bool>

Run the interactive prompt, returning true for Yes and false for No.

When stdin is not a TTY (e.g. piped input), falls back to a simple line-based [y/N] prompt for scriptability.

Parameter Type Description
returns io::Result<bool> true for Yes and false for No, or the terminal I/O error.

Component::confirm_piped

source

fn confirm_piped(&self) -> io::Result<bool>

Fallback for non-TTY stdin: print a [y/N] prompt and read one line.

Parameter Type Description
returns io::Result<bool> true when the line is y or yes in any case, false otherwise or at end of input, or the I/O error.

Component::render

source

fn render<W: Write>(&self, writer: &mut W, selection: Selection, first: bool) -> io::Result<()>

Render the current state of the selector.

Parameter Type Description
writer &mut W the terminal to draw on
selection Selection the option to mark with ›
first bool whether this is the first draw, which also prints the description line
returns io::Result<()> Ok(()) once drawn and flushed, or the write error.

Component::run_loop

source

fn run_loop<W: Write>(&self, writer: &mut W) -> io::Result<bool>

Main event loop reading key events.

Parameter Type Description
writer &mut W the terminal to redraw the selector on
returns io::Result<bool> true for Yes and false for No once a key settles it, or the I/O error.