Module interactive

Module interactive 

Source
Expand description

Interactive prompts and user input Interactive prompt module for CLI commands.

This module provides enhanced interactive user input functionality with fuzzy search, better validation, custom themes, and improved user experience.

§What

Provides:

  • Interactive prompts for user input (multi-select, single-select, text input)
  • Fuzzy search for package and environment selection
  • Enhanced visual feedback with custom theme
  • Real-time validation with helpful error messages
  • Confirmation dialogs with context and warnings
  • Package selection with git-based detection
  • Bump type selection with semantic versioning explanations
  • Environment selection with defaults
  • Summary/message text input

§How

Uses multiple specialized modules:

  • theme: Custom styled theme for consistent visual appearance
  • validation: Enhanced validation logic with helpful suggestions
  • select: Fuzzy search and enhanced selection capabilities
  • confirm: Enhanced confirmation dialogs with context
  • prompts: High-level prompt functions combining all features

The module is built on:

  • dialoguer crate for terminal-based interactive prompts
  • fuzzy-matcher for fuzzy string matching
  • console for terminal styling

All prompts are designed to be:

  • User-friendly with clear instructions
  • Fast and responsive with fuzzy search
  • Accessible across different terminal environments
  • Cancelable with proper error handling (Ctrl+C)
  • Consistent in appearance and behavior

§Why

Separating interactive functionality into specialized modules allows:

  • Reusable components across different commands
  • Consistent UX throughout the CLI
  • Easy testing with mock implementations
  • Clear separation between interactive and non-interactive modes
  • Better maintainability and extensibility
  • Enhanced user experience with modern features

§Examples

§Using High-Level Prompts

use sublime_cli_tools::interactive::prompts::{
    prompt_bump_type,
    prompt_packages,
    prompt_environments,
    prompt_summary,
    prompt_confirm,
};

// Interactive bump type selection
let bump = prompt_bump_type(false)?;
println!("User selected: {}", bump);

// Interactive package selection with fuzzy search
let packages = vec!["pkg-a".to_string(), "pkg-b".to_string()];
let detected = vec!["pkg-a".to_string()];
let selected = prompt_packages(&packages, &detected, false)?;
println!("Selected packages: {:?}", selected);

// Interactive environment selection
let envs = vec!["dev".to_string(), "staging".to_string(), "prod".to_string()];
let defaults = vec!["staging".to_string()];
let selected_envs = prompt_environments(&envs, &defaults, false)?;

// Text input with validation
let summary = prompt_summary(None, false)?;

// Confirmation with context
if prompt_confirm("Proceed?", true, false)? {
    println!("Proceeding...");
}

§Using Low-Level Components

use sublime_cli_tools::interactive::{select, confirm, validation, theme};

// Use fuzzy select directly
let items = vec!["item1", "item2", "item3"];
let selection = select::fuzzy_select("Choose", &items, Some(0), false)?;

// Use validation directly
validation::validate_non_empty("user input")?;

// Use confirm with items
let packages = vec!["pkg-a", "pkg-b"];
confirm::confirm_with_items("upgrade", &packages, true, false)?;

// Use custom theme
let theme = theme::WntTheme::new(false);

Re-exports§

pub use prompts::prompt_bump_type;
pub use prompts::prompt_confirm;
pub use prompts::prompt_confirm_dangerous;
pub use prompts::prompt_confirm_with_context;
pub use prompts::prompt_environments;
pub use prompts::prompt_packages;
pub use prompts::prompt_summary;
pub use theme::WntTheme;
pub use select::fuzzy_filter;
pub use select::fuzzy_multi_select;
pub use select::fuzzy_select;
pub use select::select_environments;
pub use select::select_packages;
pub use confirm::confirm;
pub use confirm::confirm_dangerous;
pub use confirm::confirm_with_context;
pub use confirm::confirm_with_details;
pub use confirm::confirm_with_items;
pub use validation::validate_at_least_one_selected;
pub use validation::validate_bump_type;
pub use validation::validate_environment_names;
pub use validation::validate_non_empty;
pub use validation::validate_package_names;

Modules§

confirm
Enhanced confirmation prompts.
prompts
Interactive prompts for CLI commands.
select
Enhanced selection prompts with fuzzy search.
theme
Custom theme for interactive prompts.
validation
Validation utilities for interactive prompts.