offline-cli 0.3.3

The Offline Protocol developer CLI
//! Output helpers: consistent human formatting + `--json` machine output.

use console::style;
use serde::Serialize;

/// Print a value as pretty JSON (for `--json` mode).
pub fn json<T: Serialize>(value: &T) -> anyhow::Result<()> {
    println!("{}", serde_json::to_string_pretty(value)?);
    Ok(())
}

pub fn heading(text: &str) {
    println!("\n{}", style(text).bold().underlined());
}

pub fn success(text: &str) {
    println!("{} {text}", style("✓").green().bold());
}

pub fn warn(text: &str) {
    println!("{} {text}", style("!").yellow().bold());
}

/// Progress while work happens: on stderr, so `--json` output on stdout stays
/// one JSON document.
pub fn progress(text: &str) {
    eprintln!("  {}", style(text).dim());
}

pub fn note(text: &str) {
    println!("  {}", style(text).dim());
}

pub fn item(name: &str, detail: &str) {
    println!("  {} {}", style(name).cyan(), style(detail).dim());
}