use crate::colors;
pub fn header(title: &str, context: Option<&str>, enabled: bool) -> String {
match context {
Some(context) => format!(
"{} {}",
colors::bold(&format!("◆ {title}"), enabled),
colors::dim(&format!("· {context}"), enabled)
),
None => colors::bold(&format!("◆ {title}"), enabled),
}
}
pub fn hint(text: &str, enabled: bool) -> String {
format!("hint: {}", colors::dim(text, enabled))
}
pub fn ok_mark(enabled: bool) -> String {
colors::green("✓", enabled)
}
pub fn fail_mark(enabled: bool) -> String {
colors::red("✗", enabled)
}
pub fn warn_mark(enabled: bool) -> String {
colors::yellow("!", enabled)
}
pub fn dim_label(text: &str, enabled: bool) -> String {
colors::dim(text, enabled)
}
pub fn section(title: &str, enabled: bool) -> String {
format!(
"{} {}",
colors::bold(title, enabled),
colors::dim(&"─".repeat(24), enabled)
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn header_without_context_is_bold_title_only() {
assert_eq!(header("Crukx gate", None, false), "◆ Crukx gate");
}
#[test]
fn header_with_context_appends_separator() {
assert_eq!(header("history", Some("last 5"), false), "◆ history · last 5");
}
#[test]
fn hint_prefixes_the_dimmed_text() {
assert_eq!(hint("run crukx capture", false), "hint: run crukx capture");
}
#[test]
fn color_enabled_paths_emit_escapes() {
assert!(header("gate", None, true).contains("\x1b[1m"));
assert!(colors::dim("ctx", true).contains("\x1b[2m"));
}
}