#[derive(Debug, Clone, Copy)]
pub struct Caps {
pub has_truecolor: bool,
pub colors: i32,
pub unicode: bool,
}
pub fn detect() -> Caps {
let env = |k: &str| std::env::var(k).unwrap_or_default();
let term = env("TERM");
let colorterm = env("COLORTERM");
let has_truecolor = colorterm == "truecolor" || colorterm == "24bit";
let codeset_utf8 = {
let loc = [env("LC_ALL"), env("LC_CTYPE"), env("LANG")]
.into_iter()
.find(|s| !s.is_empty())
.unwrap_or_default()
.to_ascii_lowercase();
loc.contains("utf-8") || loc.contains("utf8")
};
let unicode = term != "dumb" && term != "linux" && codeset_utf8;
let colors = terminfo_colors().unwrap_or_else(|| {
if has_truecolor || term.contains("256") || colorterm.contains("256") {
256
} else if term.is_empty() || term == "dumb" {
0
} else {
8
}
});
Caps { has_truecolor, colors, unicode }
}
fn terminfo_colors() -> Option<i32> {
let n = crate::ported::init::tccolours.load(std::sync::atomic::Ordering::Relaxed);
if n > 0 {
Some(n)
} else {
None
}
}
pub fn derive_mode(caps: &Caps, unicode_selected: bool) -> ModeChoice {
if caps.unicode && unicode_selected {
ModeChoice {
mode: "nerdfont-complete".to_string(), icon_padding: "moderate".to_string(), cap_diamond: true, cap_python: true,
cap_lock: true,
cap_arrow: true,
cap_debian: true,
}
} else {
ModeChoice {
mode: "ascii".to_string(), icon_padding: "none".to_string(),
cap_diamond: false,
cap_python: false,
cap_lock: false,
cap_arrow: false,
cap_debian: false,
}
}
}
#[derive(Debug, Clone)]
pub struct ModeChoice {
pub mode: String,
pub icon_padding: String,
pub cap_diamond: bool,
pub cap_python: bool,
pub cap_lock: bool,
pub cap_arrow: bool,
pub cap_debian: bool,
}