pub struct Input<'a, T> { /* private fields */ }
Expand description

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

Creates an input prompt.

Sets the input prompt.

Indicates whether to report the input value after interaction.

The default is to report the input value.

Sets initial text that user can accept or erase.

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.

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.

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 existence of default value, only its display in the prompt!

Creates an input prompt with a specific theme.

Enable history processing

Example
let mut history = MyHistory::default();
loop {
    if let Ok(input) = Input::<String>::new()
        .with_prompt("hist")
        .history_with(&mut history)
        .interact_text()
    {
        // Do something with the input
    }
}

Enable completion

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();

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.

Like interact_text but allows a specific terminal to be set.

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.

Like interact but allows a specific terminal to be set.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.