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

DEFAULT_BOOL_FORMATTER
String formatter used by default in Confirm prompts. Translates bool to "Yes" and false to "No".
DEFAULT_STRING_FORMATTER
String formatter used by default in inputs that return a String as input. Its behavior is to just echo the received input.

Type Aliases§

BoolFormatter
Type alias for formatters used in Confirm prompts.
CustomTypeFormatter
Type alias for formatters used in CustomType prompts.
MultiOptionFormatter
Type alias for formatters used in MultiSelect prompts.
OptionFormatter
Type alias for formatters used in Select prompts.
StringFormatter
Type alias for formatters that receive a string slice as the input, required by Text and Password for example.