Module inquire::formatter[][src]

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

String formatter used by default in Confirm prompts. Translates bool to "Yes" and false to "No".

String formatter used by default in DateSelect prompts. Prints the selected date in the format: Month Day, Year.

String formatter used by default in MultiSelect prompts. Prints the string value of all selected options, separated by commas.

String formatter used by default in Select prompts. Simply prints the string value contained in the selected option.

String formatter used by default in inputs that return a String as input. Its behavior is to just echo the received input.

Type Definitions

Type alias for formatters used in Confirm prompts.

Type alias for formatters used in CustomType prompts.

Type alias for formatters used in DateSelect prompts.

Type alias for formatters used in MultiSelect prompts.

Type alias for formatters used in Select prompts.

Type alias for formatters that receive a string slice as the input, required by Text and Password for example.