Struct dialoguer::Input [−][src]
Renders an input prompt.
Example usage
use dialoguer::Input; let name = Input::<String>::new().with_prompt("Your name").interact()?; println!("Name: {}", name);
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<'static, 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 whether the default can be editable.
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 hit 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 is to append [default]
to the prompt to tell the
user that a default is acceptable.
pub fn validate_with<V: Validator + 'static>(
&mut self,
validator: V
) -> &mut Input<'a, T>
[src]
&mut self,
validator: V
) -> &mut Input<'a, T>
Registers a validator.
Example
let mail: String = Input::new() .with_prompt("Enter email") .validate_with(|input: &str| -> Result<(), &str> { if input.contains('@') { Ok(()) } else { Err("This is not a mail address") } }) .interact() .unwrap();
pub fn interact(&self) -> Result<T>
[src]
Enables user interaction and returns the result.
If the user confirms the result is true
, false
otherwise.
The dialog is rendered on stderr.
pub fn interact_on(&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>,
[src]
V: MultiLane<T>,