[][src]Struct dialoguer::Input

pub struct Input<'a, T> { /* fields omitted */ }

Renders a simple input prompt.

Example usage

use dialoguer::Input;

let name = Input::<String>::new().with_prompt("Your name").interact()?;
println!("Name: {}", name);

Methods

impl<'a, T> Input<'a, T> where
    T: Clone + FromStr + Display,
    T::Err: Display + Debug
[src]

pub fn new() -> Input<'static, T>[src]

Creates a new input prompt.

pub fn with_theme(theme: &'a dyn Theme) -> Input<'a, T>[src]

Creates an input with a specific theme.

pub fn with_prompt(&mut self, prompt: &str) -> &mut Input<'a, T>[src]

Sets the input prompt.

pub fn with_initial_text(&mut self, val: &str) -> &mut Input<'a, T>[src]

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]

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]

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

impl<'a, T> !UnwindSafe for Input<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,