Module inquire::formatter

source ·
Expand description

Type aliases and default implementations for functions called as formatters of a given input.

Formatters receive the user input to a given prompt and return a formatted output String, which is displayed to the user as the submitted value.

§Example

Prompt code

use inquire::formatter::StringFormatter;
use inquire::Text;

let formatter: StringFormatter = &|s| {
    let mut c = s.chars();
    match c.next() {
        None => String::from("No name given"),
        Some(f) => {
            String::from("My name is ")
                + f.to_uppercase().collect::<String>().as_str()
                + c.as_str()
        }
    }
};

let name = Text::new("What's your name?")
    .with_formatter(formatter)
    .prompt();

match name {
    Ok(_) => {}
    Err(err) => println!("Error: {}", err),
}

Before submission (pressing Enter)

? What's your name? mikael

After submission

? What's your name? My name is Mikael

Constants§

Type Aliases§