lupa 0.1.1

Interactive object inspector for Rust — web UI + TUI + snapshot diffing
Documentation
//! # TUI example for `lupa`
//!
//! This example shows how to use the terminal‑based inspector (TUI) instead of
//! the web UI. It defines a more complex nested state (`AppState` containing
//! `User` and `Session`), takes snapshots, mutates the data, and finally
//! displays a diff – all inside the terminal.
//!
//! ## Run
//! ```bash
//! cargo run --example tui --features tui
//! ```
//!
//! **Note:** The `web` feature is **not** enabled by default here, so no HTTP
//! server is started. The inspector runs entirely in the terminal.
//!
//! ## Key bindings (once the TUI starts)
//! - `↑` / `↓` – move selection
//! - `Tab` – switch between Snapshots and Diffs panels
//! - `Enter` – expand / collapse the detail view
//! - `PgUp` / `PgDn` – scroll
//! - `q`, `Esc`, or `Ctrl+C` – quit the TUI

use lupa::{inspect, snapshot, snapshot_diff, RunMode};

// ---------- Data model ----------

/// The main application state – a combination of a user and a session.
#[derive(Debug, Clone)]
struct AppState {
    user: User,
    session: Session,
}

/// A simple user with id, name, and role.
#[derive(Debug, Clone)]
struct User {
    id: u64,
    name: String,
    role: Role,
}

#[derive(Debug, Clone)]
enum Role {
    Guest,
    Admin,
}

/// Session data containing a token, request/error counters, and tags.
#[derive(Debug, Clone)]
struct Session {
    token: String,
    requests: u32,
    errors: u32,
    tags: Vec<String>,
}

// ---------- Main ----------

fn main() {
    // Initial state.
    let mut state = AppState {
        user: User {
            id: 1,
            name: "Alice".into(),
            role: Role::Guest,
        },
        session: Session {
            token: "abc123".into(),
            requests: 0,
            errors: 0,
            tags: vec!["fresh".into()],
        },
    };

    // First snapshot – the untouched state.
    inspect!(state);
    let before = snapshot!(state);

    // Simulate some work: update session counters, add a tag, promote user.
    state.session.requests = 42;
    state.session.errors = 3;
    state.session.tags.push("active".into());
    state.user.role = Role::Admin;

    // Second snapshot after modifications.
    inspect!(state);
    // Show a diff between the initial and the modified state.
    snapshot_diff!(before, state);

    println!("Snapshots sent. Launching TUI inspector...\n");
    // Start the terminal UI – this will block until the user quits.
    lupa::run_mode(RunMode::Tui).unwrap();
}