Skip to main content

hello_prompt/
hello_prompt.rs

1//! The smallest possible prompt example.
2//!
3//! ```bash
4//! cargo run --example hello_prompt
5//! ```
6//!
7//! Read this top-to-bottom and you've seen the whole API surface you need
8//! for ~80% of CLIs.
9
10use cli_ui::prompt::prelude::*;
11
12fn main() {
13    intro("Set up a new project");
14
15    let name = text("What's your name?")
16        .default("Anya") // accepted on Enter when buffer is empty
17        .placeholder("e.g. Anya") // dim hint shown before typing
18        .run()
19        .or_cancel("Cancelled.");
20
21    let stack = select("Pick a stack")
22        .option("rust", "Rust")
23        .option("ts", "TypeScript")
24        .option("py", "Python")
25        .run()
26        .or_cancel("Cancelled.");
27
28    let init_git = confirm("Initialise git?")
29        .default(true)
30        .run()
31        .or_cancel("Cancelled.");
32
33    outro(format!(
34        "{name} → {} ({} git)",
35        stack.label,
36        if init_git { "with" } else { "without" }
37    ));
38}