openlatch-provider 0.2.1

Self-service onboarding CLI + runtime daemon for OpenLatch Editors and Providers
//! "OpenLatch Provider" branded header — port of openlatch-client
//! `src/cli/header.rs` adapted to print over the 4-mode `OutputConfig`, to
//! say "OpenLatch Provider" instead of "OpenLatch", and to render in magenta
//! (vs. openlatch-client's cyan) so the two tools are visually distinct in a
//! shared terminal.
//!
//! Silent in JSON mode and `--quiet`. Writes to stderr so it never
//! contaminates piped stdout.

use crate::ui::output::{OutputConfig, OutputFormat};

const LABEL: &str = " OpenLatch Provider ";
const LEAD: usize = 3;
const FALLBACK_WIDTH: usize = 50;
const MAX_WIDTH: usize = 120;

fn build_rule(color: bool) -> String {
    let detected = terminal_size::terminal_size()
        .map(|(w, _)| w.0 as usize)
        .unwrap_or(FALLBACK_WIDTH);
    let min_width = LEAD + LABEL.chars().count() + 1;
    let width = detected.clamp(min_width, MAX_WIDTH);

    let fill = if color { '' } else { '=' };
    let lead: String = std::iter::repeat_n(fill, LEAD).collect();
    let tail_len = width - LEAD - LABEL.chars().count();
    let tail: String = std::iter::repeat_n(fill, tail_len).collect();

    if color {
        // ANSI 35 = magenta/purple; differentiates the provider from the
        // openlatch-client banner, which uses cyan (36).
        format!("\x1b[35m{lead}{LABEL}{tail}\x1b[0m")
    } else {
        format!("{lead}{LABEL}{tail}")
    }
}

pub fn print_full_banner(output: &OutputConfig) {
    if output.format == OutputFormat::Json || output.quiet {
        return;
    }
    println!("{}", build_rule(output.color));
}

pub fn print(output: &OutputConfig, parts: &[&str]) {
    if output.format == OutputFormat::Json || output.quiet {
        return;
    }
    eprintln!("{}", build_rule(output.color));

    let version = env!("CARGO_PKG_VERSION");
    let mut line = format!("    v{version}");
    for part in parts.iter().filter(|p| !p.is_empty()) {
        line.push_str(" · ");
        line.push_str(part);
    }
    eprintln!("{line}");
}