inspect-rs 0.1.0

Universal introspection for Rust
Documentation
//! Demonstration of all premium semantic themes in inspect-rs.
//!
//! Run all themes:
//! ```bash
//! cargo run --example colored
//! ```
//!
//! Or demo a specific theme by name:
//! ```bash
//! cargo run --example colored -- gruvbox
//! cargo run --example colored -- nord
//! cargo run --example colored -- dracula
//! cargo run --example colored -- tokyo-night
//! cargo run --example colored -- catppuccin
//! cargo run --example colored -- one-dark
//! cargo run --example colored -- solarized-dark
//! cargo run --example colored -- solarized-light
//! cargo run --example colored -- monokai
//! cargo run --example colored -- ayu-dark
//! cargo run --example colored -- monochrome
//! ```

use inspect_rs::{
    AnsiColor, Inspect, InspectCx, Style, StyleRole, Theme, TreeConfig, format_tree_with,
};

#[derive(Inspect)]
struct Server {
    host: String,
    port: u16,
    running: bool,
    database: Database,
}

#[derive(Inspect)]
struct Database {
    engine: DatabaseEngine,
    #[inspect(secret)]
    password: String,
    nodes: Vec<String>,
}

#[derive(Inspect)]
#[allow(dead_code)]
enum DatabaseEngine {
    Postgres { pool_size: u32 },
    Mysql,
    Sqlite,
}

fn sample_server() -> Server {
    Server {
        host: "127.0.0.1".to_string(),
        port: 8080,
        running: true,
        database: Database {
            engine: DatabaseEngine::Postgres { pool_size: 32 },
            password: "super_secret_production_password!".to_string(),
            nodes: vec![
                "db-primary.internal".to_string(),
                "db-replica-1.internal".to_string(),
                "db-replica-2.internal".to_string(),
            ],
        },
    }
}

fn main() {
    let server = sample_server();
    let mut cx = InspectCx::new();
    let inspected = server.inspect(&mut cx);

    let specific_theme = std::env::args().nth(1);

    if let Some(ref name) = specific_theme {
        if name != "all" && name != "--all" {
            if let Some(theme) = Theme::by_name(name) {
                println!("=== Theme: {} ===", name);
                let config = TreeConfig::colored().with_theme(theme);
                println!("{}", format_tree_with(&inspected, config));
                return;
            } else {
                eprintln!("Unknown theme '{}'. Available themes:", name);
                for theme_name in Theme::NAMES {
                    eprintln!("  - {}", theme_name);
                }
                std::process::exit(1);
            }
        }
    }

    let all_themes: &[(&str, &str, Theme)] = &[
        ("1. Default Dark", "Warm copper & soft slate for dark terminals", Theme::dark()),
        ("2. Gruvbox", "Iconic warm, earthy retro groove palette", Theme::gruvbox()),
        ("3. Nord", "Arctic, cool bluish-slate palette", Theme::nord()),
        ("4. Dracula", "Vibrant dark theme with purple and cyan accents", Theme::dracula()),
        ("5. Catppuccin Mocha", "Soft pastel comfort palette", Theme::catppuccin_mocha()),
        (
            "6. Tokyo Night",
            "Neon dark city aesthetic inspired by Tokyo nightlife",
            Theme::tokyo_night(),
        ),
        ("7. One Dark", "Atom & VS Code iconic editor palette", Theme::one_dark()),
        ("8. Solarized Dark", "Ethan Schoonover's precision dark palette", Theme::solarized_dark()),
        (
            "9. Solarized Light",
            "Precision Solarized light background palette",
            Theme::solarized_light(),
        ),
        ("10. Light", "High-contrast palette for light backgrounds", Theme::light()),
        ("11. Monokai", "Classic Sublime Text high-contrast palette", Theme::monokai()),
        ("12. Ayu Dark", "Modern warm dark editor palette", Theme::ayu_dark()),
        ("13. ANSI 16", "Universal 4-bit standard ANSI for restricted terminals", Theme::ansi16()),
        (
            "14. Monochrome",
            "Pure terminal effects (bold, dim, italic, underline) with zero colors",
            Theme::monochrome(),
        ),
    ];

    for (title, desc, theme) in all_themes {
        println!("=== {} ({}) ===", title, desc);
        let config = TreeConfig::colored().with_theme(*theme);
        println!("{}", format_tree_with(&inspected, config));
    }

    println!("=== 15. Truncation Limits (Max 2 Items) ===");
    let truncated_cfg = TreeConfig::colored().with_max_items(2);
    println!("{}", format_tree_with(&inspected, truncated_cfg));

    println!("=== 16. Custom Theme (Custom Colors via Builder) ===");
    let custom_theme = Theme::dark()
        .with(StyleRole::Type, Style::new().bold().fg_ansi(AnsiColor::BrightYellow))
        .with(StyleRole::Field, Style::new().fg_ansi(AnsiColor::BrightCyan))
        .with(StyleRole::String, Style::new().fg_ansi(AnsiColor::BrightGreen));
    let custom_cfg = TreeConfig::colored().with_theme(custom_theme);
    println!("{}", format_tree_with(&inspected, custom_cfg));

    println!("=== 17. Clean Plain / No-Color Output (Piped or redirected) ===");
    let plain_cfg = TreeConfig::plain();
    println!("{}", format_tree_with(&inspected, plain_cfg));
}