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 autocompletion support;Editor
* to get longer text inputs by opening a text editor for the user;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.
* The Editor and DateSelect prompts are available by enabling the editor
and date
features, respectively.
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;
- Support for fine-grained configuration for each prompt type, allowing you to customize:
- Default values;
- Input validators and formatters;
- Help messages;
- Autocompletion for
Text
prompts; - Custom list filters for Select and
MultiSelect
prompts; - Custom parsers for
Confirm
andCustomType
prompts; - Custom extensions for files created by
Editor
prompts; - and many others!
§Simple Example
use inquire::{Text, validator::{StringValidator, Validation}};
fn main() {
let validator = |input: &str| if input.chars().count() > 140 {
Ok(Validation::Invalid("You're only allowed 140 characters.".into()))
} else {
Ok(Validation::Valid)
};
let status = Text::new("What are you thinking about?")
.with_validator(validator)
.prompt();
match status {
Ok(status) => println!("Your status is being published..."),
Err(err) => println!("Error while publishing your status: {}", err),
}
}
Re-exports§
pub use crate::autocompletion::Autocomplete;
pub use crate::error::CustomUserError;
pub use crate::error::InquireError;
Modules§
- autocompletion
- Trait and structs used by prompts to provide autocompletion features.
- error
- Definitions of
inquire
’s error handling - formatter
- Type aliases and default implementations for functions called as formatters of a given input.
- list_
option - Utilities used to wrap user selections in Select and
MultiSelect
prompts. - parser
- Type aliases and default implementations for parsers called in prompts
that need to parse user input, such as Confirm or
CustomType
. - type_
aliases - General type aliases.
- ui
- UI-related definitions for rendered content.
- validator
- Traits and structs used by prompts to validate user input before returning the values to their callers.
Macros§
- length
- Shorthand for the built-in
ExactLengthValidator
that checks whether the answer length is equal to the specified value. - max_
length - Shorthand for the built-in
MaxLengthValidator
that checks whether the answer length is smaller than or equal to the specified threshold. - min_
length - Shorthand for the built-in
MinLengthValidator
that checks whether the answer length is larger than or equal to the specified threshold. - parse_
type - 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. - required
- Shorthand for the built-in
ValueRequiredValidator
that checks whether the answer is not empty.
Structs§
- Confirm
- Prompt to ask the user for simple yes/no questions, commonly known by asking the user displaying the
(y/n)
text. - Custom
Type - Generic prompt suitable for when you need to parse the user input into a specific type, for example an
f64
or arust_decimal
, maybe even anuuid
. - Date
Select - Prompt that allows user to select a date (time not supported) from an interactive calendar. Available via the
date
feature. - Editor
- This prompt is meant for cases where you need the user to write some text that might not fit in a single line, such as long descriptions or commit messages.
- Multi
Select - Prompt suitable for when you need the user to select many options (including none if applicable) among a list of them.
- Password
- Prompt meant for secretive text inputs.
- Select
- Prompt suitable for when you need the user to select one option among many.
- Text
- Standard text prompt that returns the user string input.
Enums§
- Action
- Top-level type to describe the directives a prompt receives.
- Custom
Type Prompt Action - Set of actions for a CustomTypePrompt.
- Date
Select Prompt Action - Set of actions for a DateSelectPrompt.
- Editor
Prompt Action - Set of actions for an EditorPrompt.
- Input
Action - Set of actions for a text input handler.
- Multi
Select Prompt Action - Set of actions for a MultiSelectPrompt.
- Password
Display Mode - Display modes of the text input of a password prompt.
- Password
Prompt Action - Set of actions for a PasswordPrompt.
- Select
Prompt Action - Set of actions for a SelectPrompt.
- Text
Prompt Action - Set of actions for a TextPrompt.
Traits§
- Inner
Action - InnerActions are specialized prompt actions.
Functions§
- prompt_
confirmation - This function is a helpful one-liner to prompt the user for the confirmation of an action.
- prompt_
date - This function is a helpful one-liner to prompt the user for a date.
- prompt_
f32 - This function is a helpful one-liner to prompt the user for a number and parse it to f32.
- prompt_
f64 - This function is a helpful one-liner to prompt the user for a number and parse it to f64.
- prompt_
secret - This function is a helpful one-liner to prompt the user for a password, or any secret text.
- prompt_
text - This function is a helpful one-liner to prompt the user for a text input.
- prompt_
u32 - This function is a helpful one-liner to prompt the user for a number and parse it to u32.
- prompt_
u64 - This function is a helpful one-liner to prompt the user for a number and parse it to u64.
- prompt_
u128 - This function is a helpful one-liner to prompt the user for a number and parse it to u128.
- prompt_
usize - This function is a helpful one-liner to prompt the user for a number and parse it to usize.
- set_
global_ render_ config - Acquires a write lock to the global RenderConfig object and updates the inner value with the provided argument.
Type Aliases§
- Confirm
Prompt Action - Set of actions for a ConfirmPrompt.