Crate inquire[][src]

Expand description

inquire is a library for building interactive prompts on terminals.

It provides several different prompts in order to interactively ask the user for information via the CLI. With inquire, you can use:

  • Text to get text input from the user, with built-in auto-completion support;
  • DateSelect* to get a date input from the user, selected via an interactive calendar;
  • Select to ask the user to select one option from a given list;
  • MultiSelect to ask the user to select an arbitrary number of options from a given list;
  • Confirm for simple yes/no confirmation prompts;
  • CustomType for text prompts that you would like to parse to a custom type, such as numbers or UUIDs;
  • Password for secretive text prompts.

Check out the GitHub repository to see demos of what you can do with inquire.

Features

  • Cross-platform, supporting UNIX and Windows terminals (thanks to crossterm);
  • Several kinds of prompts to suit your needs;
  • Standardized error handling (thanks to thiserror);
  • Support for fine-grained configuration for each prompt type, allowing you to customize:
    • Default values;
    • Input validators and formatters;
    • Help messages;
    • Auto-completion for Text prompts;
    • Custom list filters for Select and MultiSelect prompts;
    • Custom parsers for Confirm and CustomType prompts;
    • and many others!

* Date-related features are available by enabling the date feature.

Simple Example

use inquire::{max_length, validator::InquireLength, Text};

fn main() {
    let status = Text::new("What are you thinking about?")
        .with_validator(max_length!(140, "You're only allowed 140 characters."))
        .prompt();
     
    match status {
        Ok(status) => println!("Your status is being published..."),
        Err(err) => println!("Error while publishing your status: {}", 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.

UI-related definitions for rendered content.

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

Prompt to ask the user for simple yes/no questions, commonly known by asking the user displaying the (y/n) text.

Generic prompt suitable for when you need to parse the user input into a specific type, for example an f64 or a rust_decimal, maybe even an uuid.

Prompt that allows user to select a date (time not supported) from an interactive calendar. Available via the date feature.

Prompt suitable for when you need the user to select many options (including none if applicable) among a list of them.

Prompt meant for secretive text inputs.

Prompt suitable for when you need the user to select one option among many.

Standard text prompt that returns the user string input.