1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! Good looking prompts for the terminal
//!
//! # Available prompts
//!
//! - [`Confirm`] - Ask yes/no questions.
//! - [`Toggle`] - Choose between two options.
//! - [`Text`] - One-line user input.
//! - [`Number`] - One-line user input of numbers.
//! - [`Password`] - One-line user input as password.
//! - [`Select`] - Select an item from a list.
//! - [`MultiSelect`] - Select multiple items from a list.
//!
//! # Simple Example
//!
//! ```rust, no_run
//! use asky::{Confirm, Text};
//!
//! fn main() -> std::io::Result<()> {
//! let name = Text::new("Hi. What's your name?").prompt()?;
//!
//! if Confirm::new("Do you like coffee?").prompt()? {
//! println!("Great! Me too");
//! } else {
//! println!("Hmm... Interesting");
//! }
//!
//! // ...
//!
//! Ok(())
//! }
//! ```
//!
//! # Customization
//!
//! If you'd like to use this crate but don't want the default styles or just want to customize as you like,
//! all the prompts allow setting a custom formatter using `format()` method.
//!
//! The formatter receives a prompt state reference and a [`DrawTime`],
//! and returns the string to display in the terminal.
//!
//! > Note: When using a custom formatter, you are responsible for the presentation of the prompt,
//! > so you must handle the colors, icons, etc. by yourself.
//!
//! #### Example
//!
//! ```rust, no_run
//! # use asky::Confirm;
//! # fn main() -> std::io::Result<()> {
//! Confirm::new("Do you like Rust?")
//! .format(|prompt, _draw_time| {
//! let state = if prompt.active { "Y/n" } else { "y/N" };
//! format!("{} {}\n", prompt.message, state)
//! })
//! .prompt();
//! # Ok(())
//! # }
//! ```
//!
//! This will prints
//!
//! ```bash
//! Do you like Rust? y/N
//! ```
//!
//! ## Cursor Position
//!
//! Almost all the prompts just need a custom string, but some prompts like [`Text`] also requires an array of `[x, y]`
//! position for the cursor, due to these prompts also depends on the cursor position in the process.
//!
//! #### Example
//!
//! ```rust, no_run
//! # use asky::Text;
//! # fn main() -> std::io::Result<()> {
//! Text::new("What is your name")
//! .format(|prompt, _draw_time| {
//! let cursor_col = prompt.input.col;
//! let prefix = "> ";
//!
//! let x = (prefix.len() + cursor_col);
//! let y = 1;
//!
//! (
//! format!("{}\n{} {}", prompt.message, prefix, prompt.input.value),
//! [x, y],
//! )
//! })
//! .prompt();
//! # Ok(())
//! # }
//!
//! ```
//!
//! This will prints
//!
//! ```bash
//! What is your name?
//! > |
//! ```
//!
//! Where `|` is the cursor position.
pub use Confirm;
pub use MultiSelect;
pub use Number;
pub use Password;
pub use Select;
pub use Text;
pub use Toggle;
pub use ;
pub use LineInput;
pub use NumLike;
pub use DrawTime;