Skip to main content

pandora_kit/
lib.rs

1//! **CLI toolkit with interactive TUI popups for shell scripts and terminal workflows.**
2//!
3//! The main binary is `pan`. Each subcommand opens an interactive terminal popup:
4//!
5//! | Command   | Description                    | Output                     |
6//! |-----------|--------------------------------|----------------------------|
7//! | `confirm` | Popup de confirmación sí/no    | exit 0 / 1                 |
8//! | `choose`  | Selector de una lista de ítems | ítems en stdout            |
9//! | `filter`  | Selector con búsqueda por texto| ítems en stdout            |
10//! | `spin`    | Spinner animado                | exit del comando           |
11//! | `input`   | Captura de texto libre         | texto en stdout            |
12//! | `file`    | Explorador interactivo de archivos | paths en stdout        |
13//! | `menu`    | Menú jerárquico                | path en stdout             |
14//! | `log`     | Línea de log formateada        | texto a stdout             |
15//! | `update`  | Auto-actualización             | mensajes en stdout         |
16//!
17//! ## Guías detalladas
18//!
19//! Cada subcomando tiene su guía detallada en `pandora/guides/`.
20//! Ejecutá `pan <subcomando> --guide` para verla en el terminal.
21
22mod choose;
23mod confirm;
24mod file;
25mod filter;
26mod input;
27mod keybinds;
28mod log;
29mod menu;
30pub mod popup_config;
31mod spin;
32mod style;
33mod tty;
34mod update;
35
36use clap::{Parser, Subcommand};
37
38const PANDORA_GUIDE: &str = include_str!("../guides/PANDORA_GUIDE.md");
39pub const BIN_NAME: &str = "pan";
40
41#[derive(Parser)]
42#[command(name = BIN_NAME, about = "CLI toolkit with interactive TUI popups", version = env!("CARGO_PKG_VERSION"))]
43struct Cli {
44    /// Display the complete pan guide
45    #[arg(long)]
46    guide: bool,
47
48    #[command(subcommand)]
49    command: Option<Commands>,
50}
51
52#[derive(Subcommand)]
53enum Commands {
54    /// Show a confirmation popup, returns 0 on accept, 1 on cancel
55    Confirm(confirm::ConfirmArgs),
56    /// Show an interactive item selector
57    Choose(choose::ChooseArgs),
58    /// Show an interactive filter & select popup
59    Filter(filter::FilterArgs),
60    /// Show an animated spinner popup
61    Spin(spin::SpinArgs),
62    /// Print a formatted log line
63    Log(log::LogArgs),
64    /// Open an interactive file browser
65    File(file::FileArgs),
66    /// Capture text input from the user
67    Input(input::InputArgs),
68    /// Interactive tree menu from JSON or plano input
69    Menu(menu::MenuArgs),
70    /// Self-update to the latest release
71    Update(update::UpdateArgs),
72}
73
74pub fn entrypoint() {
75    let cli = Cli::parse();
76
77    if cli.guide {
78        println!("{}", PANDORA_GUIDE);
79        return;
80    }
81
82    match cli.command {
83        Some(Commands::Confirm(args)) => confirm::run(args),
84        Some(Commands::Choose(args)) => choose::run(args),
85        Some(Commands::Filter(args)) => filter::run(args),
86        Some(Commands::Spin(args)) => spin::run(args),
87        Some(Commands::Log(args)) => log::run(args),
88        Some(Commands::File(args)) => file::run(args),
89        Some(Commands::Input(args)) => input::run(args),
90        Some(Commands::Menu(args)) => menu::run(args),
91        Some(Commands::Update(args)) => update::run(args),
92        None => {
93            let mut cmd = <Cli as clap::CommandFactory>::command();
94            cmd.print_help().unwrap();
95            println!();
96        }
97    }
98}