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
22pub mod badge;
23mod choose;
24mod confirm;
25pub mod drag;
26mod file;
27mod filter;
28mod input;
29mod keybinds;
30mod log;
31mod menu;
32pub mod popup_config;
33pub mod popup_rect;
34mod spin;
35mod style;
36mod tty;
37mod update;
38
39use clap::{Parser, Subcommand};
40
41const PANDORA_GUIDE: &str = include_str!("../guides/PANDORA_GUIDE.md");
42pub const BIN_NAME: &str = "pan";
43
44#[derive(Parser)]
45#[command(name = BIN_NAME, about = "CLI toolkit with interactive TUI popups", version = env!("CARGO_PKG_VERSION"))]
46struct Cli {
47    /// Display the complete pan guide
48    #[arg(long)]
49    guide: bool,
50
51    #[command(subcommand)]
52    command: Option<Commands>,
53}
54
55#[derive(Subcommand)]
56enum Commands {
57    /// Show a confirmation popup, returns 0 on accept, 1 on cancel
58    Confirm(confirm::ConfirmArgs),
59    /// Show an interactive item selector
60    Choose(choose::ChooseArgs),
61    /// Show an interactive filter & select popup
62    Filter(filter::FilterArgs),
63    /// Show an animated spinner popup
64    Spin(spin::SpinArgs),
65    /// Print a formatted log line
66    Log(log::LogArgs),
67    /// Open an interactive file browser
68    File(file::FileArgs),
69    /// Capture text input from the user
70    Input(input::InputArgs),
71    /// Interactive tree menu from JSON or plano input
72    Menu(menu::MenuArgs),
73    /// Self-update to the latest release
74    Update(update::UpdateArgs),
75}
76
77pub fn entrypoint() {
78    let cli = Cli::parse();
79
80    if cli.guide {
81        println!("{}", PANDORA_GUIDE);
82        return;
83    }
84
85    match cli.command {
86        Some(Commands::Confirm(args)) => confirm::run(args),
87        Some(Commands::Choose(args)) => choose::run(args),
88        Some(Commands::Filter(args)) => filter::run(args),
89        Some(Commands::Spin(args)) => spin::run(args),
90        Some(Commands::Log(args)) => log::run(args),
91        Some(Commands::File(args)) => file::run(args),
92        Some(Commands::Input(args)) => input::run(args),
93        Some(Commands::Menu(args)) => menu::run(args),
94        Some(Commands::Update(args)) => update::run(args),
95        None => {
96            let mut cmd = <Cli as clap::CommandFactory>::command();
97            cmd.print_help().unwrap();
98            println!();
99        }
100    }
101}