use owo_colors::{OwoColorize, Style};
pub fn accent() -> Style {
Style::new().magenta()
}
pub fn muted() -> Style {
Style::new().bright_black()
}
pub fn strong() -> Style {
Style::new().bold()
}
pub fn success() -> Style {
Style::new().green()
}
pub fn warning() -> Style {
Style::new().yellow()
}
pub fn danger() -> Style {
Style::new().red()
}
pub fn state_style(state: &str) -> Style {
match state {
"active" => success(),
"deploying" => accent(),
"sleeping" => Style::new().cyan(),
"degraded" => warning(),
"crashed" | "failed" => danger(),
_ => muted(),
}
}
pub fn state_word(state: &str) -> &str {
match state {
"draft" | "idle" => "sin desplegar",
"deploying" => "desplegando",
"active" => "en marcha",
"sleeping" => "dormido",
"degraded" => "con problemas",
"crashed" => "ha caído",
"failed" => "ha fallado",
"removing" => "eliminando",
other => other,
}
}
pub fn deployment_status_style(status: &str) -> Style {
match status {
"active" => success(),
"queued" | "building" | "deploying" => accent(),
"failed" | "crashed" | "cancelled" => danger(),
_ => muted(),
}
}
pub fn state_dot(state: &str) -> String {
format!("{}", "●".style(state_style(state)))
}
pub const CHECK: &str = "✔";
pub const CROSS: &str = "✖";
pub const SKIP: &str = "–";
pub const PENDING: &str = "○";
pub const ARROW: &str = "→";
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_should_translate_a_running_service() {
assert_eq!(state_word("active"), "en marcha");
}
#[test]
fn it_should_pass_an_unknown_state_through_unchanged() {
assert_eq!(state_word("something-new"), "something-new");
}
}