use std::io::IsTerminal;
pub fn is_piped() -> bool {
!std::io::stdout().is_terminal()
}
macro_rules! status {
($($arg:tt)*) => {
if $crate::output::is_piped() {
eprintln!($($arg)*);
} else {
println!($($arg)*);
}
};
}
pub(crate) use status;
pub fn colorize_description(desc: &str) -> String {
use colored::Colorize;
if let Some(rest) = desc.strip_prefix("[alpha] ") {
format!("{} {}", "[alpha]".bright_yellow().bold(), rest.dimmed())
} else if let Some(rest) = desc.strip_prefix("[beta] ") {
format!("{} {}", "[beta]".bright_yellow().bold(), rest.dimmed())
} else {
format!("{}", desc.dimmed())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_piped_returns_bool() {
let _ = is_piped();
}
#[test]
fn status_macro_does_not_panic() {
status!("test message");
status!("{} {}", "hello", "world");
}
#[test]
fn test_colorize_description_alpha() {
let result = colorize_description("[alpha] Experimental model");
assert!(result.contains("[alpha]"));
assert!(result.contains("Experimental model"));
}
#[test]
fn test_colorize_description_beta() {
let result = colorize_description("[beta] Experimental model");
assert!(result.contains("[beta]"));
assert!(result.contains("Experimental model"));
}
#[test]
fn test_colorize_description_no_tag() {
let result = colorize_description("A stable model description");
assert!(result.contains("A stable model description"));
}
#[test]
fn test_colorize_description_empty() {
let result = colorize_description("");
let _ = result;
}
}