use crate::cli::output::{OutputConfig, OutputFormat};
const LABEL: &str = " OpenLatch ";
const LEAD: usize = 3;
const FALLBACK_WIDTH: usize = 44;
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 {
format!("\x1b[36m{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}");
}