use std::sync::OnceLock;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Tier {
NerdFont,
Unicode,
Ascii,
}
fn tier() -> Tier {
static T: OnceLock<Tier> = OnceLock::new();
*T.get_or_init(|| {
match std::env::var("POWERLINERS_ICONS")
.ok()
.as_deref()
.map(str::trim)
.map(str::to_ascii_lowercase)
.as_deref()
{
Some("ascii") => Tier::Ascii,
Some("unicode") => Tier::Unicode,
_ => Tier::NerdFont,
}
})
}
fn pick(nf: &'static str, uni: &'static str, ascii: &'static str) -> &'static str {
match tier() {
Tier::NerdFont => nf,
Tier::Unicode => uni,
Tier::Ascii => ascii,
}
}
pub fn disk() -> &'static str {
pick("\u{F0A0}", "⛁", "D:")
}
pub fn cpu() -> &'static str {
pick("\u{F4BC}", "⚙\u{FE0E}", "CPU:")
}
pub fn gpu() -> &'static str {
pick("\u{F2DB}", "⎚", "GPU:")
}
pub fn memory() -> &'static str {
pick("\u{EFC5}", "▤", "MEM:")
}
pub fn thermometer() -> &'static str {
pick("\u{F2C8}", "🌡\u{FE0E}", "T:")
}
pub fn branch() -> &'static str {
pick("\u{E0A0}", "", "b:")
}
pub fn github() -> &'static str {
pick("\u{F09B}", "", "gh:")
}
pub fn tag() -> &'static str {
pick("\u{F02B}", "⚑", "tag:")
}
pub fn docker() -> &'static str {
pick("\u{ED7E}", "🐳\u{FE0E}", "D:")
}
pub fn kubernetes() -> &'static str {
pick("\u{F10FE}", "⎈", "k8s:")
}
pub fn process() -> &'static str {
pick("\u{F0493}", "⚙\u{FE0E}", "P:")
}
pub fn weather_sunny() -> &'static str {
pick("\u{E30D}", "☀", "SUN")
}
pub fn weather_night() -> &'static str {
pick("\u{E32B}", "☾", "NIGHT")
}
pub fn weather_rainy() -> &'static str {
pick("\u{E318}", "☔", "RAIN")
}
pub fn weather_cloudy() -> &'static str {
pick("\u{E312}", "☁", "CLOUDS")
}
pub fn weather_snowy() -> &'static str {
pick("\u{E31A}", "❄", "SNOW")
}
pub fn weather_stormy() -> &'static str {
pick("\u{E31D}", "⛈", "STORM")
}
pub fn weather_foggy() -> &'static str {
pick("\u{E313}", "🌫", "FOG")
}
pub fn weather_windy() -> &'static str {
pick("\u{E31F}", "🌬", "WIND")
}
pub fn weather_unknown() -> &'static str {
pick("\u{E374}", "?", "?")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn pick_default_is_nerdfont() {
assert_eq!(
super::pick("nf", "u", "a"),
match tier() {
Tier::NerdFont => "nf",
Tier::Unicode => "u",
Tier::Ascii => "a",
}
);
}
#[test]
fn weather_unknown_is_never_empty() {
assert!(!weather_unknown().is_empty());
}
}