Crate inquire[][src]

Expand description

inquire is a library for building interactive prompts on terminals, inspired by survey.

It provides several different prompts in order to interactively ask the user for information via the CLI.

With inquire, you can ask the user to:

  • Select one option among many choices
  • Select many options among many choices
    • The user can filter the options on both selects!
  • Input a line of text
    • You can easily set-up auto-completion.
  • Confirm an action with yes or no responses
  • Input a text and have it automatically validated and parsed to retrieve any type
    • Useful when asking for numerical inputs, or even formatted ids!
  • Input a password
  • Pick a date from an interactive calendar.

You can customize several aspects of each one of these prompts such as the page size and the behavior of the filter when selecting options, help and error messages, validate inputs, format the final output, etc.

A more complete documentation is present in the README.md file of the repository. Please go there while the proper docs are being updated.

Example

use inquire::{min_length, Text};

fn main() {
    let name = Text::new("What is your name?")
        .with_validator(min_length!(8, "Sorry, this name is invalid"))
        .prompt();
     
    match name {
        Ok(name) => println!("Hello {}", name),
        Err(err) => println!("Error: {}", err),
    }
}

Modules

General type aliases and default values used by multiple prompts.

Definitions of inquire’s error handling

Type aliases and default implementations for functions called as formatters of a given input.

Utilities used to wrap user selections in Select and MultiSelect prompts.

Type aliases and default implementations for parsers called in prompts that need to parse user input, such as Confirm or CustomType.

Type aliases for functions used by prompts to validate user input before returning the values to their callers.

Macros

Built-in validator that checks whether the answer length is equal to the specified value.

Built-in validator that checks whether the answer length is smaller than or equal to the specified threshold.

Built-in validator that checks whether the answer length is larger than or equal to the specified threshold.

Built-in parser creator that checks whether the answer is able to be successfully parsed to a given type, such as f64. The given type must implement the FromStr trait.

Built-in validator that checks whether the answer is not empty.

Structs

Confirmation prompt, expecting y/n answers and returning a bool value.

Prompt to retrieve custom types automatically parsed from the user’s input.

Interactive date picker to select simple dates (no time or timezones included).

Selection of any amount of options from an interactive list.

Retrieves a single line of text input without echoing back the user’s keypresses.

Selection of one option from an interactive list.

Prompts the user for a single line of text input.