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"
andfalse
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§
- Bool
Formatter - Type alias for formatters used in Confirm prompts.
- Custom
Type Formatter - Type alias for formatters used in
CustomType
prompts. - Multi
Option Formatter - Type alias for formatters used in
MultiSelect
prompts. - Option
Formatter - Type alias for formatters used in Select prompts.
- String
Formatter - Type alias for formatters that receive a string slice as the input, required by Text and Password for example.