use colored::{ColoredString, Colorize};
use indicatif::ProgressStyle;
use std::io::IsTerminal;
use std::sync::Once;
pub const MOSS: (u8, u8, u8) = (0x3F, 0x6B, 0x4E);
pub const BRASS: (u8, u8, u8) = (0x8A, 0x6A, 0x1F);
pub const DUST: (u8, u8, u8) = (0x7A, 0x6F, 0x5C);
pub const MADDER: (u8, u8, u8) = (0x8A, 0x3A, 0x3A);
pub const SIGNAL: (u8, u8, u8) = (0x3B, 0x5B, 0xDB);
static INIT: Once = Once::new();
pub fn init() {
INIT.call_once(|| {
let no_color = std::env::var_os("NO_COLOR").is_some();
let is_tty = std::io::stdout().is_terminal();
if no_color || !is_tty {
colored::control::set_override(false);
}
});
}
#[must_use]
pub fn dim(s: &str) -> ColoredString {
s.dimmed()
}
#[must_use]
pub fn mono_eyebrow(label: &str) -> ColoredString {
label.dimmed()
}
#[must_use]
pub fn tick_row(width: usize) -> String {
let row = "·".repeat(width);
format!("{}", row.dimmed())
}
#[must_use]
pub fn moss(s: impl AsRef<str>) -> ColoredString {
let (r, g, b) = MOSS;
s.as_ref().truecolor(r, g, b)
}
#[must_use]
pub fn madder(s: impl AsRef<str>) -> ColoredString {
let (r, g, b) = MADDER;
s.as_ref().truecolor(r, g, b)
}
#[must_use]
pub fn brass(s: impl AsRef<str>) -> ColoredString {
let (r, g, b) = BRASS;
s.as_ref().truecolor(r, g, b)
}
#[must_use]
pub fn dust_color(s: impl AsRef<str>) -> ColoredString {
let (r, g, b) = DUST;
s.as_ref().truecolor(r, g, b)
}
#[must_use]
pub fn signal(s: impl AsRef<str>) -> ColoredString {
let (r, g, b) = SIGNAL;
s.as_ref().truecolor(r, g, b)
}
#[must_use]
pub fn chip(label: &str, rgb: (u8, u8, u8)) -> String {
let dot = "·".truecolor(rgb.0, rgb.1, rgb.2);
let text = label.truecolor(rgb.0, rgb.1, rgb.2);
format!("{dot} {text}")
}
#[must_use]
pub fn ok(label: &str) -> String {
chip(label, MOSS)
}
#[must_use]
pub fn warn(label: &str) -> String {
chip(label, BRASS)
}
#[must_use]
pub fn stale(label: &str) -> String {
chip(label, DUST)
}
#[must_use]
pub fn lost(label: &str) -> String {
chip(label, MADDER)
}
#[must_use]
pub fn live(label: &str) -> String {
chip(label, SIGNAL)
}
pub fn header(eyebrow: &str, title: &str) {
println!(" {}", eyebrow.dimmed());
println!(" {}", title.bold());
println!(" {}", tick_row(60));
}
#[must_use]
pub fn err_prefix() -> String {
let (r, g, b) = MADDER;
format!("{}", "err ·".truecolor(r, g, b))
}
#[must_use]
pub fn progress_style(unit: &str) -> ProgressStyle {
let template = format!(" {{bar:30}} {{pos}}/{{len}} · {unit} · {{msg}}");
ProgressStyle::with_template(&template)
.unwrap_or_else(|_| ProgressStyle::default_bar())
.progress_chars("──╌")
}