inquire/
lib.rs

1//! `inquire` is a library for building interactive prompts on terminals.
2//!
3//! It provides several different prompts in order to interactively ask the user
4//! for information via the CLI. With `inquire`, you can use:
5//!
6//! - [`Text`] to get text input from the user, with _built-in autocompletion support_;
7//! - [`Editor`]* to get longer text inputs by opening a text editor for the user;
8//! - [`DateSelect`]* to get a date input from the user, selected via an _interactive calendar_;
9//! - [`Select`] to ask the user to select one option from a given list;
10//! - [`MultiSelect`] to ask the user to select an arbitrary number of options from a given list;
11//! - [`Confirm`] for simple yes/no confirmation prompts;
12//! - [`CustomType`] for text prompts that you would like to parse to a custom type, such as numbers or UUIDs;
13//! - [`Password`] for secretive text prompts.
14//!
15//! Check out the [GitHub repository](https://github.com/mikaelmello/inquire) to see demos of what you can do with `inquire`.
16//!
17//! # Features
18//!
19//! - Cross-platform, supporting UNIX and Windows terminals (thanks to [crossterm](https://crates.io/crates/crossterm));
20//! - Several kinds of prompts to suit your needs;
21//! - Standardized error handling (thanks to [thiserror](https://crates.io/crates/thiserror));
22//! - Support for fine-grained configuration for each prompt type, allowing you to customize:
23//!   - Default values;
24//!   - Input validators and formatters;
25//!   - Help messages;
26//!   - Autocompletion for [`Text`] prompts;
27//!   - Custom list filters for Select and [`MultiSelect`] prompts;
28//!   - Custom parsers for [`Confirm`] and [`CustomType`] prompts;
29//!   - Custom extensions for files created by [`Editor`] prompts;
30//!   - and many others!
31//!
32//! \* Date-related features are available by enabling the `date` feature.
33//!
34//! # Simple Example
35//!
36//! ```rust no_run
37//! use inquire::{Text, validator::{StringValidator, Validation}};
38//!
39//! fn main() {
40//!     let validator = |input: &str| if input.chars().count() > 140 {
41//!         Ok(Validation::Invalid("You're only allowed 140 characters.".into()))
42//!     } else {
43//!         Ok(Validation::Valid)
44//!     };
45//!
46//!     let status = Text::new("What are you thinking about?")
47//!         .with_validator(validator)
48//!         .prompt();
49//!
50//!     match status {
51//!         Ok(status) => println!("Your status is being published..."),
52//!         Err(err) => println!("Error while publishing your status: {}", err),
53//!     }
54//! }
55//! ```
56//!
57//! [`Text`]: crate::Text
58//! [`DateSelect`]: crate::DateSelect
59//! [`Select`]: crate::Select
60//! [`MultiSelect`]: crate::MultiSelect
61//! [`Confirm`]: crate::Confirm
62//! [`CustomType`]: crate::CustomType
63//! [`Password`]: crate::Password
64//! [`Editor`]: crate::Editor
65
66#![warn(missing_docs)]
67#![cfg_attr(docsrs, feature(doc_cfg))]
68#![allow(clippy::bool_to_int_with_if)]
69mod ansi;
70pub mod autocompletion;
71mod config;
72#[cfg(feature = "date")]
73mod date_utils;
74pub mod error;
75pub mod formatter;
76mod input;
77pub mod list_option;
78pub mod parser;
79mod prompts;
80mod terminal;
81pub mod type_aliases;
82pub mod ui;
83mod utils;
84pub mod validator;
85
86pub use crate::autocompletion::Autocomplete;
87pub use crate::config::set_global_render_config;
88pub use crate::error::{CustomUserError, InquireError};
89pub use crate::prompts::*;