sublime_cli_tools/interactive/mod.rs
1//! Interactive prompt module for CLI commands.
2//!
3//! This module provides enhanced interactive user input functionality with
4//! fuzzy search, better validation, custom themes, and improved user experience.
5//!
6//! # What
7//!
8//! Provides:
9//! - Interactive prompts for user input (multi-select, single-select, text input)
10//! - Fuzzy search for package and environment selection
11//! - Enhanced visual feedback with custom theme
12//! - Real-time validation with helpful error messages
13//! - Confirmation dialogs with context and warnings
14//! - Package selection with git-based detection
15//! - Bump type selection with semantic versioning explanations
16//! - Environment selection with defaults
17//! - Summary/message text input
18//!
19//! # How
20//!
21//! Uses multiple specialized modules:
22//! - `theme`: Custom styled theme for consistent visual appearance
23//! - `validation`: Enhanced validation logic with helpful suggestions
24//! - `select`: Fuzzy search and enhanced selection capabilities
25//! - `confirm`: Enhanced confirmation dialogs with context
26//! - `prompts`: High-level prompt functions combining all features
27//!
28//! The module is built on:
29//! - `dialoguer` crate for terminal-based interactive prompts
30//! - `fuzzy-matcher` for fuzzy string matching
31//! - `console` for terminal styling
32//!
33//! All prompts are designed to be:
34//! - User-friendly with clear instructions
35//! - Fast and responsive with fuzzy search
36//! - Accessible across different terminal environments
37//! - Cancelable with proper error handling (Ctrl+C)
38//! - Consistent in appearance and behavior
39//!
40//! # Why
41//!
42//! Separating interactive functionality into specialized modules allows:
43//! - Reusable components across different commands
44//! - Consistent UX throughout the CLI
45//! - Easy testing with mock implementations
46//! - Clear separation between interactive and non-interactive modes
47//! - Better maintainability and extensibility
48//! - Enhanced user experience with modern features
49//!
50//! # Examples
51//!
52//! ## Using High-Level Prompts
53//!
54//! ```rust,no_run
55//! use sublime_cli_tools::interactive::prompts::{
56//! prompt_bump_type,
57//! prompt_packages,
58//! prompt_environments,
59//! prompt_summary,
60//! prompt_confirm,
61//! };
62//!
63//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
64//! // Interactive bump type selection
65//! let bump = prompt_bump_type(false)?;
66//! println!("User selected: {}", bump);
67//!
68//! // Interactive package selection with fuzzy search
69//! let packages = vec!["pkg-a".to_string(), "pkg-b".to_string()];
70//! let detected = vec!["pkg-a".to_string()];
71//! let selected = prompt_packages(&packages, &detected, false)?;
72//! println!("Selected packages: {:?}", selected);
73//!
74//! // Interactive environment selection
75//! let envs = vec!["dev".to_string(), "staging".to_string(), "prod".to_string()];
76//! let defaults = vec!["staging".to_string()];
77//! let selected_envs = prompt_environments(&envs, &defaults, false)?;
78//!
79//! // Text input with validation
80//! let summary = prompt_summary(None, false)?;
81//!
82//! // Confirmation with context
83//! if prompt_confirm("Proceed?", true, false)? {
84//! println!("Proceeding...");
85//! }
86//! # Ok(())
87//! # }
88//! ```
89//!
90//! ## Using Low-Level Components
91//!
92//! ```rust,no_run
93//! use sublime_cli_tools::interactive::{select, confirm, validation, theme};
94//!
95//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
96//! // Use fuzzy select directly
97//! let items = vec!["item1", "item2", "item3"];
98//! let selection = select::fuzzy_select("Choose", &items, Some(0), false)?;
99//!
100//! // Use validation directly
101//! validation::validate_non_empty("user input")?;
102//!
103//! // Use confirm with items
104//! let packages = vec!["pkg-a", "pkg-b"];
105//! confirm::confirm_with_items("upgrade", &packages, true, false)?;
106//!
107//! // Use custom theme
108//! let theme = theme::WntTheme::new(false);
109//! # Ok(())
110//! # }
111//! ```
112
113// Module declarations
114pub mod confirm;
115pub mod prompts;
116pub mod select;
117pub mod theme;
118pub mod validation;
119
120#[cfg(test)]
121mod tests;
122
123// Re-export commonly used prompt functions for convenience
124pub use prompts::{
125 prompt_bump_type, prompt_confirm, prompt_confirm_dangerous, prompt_confirm_with_context,
126 prompt_environments, prompt_packages, prompt_summary,
127};
128
129// Re-export theme for external use
130pub use theme::WntTheme;
131
132// Re-export select functions for advanced usage
133pub use select::{
134 fuzzy_filter, fuzzy_multi_select, fuzzy_select, select_environments, select_packages,
135};
136
137// Re-export confirm functions for advanced usage
138pub use confirm::{
139 confirm, confirm_dangerous, confirm_with_context, confirm_with_details, confirm_with_items,
140};
141
142// Re-export validation functions for external use
143pub use validation::{
144 validate_at_least_one_selected, validate_bump_type, validate_environment_names,
145 validate_non_empty, validate_package_names,
146};