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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
//! This is a rust port of <https://www.npmjs.com/package/@clack/prompts>
//!
//! ## Setup
//!
//! You can setup the start and end of a prompt session with the macros [`intro!`] and [`outro!`], respectively
//!
//! ```
//! use may_clack::{intro, outro};
//!
//! intro!("intro");
//! // do stuff
//! outro!("outro");
//! ```
//!
//! ## Cancel
//!
//! When the user cancels a question, you can use the [`cancel!`] utility to provide a cancellation message.
//!
//! When cancelled the will return a [`error::ClackError::Cancelled`].
//!
//! All input types that can return a `Cancelled` Err will also have the option to add a `.cancel` closure
//!
//! ```no_run
//! use may_clack::{cancel, input, error::ClackError};
//!
//! let text = input("todo").interact();
//! if let Err(ClackError::Cancelled) = text {
//! cancel!("operation cancelled")
//! }
//! ```
//!
//! ## Info
//!
//! If you want to write a message in a prompting session you can use the [`info!`] utility.
//!
//! ```
//! use may_clack::{info, intro, outro};
//!
//! intro!("intro");
//! // do stuff
//! info!("info");
//! // do stuff
//! outro!("outro");
//! ```
//!
//! ## General
//!
//! There are 6 components: [`input`](#input), [`confirm`](#confirm),
//! [`select`](#select), [`multi_select`](#multi_select), [`multi_input`](#multi_input)
//!
//! Each of the input types returns a struct, that allows you to setup the prompt.
//! since every prompt needs a message the initial
//!
//! To actually prompt the user after setting up you have to call `.interact()`
//!
//! ```no_run
//! use may_clack::confirm;
//!
//! let answer = confirm("Yes or No?").interact();
//! ```
//!
//! # Components
//!
//! ## Input
//!
//! The [`input::Input`] component accepts a single line of text.
//!
//! ```no_run
//! use may_clack::input;
//!
//! let answer = input("what is the meaning of life?").initial_value("42").interact();
//! println!("{:?}", answer);
//! ```
//!
//! ## Confirm
//!
//! The [`confirm::Confirm`] component accepts a yes or no answer.
//!
//! ```no_run
//! use may_clack::confirm;
//!
//! let answer = confirm("do you want to continue?").interact();
//! println!("answer {:?}", answer);
//! ```
//!
//! ## `Select`
//!
//! The [`select::Select`] component allows the user to choose one value from a list of options.
//!
//! ```no_run
//! use may_clack::select;
//!
//! #[derive(Debug, Clone)]
//! enum Fruit {
//! Mango,
//! Peach,
//! PassionFruit,
//! }
//!
//! let fruit = select("pick a fruit")
//! .option_hint(Fruit::Mango, "Mango", "The best one")
//! .option(Fruit::Peach, "Peach")
//! .option(Fruit::PassionFruit, "Passion fruit")
//! .interact();
//! println!("fruit {:?}", fruit);
//! ```
//!
//! ## `MultiSelect`
//!
//! The [`multi_select::MultiSelect`] component allows the user to choose multiple values from a list of options.
//!
//! ```no_run
//! use may_clack::multi_select;
//!
//! let toppings = multi_select("Choose your toppings")
//! .option("fruits", "Dried fruits")
//! .option("chocolate", "Chocolate chips")
//! .option_hint("sauce", "Chocolate sauce", "it's warm")
//! .interact();
//! println!("toppings {:?}", toppings);
//! ```
//!
//! ## `MultiInput`
//!
//! The [`multi_input::MultiInput`] component accepts multiple lines of text.
//!
//! ```no_run
//! use may_clack::multi_input;
//!
//! let lines = multi_input("idk").interact();
//! println!("lines {:?}", lines);
//! ```
//!
pub mod error;
mod prompt;
pub mod style;
pub mod traits;
pub use prompt::*;
pub use prompt::confirm::confirm;
pub use prompt::input::input;
pub use prompt::multi_input::multi_input;
pub use prompt::multi_select::multi_select;
pub use prompt::select::select;