pets_tools 0.2.0

MusKitty multi-repo source management CLI — one command to clone, build, test, push, and publish 9 independent crate repositories
//! Colored terminal output utilities.
//! Zero external deps — uses ANSI escape codes directly.

/// Print a green success message.
pub fn success(msg: &str) {
    println!("\x1b[32m✓\x1b[0m {}", msg);
}

/// Print a red error message.
pub fn error(msg: &str) {
    eprintln!("\x1b[31m✗ {}\x1b[0m", msg);
}

/// Print a yellow warning.
pub fn warn(msg: &str) {
    eprintln!("\x1b[33m⚠ {}\x1b[0m", msg);
}

/// Print a cyan info message.
pub fn info(msg: &str) {
    println!("\x1b[36m  {}\x1b[0m", msg);
}

/// Print a bold heading.
pub fn heading(msg: &str) {
    println!("\x1b[1;34m{}\x1b[0m", msg);
}

/// Render a status table with aligned columns.
/// Columns: name, branch, status, ahead/behind, last commit
pub fn status_table(rows: &[(String, String, String, String, String)]) {
    if rows.is_empty() {
        info("(no repos found)");
        return;
    }

    // Column widths
    let mut w_name = 4; // "REPO"
    let mut w_branch = 6;
    let mut w_status = 6;
    let mut w_ab = 12; // "AHEAD/BEHIND"
    let mut w_commit = 11;

    for (name, branch, status, ab, commit) in rows {
        w_name = w_name.max(name.len());
        w_branch = w_branch.max(branch.len());
        w_status = w_status.max(status.len());
        w_ab = w_ab.max(ab.len());
        w_commit = w_commit.max(commit.len());
    }

    // Header
    let header = format!(
        "  {:<w_name$}  {:<w_branch$}  {:<w_status$}  {:<w_ab$}  {:<w_commit$}",
        "REPO",
        "BRANCH",
        "STATUS",
        "AHEAD/BEHIND",
        "LAST COMMIT",
        w_name = w_name,
        w_branch = w_branch,
        w_status = w_status,
        w_ab = w_ab,
        w_commit = w_commit,
    );
    println!("\x1b[1m{}\x1b[0m", header);
    println!("{}", "-".repeat(header.len() + 2));

    // Rows
    for (name, branch, status, ab, commit) in rows {
        let color = if status == "clean" || status == "ok" {
            "\x1b[32m"
        } else {
            "\x1b[33m"
        };
        println!(
            "  {:<w_name$}  {:<w_branch$}  {}{:<w_status$}\x1b[0m  {:<w_ab$}  {:<w_commit$}",
            name,
            branch,
            color,
            status,
            ab,
            commit,
            w_name = w_name,
            w_branch = w_branch,
            w_status = w_status,
            w_ab = w_ab,
            w_commit = w_commit,
        );
    }
}

/// Print a summary line like "3 updated, 4 up-to-date, 1 failed".
pub fn summary(updated: usize, skipped: usize, failed: usize) {
    let mut parts = vec![];
    if updated > 0 {
        parts.push(format!("\x1b[32m{} updated\x1b[0m", updated));
    }
    if skipped > 0 {
        parts.push(format!("{} up-to-date", skipped));
    }
    if failed > 0 {
        parts.push(format!("\x1b[31m{} failed\x1b[0m", failed));
    }
    println!("\n  {}", parts.join(", "));
}

/// Print a separator line.
pub fn separator() {
    println!("{}", "-".repeat(60));
}