pub struct Input<'a> {
pub title: String,
pub description: String,
pub prompt: String,
pub placeholder: String,
pub suggestions: Vec<&'a str>,
pub inline: bool,
pub password: bool,
pub input: String,
pub theme: &'a Theme,
pub validation: fn(_: &str) -> Result<(), &str>,
/* private fields */
}Expand description
Single line text input
§Example
use demand::Input;
let input = Input::new("What's your name?")
.description("We'll use this to personalize your experience.")
.placeholder("Enter your name");
let name = input.run().expect("error running input");Fields§
§title: StringThe title of the input
description: StringA description to display after the title
prompt: StringA prompt to display after the description
placeholder: StringA placeholder to display in the input
suggestions: Vec<&'a str>A list of suggestions to autocomplete from
inline: boolShow the input inline
password: boolWhether to mask the input
input: StringInput entered by the user
theme: &'a ThemeColors/style of the input
validation: fn(_: &str) -> Result<(), &str>Validation function
Implementations§
source§impl<'a> Input<'a>
impl<'a> Input<'a>
sourcepub fn description(self, description: &str) -> Self
pub fn description(self, description: &str) -> Self
Sets the description of the input.
If the input is inline, it is displayed to the right of the title. Otherwise, it is displayed below the title.
sourcepub fn inline(self, inline: bool) -> Self
pub fn inline(self, inline: bool) -> Self
Sets the inline flag of the input.
If true, the input is displayed inline with the title
sourcepub fn password(self, password: bool) -> Self
pub fn password(self, password: bool) -> Self
Sets the password flag of the input.
If true, the input is masked with asterisks
sourcepub fn placeholder(self, placeholder: &str) -> Self
pub fn placeholder(self, placeholder: &str) -> Self
Sets the placeholder of the input.
The placeholder is displayed in the input before the user enters any text
sourcepub fn suggestions(self, suggestions: Vec<&'static str>) -> Self
pub fn suggestions(self, suggestions: Vec<&'static str>) -> Self
Sets the suggestions of the input
sourcepub fn prompt(self, prompt: &str) -> Self
pub fn prompt(self, prompt: &str) -> Self
Sets the prompt of the input.
The prompt is displayed after the title and description. If empty, the default prompt > is displayed.