dsplce_co_promptuity/lib.rs
1//! # Promptuity
2//!
3//! Promptuity is a library that provides interactive prompts. It is highly extensible, allowing you to build your original prompts from scratch. It brings ingenuity to various projects.
4//!
5//! ## Concept
6//!
7//! - **Not easy, But simple**
8//! - Avoids APIs with implicit behavior, aiming to provide as transparent APIs as possible.
9//! - The amount of code required to start a prompt may be more compared to other libraries.
10//! - **Extensible**
11//! - You can customize built-in prompts or build your prompts from scratch.
12//! - The built-in prompts are minimal, assuming that prompt requirements vary by project.
13//! - **Beautiful**
14//! - Offers two types of built-in Themes.
15//! - Themes can also be fully customized to fit your ideal.
16//!
17//! ## Quick Start
18//!
19//! The basic usage is as follows.
20//!
21//! ```no_run
22//! use promptuity::prompts::{Confirm, Input, Select, SelectOption};
23//! use promptuity::themes::FancyTheme;
24//! use promptuity::{Error, Promptuity, Term};
25//!
26//! fn main() -> Result<(), Error> {
27//! let mut term = Term::default();
28//! let mut theme = FancyTheme::default();
29//! let mut p = Promptuity::new(&mut term, &mut theme);
30//!
31//! p.term().clear()?;
32//!
33//! p.with_intro("Survey").begin()?;
34//!
35//! let name = p.prompt(Input::new("Please enter your username").with_placeholder("username"))?;
36//!
37//! let _ = p.prompt(Confirm::new("Are you a full-time software developer?").with_default(true))?;
38//!
39//! let _ = p.prompt(
40//! Select::new(
41//! "Select your primary programming language",
42//! vec![
43//! SelectOption::new("Rust", "rust"),
44//! SelectOption::new("Go", "go"),
45//! SelectOption::new("C++", "cpp"),
46//! SelectOption::new("C", "c"),
47//! SelectOption::new("TypeScript", "typescript"),
48//! SelectOption::new("JavaScript", "javascript"),
49//! SelectOption::new("Deno", "deno"),
50//! SelectOption::new("Python", "python"),
51//! SelectOption::new("Java", "java"),
52//! SelectOption::new("Dart", "dart"),
53//! SelectOption::new("Other", "other"),
54//! ],
55//! )
56//! .with_hint("Submit with Space or Enter."),
57//! )?;
58//!
59//! p.with_outro(format!("Thank you for your response, {}!", name))
60//! .finish()?;
61//!
62//! Ok(())
63//! }
64//! ```
65//!
66//! ## Error Handling
67//!
68//! All errors are consolidated into [`promptuity::Error`](#).
69//!
70//! In many cases, prompt interruptions will need to be handled individually. Interruptions occur during user input reception, typically through inputs like <kbd>Ctrl</kbd> + <kbd>C</kbd> or <kbd>ESC</kbd>.
71//!
72//! ```rust
73//! use promptuity::prompts::Input;
74//! use promptuity::themes::MinimalTheme;
75//! use promptuity::{Error, Promptuity, Term};
76//!
77//! fn ask() -> Result<String, Error> {
78//! let mut term = Term::default();
79//! let mut theme = MinimalTheme::default();
80//! let mut p = Promptuity::new(&mut term, &mut theme);
81//!
82//! p.begin()?;
83//! let name = p.prompt(Input::new("Please enter your username").with_placeholder("username"))?;
84//! p.finish()?;
85//!
86//! Ok(name)
87//! }
88//!
89//! fn main() {
90//! match ask() {
91//! Ok(name) => println!("Hello, {}!", name),
92//! Err(Error::Cancel) => {}
93//! Err(e) => eprintln!("Error: {}", e),
94//! }
95//! }
96//! ```
97//!
98//! Prompt interruptions can be handled as [`Error::Cancel`]. In the above examples, no message is displayed in the event of an interruption.
99
100pub mod event;
101pub mod pagination;
102pub mod prompts;
103pub mod style;
104pub mod themes;
105
106mod error;
107mod prompt;
108mod term;
109mod theme;
110
111pub use error::*;
112pub use prompt::*;
113pub use term::*;
114pub use theme::*;