Struct dialoguer::Input [−][src]
Renders an input prompt.
Example usage
use dialoguer::Input; let input : String = Input::new() .with_prompt("Tea or coffee?") .with_initial_text("Yes") .default("No".into()) .interact_text()?;
It can also be used with turbofish notation:
let input = Input::<String>::new() .interact_text()?;
Implementations
impl<'a, T> Input<'a, T> where
T: Clone + FromStr + Display,
T::Err: Display + Debug,
[src]
T: Clone + FromStr + Display,
T::Err: Display + Debug,
pub fn new() -> Input<'a, T>
[src]
Creates an input prompt.
pub fn with_theme(theme: &'a dyn Theme) -> Input<'a, T>
[src]
Creates an input prompt with a specific theme.
pub fn with_prompt<S: Into<String>>(&mut self, prompt: S) -> &mut Input<'a, T>
[src]
Sets the input prompt.
pub fn with_initial_text<S: Into<String>>(
&mut self,
val: S
) -> &mut Input<'a, T>
[src]
&mut self,
val: S
) -> &mut Input<'a, T>
Sets initial text that user can accept or erase.
pub fn default(&mut self, value: T) -> &mut Input<'a, T>
[src]
Sets a default.
Out of the box the prompt does not have a default and will continue to display until the user inputs something and hits enter. If a default is set the user can instead accept the default with enter.
pub fn allow_empty(&mut self, val: bool) -> &mut Input<'a, T>
[src]
Enables or disables an empty input
By default, if there is no default value set for the input, the user must input a non-empty string.
pub fn show_default(&mut self, val: bool) -> &mut Input<'a, T>
[src]
Disables or enables the default value display.
The default behaviour is to append [default
] to the prompt to tell the
user what is the default value.
This method does not affect existance of default value, only its display in the prompt!
pub fn validate_with<V>(&mut self, validator: V) -> &mut Input<'a, T> where
V: Validator<T> + 'a,
T: 'a,
[src]
V: Validator<T> + 'a,
T: 'a,
Registers a validator.
Example
let mail: String = Input::new() .with_prompt("Enter email") .validate_with(|input: &String| -> Result<(), &str> { if input.contains('@') { Ok(()) } else { Err("This is not a mail address") } }) .interact() .unwrap();
pub fn interact_text(&mut self) -> Result<T>
[src]
Enables the user to enter a printable ascii sequence and returns the result.
Its difference from interact
is that it only allows ascii characters for string,
while interact
allows virtually any character to be used e.g arrow keys.
The dialog is rendered on stderr.
pub fn interact_text_on(&mut self, term: &Term) -> Result<T>
[src]
Like interact_text
but allows a specific terminal to be set.
pub fn interact(&mut self) -> Result<T>
[src]
Enables user interaction and returns the result.
Allows any characters as input, including e.g arrow keys.
Some of the keys might have undesired behavior.
For more limited version, see interact_text
.
If the user confirms the result is true
, false
otherwise.
The dialog is rendered on stderr.
pub fn interact_on(&mut self, term: &Term) -> Result<T>
[src]
Like interact
but allows a specific terminal to be set.
Trait Implementations
impl<'a, T> Default for Input<'a, T> where
T: Clone + FromStr + Display,
T::Err: Display + Debug,
[src]
T: Clone + FromStr + Display,
T::Err: Display + Debug,
Auto Trait Implementations
impl<'a, T> !RefUnwindSafe for Input<'a, T>
impl<'a, T> !Send for Input<'a, T>
impl<'a, T> !Sync for Input<'a, T>
impl<'a, T> Unpin for Input<'a, T> where
T: Unpin,
T: Unpin,
impl<'a, T> !UnwindSafe for Input<'a, T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,