memea

Function query

Source
pub fn query(
    prompt: &str,
    warn: bool,
    default: QueryDefault,
) -> Result<bool, MemeaError>
Expand description

Prompts the user for a yes/no response with optional default.

This function displays a prompt to the user and waits for a yes/no response. It can display the prompt as a warning (in yellow) or normal text, and supports default responses when the user presses enter without typing.

§Arguments

  • prompt - The question to ask the user
  • warn - Whether to display the prompt as a warning (colored)
  • default - Default response behavior if user presses enter

§Returns

  • Ok(true) - User confirmed with yes
  • Ok(false) - User declined with no
  • Err(MemeaError) - I/O error during user interaction

§Examples

use memea::{query, QueryDefault};

let overwrite = query("File exists. Overwrite?", true, QueryDefault::No)?;
if overwrite {
    println!("User chose to overwrite");
}