Standardize error messages, formatting, and code style. Refine --help text for consistency. Update comments for clarity and tone alignment.

This commit is contained in:
2026-08-13 17:50:06 +02:00
parent e36360e18c
commit 1b947fec24
7 changed files with 123 additions and 121 deletions

View File

@@ -1,9 +1,10 @@
//! Colorized status output, honoring `NO_COLOR` and terminal detection.
//! Colorized status output, honouring `NO_COLOR` and terminal detection.
use std::io::IsTerminal;
use std::sync::OnceLock;
fn color_enabled() -> bool {
fn color_enabled() -> bool
{
static ENABLED: OnceLock<bool> = OnceLock::new();
*ENABLED.get_or_init(|| {
std::env::var_os("NO_COLOR").is_none()
@@ -13,46 +14,19 @@ fn color_enabled() -> bool {
})
}
fn paint(code: &str, s: &str) -> String {
if color_enabled() {
format!("\x1b[{code}m{s}\x1b[0m")
} else {
s.to_string()
}
fn paint(code: &str, s: &str) -> String
{
if color_enabled() { format!("\x1b[{code}m{s}\x1b[0m") }
else { s.to_string() }
}
pub fn red(s: &str) -> String {
paint("31", s)
}
pub fn red(s: &str) -> String { paint("31", s) }
pub fn yellow(s: &str) -> String { paint("33", s) }
pub fn green(s: &str) -> String { paint("32", s) }
pub fn blue(s: &str) -> String { paint("34", s) }
pub fn cyan(s: &str) -> String { paint("36", s) }
pub fn yellow(s: &str) -> String {
paint("33", s)
}
pub fn green(s: &str) -> String {
paint("32", s)
}
pub fn blue(s: &str) -> String {
paint("34", s)
}
pub fn cyan(s: &str) -> String {
paint("36", s)
}
pub fn err(msg: &str) {
eprintln!("{}", red(&format!("Error: {msg}")));
}
pub fn warn(msg: &str) {
eprintln!("{}", yellow(&format!("Warning: {msg}")));
}
pub fn info(msg: &str) {
println!("{}", blue(msg));
}
pub fn ok(msg: &str) {
println!("{}", green(msg));
}
pub fn err(msg: &str) { eprintln!("{}", red(&format!("Error: {msg}"))); }
pub fn warn(msg: &str) { eprintln!("{}", yellow(&format!("Warning: {msg}"))); }
pub fn info(msg: &str) { println!("{}", blue(msg)); }
pub fn ok(msg: &str) { println!("{}", green(msg)); }