use crate::template::{PathResolver, TemplateStats};
use console::{style, Term};
pub fn display_banner() {
let term = Term::stdout();
let version = env!("CARGO_PKG_VERSION");
let banner = r#"
██████╗███████╗██████╗ ████████╗ ██╗ ██╗ ██████╗ ███████╗███╗ ██╗
██╔════╝██╔════╝██╔══██╗╚══██╔══╝ ╚██╗██╔╝ ██╔════╝ ██╔════╝████╗ ██║
██║ █████╗ ██████╔╝ ██║ █████╗ ╚███╔╝█████╗██║ ███╗█████╗ ██╔██╗ ██║
██║ ██╔══╝ ██╔══██╗ ██║ ╚════╝ ██╔██╗╚════╝██║ ██║██╔══╝ ██║╚██╗██║
╚██████╗███████╗██║ ██║ ██║ ██╔╝ ██╗ ╚██████╔╝███████╗██║ ╚████║
╚═════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝
"#
.to_string();
let _ = term.write_line(&style(banner).cyan().to_string());
let stats = TemplateStats::from_all_directories();
let template_info = if stats.total > 0 {
format_template_stats(&stats)
} else {
"No templates installed. Run: cxg template update".to_string()
};
let info_line = format!(
" {} v{} | {}",
style("cxg").bold(),
version,
template_info
);
let _ = term.write_line(&style(info_line).dim().to_string());
let _ = term.write_line(&style("=".repeat(80)).dim().to_string());
let _ = term.write_line("");
}
fn format_template_stats(stats: &TemplateStats) -> String {
let mut parts: Vec<String> = Vec::new();
let mut langs: Vec<_> = stats.by_language.iter().collect();
langs.sort_by(|a, b| b.1.cmp(a.1));
for (lang, count) in langs.iter().take(4) {
let short_lang = match lang.as_str() {
"javascript" => "js",
"python" => "py",
"shell" => "sh",
_ => lang.as_str(),
};
parts.push(format!("{}: {}", short_lang, count));
}
format!("{} templates ({})", stats.total, parts.join(", "))
}
pub fn display_minimal_banner() {
let version = env!("CARGO_PKG_VERSION");
let stats = TemplateStats::from_all_directories();
let template_info = if stats.total > 0 {
format!(" | {} templates", stats.total)
} else {
String::new()
};
println!(
"{}",
style(format!("cxg v{}{}", version, template_info))
.cyan()
.bold()
);
}
pub fn get_template_version() -> Option<String> {
let user_dir = PathResolver::user_template_dir().join("official");
if !user_dir.exists() {
return None;
}
if let Ok(repo) = git2::Repository::open(&user_dir) {
if let Ok(head) = repo.head() {
if let Some(commit) = head.target() {
return Some(commit.to_string()[..8].to_string());
}
}
}
None
}