pub const BANNER_ART: &str = r#" ██████╗ ███╗ ██╗ █████╗ ██╗ ██╗
██╔════╝ ████╗ ██║██╔══██╗██║ ██║
██║ ███╗██╔██╗ ██║███████║██║ █╗ ██║
██║ ██║██║╚██╗██║██╔══██║██║███╗██║
╚██████╔╝██║ ╚████║██║ ██║╚███╔███╔╝
╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝ ╚══╝╚══╝ "#;
pub const EMBER: (u8, u8, u8) = (0xFF, 0x67, 0x00);
pub fn subtitle() -> String {
format!("gnaw v{} · codebase → prompt", env!("CARGO_PKG_VERSION"))
}
use std::io::IsTerminal;
pub fn should_show(quiet: bool) -> bool {
if quiet {
return false;
}
if std::env::var_os("GNAW_NO_BANNER").is_some() {
return false;
}
std::io::stderr().is_terminal()
}
pub fn print_cli(quiet: bool) {
if !should_show(quiet) {
return;
}
eprintln!("{}", render_cli());
}
pub fn render_cli() -> String {
use colored::Colorize;
let art = BANNER_ART.truecolor(EMBER.0, EMBER.1, EMBER.2);
format!("{art}\n {}\n", subtitle().dimmed())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn quiet_suppresses_banner() {
assert!(!should_show(true));
}
#[test]
fn env_var_suppresses_banner() {
unsafe { std::env::set_var("GNAW_NO_BANNER", "1") };
assert!(!should_show(false));
unsafe { std::env::remove_var("GNAW_NO_BANNER") };
}
#[test]
fn cli_render_includes_version_and_tagline() {
let out = render_cli();
assert!(out.contains(env!("CARGO_PKG_VERSION")));
assert!(out.contains("codebase"));
}
#[test]
fn art_is_six_lines() {
assert_eq!(BANNER_ART.lines().count(), 6);
}
}