use std::env;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TerminalType {
ITerm2,
Kitty,
Wezterm,
Generic,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GraphicsCapability {
ITerm2Inline,
KittyGraphics,
CellBased,
}
impl TerminalType {
pub fn detect() -> Self {
if let Ok(term_program) = env::var("TERM_PROGRAM") {
match term_program.as_str() {
"iTerm.app" => return Self::ITerm2,
"WezTerm" => return Self::Wezterm,
_ => {}
}
}
if env::var("KITTY_WINDOW_ID").is_ok() {
return Self::Kitty;
}
Self::Generic
}
pub fn graphics_capability(self) -> GraphicsCapability {
match self {
Self::ITerm2 => GraphicsCapability::ITerm2Inline,
Self::Kitty => GraphicsCapability::KittyGraphics,
Self::Wezterm => {
GraphicsCapability::KittyGraphics
}
Self::Generic => GraphicsCapability::CellBased,
}
}
pub fn name(self) -> &'static str {
match self {
Self::ITerm2 => "iTerm2",
Self::Kitty => "Kitty",
Self::Wezterm => "Wezterm",
Self::Generic => "Generic",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_terminal_detection() {
let term_type = TerminalType::detect();
let capability = term_type.graphics_capability();
println!("Detected: {:?}, Capability: {:?}", term_type, capability);
}
}