diff --git a/src/terminal/kitty.rs b/src/terminal/kitty.rs index 0c717ec8..26df39d1 100644 --- a/src/terminal/kitty.rs +++ b/src/terminal/kitty.rs @@ -32,11 +32,24 @@ use std::process::{Command, Stdio}; use std::str; use url::Url; -/// Whether we run in Kitty or not. -pub fn is_kitty() -> bool { +/// Whether we run in Kitty or not. It also returns the version. +pub fn is_kitty() -> Option<(u8, u8, u8)> { std::env::var("TERM") - .map(|value| value == "xterm-kitty") - .unwrap_or(false) + .ok() + .filter(|value| value == "xterm-kitty")?; + + let output = Command::new("kitty").arg("--version").output().ok()?; + if output.status.success() { + // Output is in the form of `kitty .. created...`. + let output = std::str::from_utf8(&output.stdout).ok()?; + let mut version = output.split_ascii_whitespace().nth(1)?.split('.'); + let major = version.next()?.parse().ok()?; + let minor = version.next()?.parse().ok()?; + let patch = version.next()?.parse().ok()?; + Some((major, minor, patch)) + } else { + None + } } /// Retrieve the terminal size in pixels by calling the command-line tool `kitty`. diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index a46695e0..2b22a660 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -128,11 +128,15 @@ impl TerminalCapabilities { } /// Terminal capabilities of Kitty. - pub fn kitty() -> TerminalCapabilities { + pub fn kitty(version: (u8, u8, u8)) -> TerminalCapabilities { TerminalCapabilities { name: "Kitty".to_string(), style: Some(StyleCapability::Ansi(AnsiStyle)), - links: None, + links: if version >= (0, 19, 0) { + Some(LinkCapability::OSC8(self::osc::OSC8Links)) + } else { + None + }, image: Some(ImageCapability::Kitty(self::kitty::KittyImages)), marks: None, } @@ -155,8 +159,8 @@ impl TerminalCapabilities { Self::iterm2() } else if self::terminology::is_terminology() { Self::terminology() - } else if self::kitty::is_kitty() { - Self::kitty() + } else if let Some(version) = self::kitty::is_kitty() { + Self::kitty(version) } else if get_vte_version().filter(|&v| v >= (50, 0)).is_some() { Self::vte50() } else {