use std::io::IsTerminal;
use std::sync::Once;
use colored::{ColoredString, Colorize};
pub const ROBOT: &str = "🤖";
pub const NOTE: &str = "📝";
pub const TODO: &str = "✅";
pub const FILE: &str = "📄";
pub const TIME: &str = "⏱";
pub const BRAIN: &str = "🧠";
pub const SAVE: &str = "💾";
pub const BOLT: &str = "⚡";
pub const OK_GLYPH: &str = "✓";
pub const WARN_GLYPH: &str = "⚠";
pub const ERR_GLYPH: &str = "❌";
pub const MAG: &str = "🔍";
pub const SPARKLES: &str = "✨";
pub const GEAR: &str = "⚙";
pub const PROMPT_ARROW: &str = "›";
pub fn init() {
static INIT: Once = Once::new();
INIT.call_once(|| {
if !std::io::stderr().is_terminal() {
colored::control::set_override(false);
}
});
}
#[must_use]
pub fn accent(s: &str) -> ColoredString {
s.cyan().bold()
}
#[must_use]
pub fn info(s: &str) -> ColoredString {
s.bright_blue()
}
#[must_use]
pub fn warn(s: &str) -> ColoredString {
s.yellow()
}
#[must_use]
pub fn error(s: &str) -> ColoredString {
s.red().bold()
}
#[must_use]
pub fn dim(s: &str) -> ColoredString {
s.dimmed()
}
#[must_use]
pub fn ok(s: &str) -> ColoredString {
s.green()
}
#[must_use]
pub fn brand(s: &str) -> ColoredString {
s.magenta().bold()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn init_is_idempotent() {
init();
init();
init();
}
#[test]
fn all_helpers_round_trip_text() {
let funcs: [fn(&str) -> ColoredString; 7] = [accent, info, warn, error, dim, ok, brand];
for f in funcs {
let s = f("hello");
assert!(
format!("{s}").contains("hello"),
"helper dropped the inner text"
);
}
}
#[test]
fn emoji_constants_are_non_empty() {
let glyphs = [
ROBOT,
NOTE,
TODO,
FILE,
TIME,
BRAIN,
SAVE,
BOLT,
OK_GLYPH,
WARN_GLYPH,
ERR_GLYPH,
MAG,
SPARKLES,
GEAR,
PROMPT_ARROW,
];
for g in glyphs {
assert!(!g.is_empty(), "empty glyph found");
}
}
}