From 3321f47d46c8d1888decb4d734c35b883a4e6c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Fri, 4 Oct 2024 23:43:36 +0800 Subject: [PATCH] refactor: use `Kgp` instead of `Kitty` since "Kitty" is a terminal emulator not a protocol name (#1732) --- README.md | 2 +- yazi-adapter/src/adapter.rs | 24 +++++++++---------- yazi-adapter/src/emulator.rs | 8 +++---- yazi-adapter/src/{kitty.rs => kgp.rs} | 6 ++--- yazi-adapter/src/{kitty_old.rs => kgp_old.rs} | 6 ++--- yazi-adapter/src/lib.rs | 8 +++---- 6 files changed, 27 insertions(+), 27 deletions(-) rename yazi-adapter/src/{kitty.rs => kgp.rs} (98%) rename yazi-adapter/src/{kitty_old.rs => kgp_old.rs} (96%) diff --git a/README.md b/README.md index 96e7fb9b..9e78a17e 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265 | Platform | Protocol | Support | | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | | [kitty](https://github.com/kovidgoyal/kitty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in | -| [Konsole](https://invent.kde.org/utilities/konsole) | [Kitty old protocol](https://github.com/sxyazi/yazi/blob/main/yazi-adapter/src/kitty_old.rs) | ✅ Built-in | +| [Konsole](https://invent.kde.org/utilities/konsole) | [Kitty old protocol](https://github.com/sxyazi/yazi/blob/main/yazi-adapter/src/kgp_old.rs) | ✅ Built-in | | [iTerm2](https://iterm2.com) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | | [WezTerm](https://github.com/wez/wezterm) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | | [Mintty](https://github.com/mintty/mintty) (Git Bash) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | diff --git a/yazi-adapter/src/adapter.rs b/yazi-adapter/src/adapter.rs index 9ddd6860..6d84954d 100644 --- a/yazi-adapter/src/adapter.rs +++ b/yazi-adapter/src/adapter.rs @@ -5,13 +5,13 @@ use ratatui::layout::Rect; use tracing::warn; use yazi_shared::env_exists; -use super::{Iip, Kitty, KittyOld}; +use super::{Iip, Kgp, KgpOld}; use crate::{Chafa, Emulator, SHOWN, Sixel, TMUX, Ueberzug, WSL}; #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum Adapter { - Kitty, - KittyOld, + Kgp, + KgpOld, Iip, Sixel, @@ -24,8 +24,8 @@ pub enum Adapter { impl Display for Adapter { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Kitty => write!(f, "kitty"), - Self::KittyOld => write!(f, "kitty"), + Self::Kgp => write!(f, "kgp"), + Self::KgpOld => write!(f, "kgp-old"), Self::Iip => write!(f, "iip"), Self::Sixel => write!(f, "sixel"), Self::X11 => write!(f, "x11"), @@ -42,8 +42,8 @@ impl Adapter { } match self { - Self::Kitty => Kitty::image_show(path, max).await, - Self::KittyOld => KittyOld::image_show(path, max).await, + Self::Kgp => Kgp::image_show(path, max).await, + Self::KgpOld => KgpOld::image_show(path, max).await, Self::Iip => Iip::image_show(path, max).await, Self::Sixel => Sixel::image_show(path, max).await, Self::X11 | Self::Wayland => Ueberzug::image_show(path, max).await, @@ -57,8 +57,8 @@ impl Adapter { pub fn image_erase(self, area: Rect) -> Result<()> { match self { - Self::Kitty => Kitty::image_erase(area), - Self::KittyOld => KittyOld::image_erase(area), + Self::Kgp => Kgp::image_erase(area), + Self::KgpOld => KgpOld::image_erase(area), Self::Iip => Iip::image_erase(area), Self::Sixel => Sixel::image_erase(area), Self::X11 | Self::Wayland => Ueberzug::image_erase(area), @@ -76,7 +76,7 @@ impl Adapter { #[inline] pub(super) fn needs_ueberzug(self) -> bool { - !matches!(self, Self::Kitty | Self::KittyOld | Self::Iip | Self::Sixel) + !matches!(self, Self::Kgp | Self::KgpOld | Self::Iip | Self::Sixel) } } @@ -94,7 +94,7 @@ impl Adapter { if env_exists("ZELLIJ_SESSION_NAME") { protocols.retain(|p| *p == Self::Sixel); } else if *TMUX { - protocols.retain(|p| *p != Self::KittyOld); + protocols.retain(|p| *p != Self::KgpOld); } if let Some(p) = protocols.first() { return *p; @@ -114,7 +114,7 @@ impl Adapter { return Self::X11; } if *WSL { - return Self::KittyOld; + return Self::KgpOld; } warn!("[Adapter] Falling back to chafa"); diff --git a/yazi-adapter/src/emulator.rs b/yazi-adapter/src/emulator.rs index 498e090e..6d172a00 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -34,12 +34,12 @@ impl Emulator { pub fn adapters(self) -> Vec { match self { Self::Unknown(adapters) => adapters, - Self::Kitty => vec![Adapter::Kitty], - Self::Konsole => vec![Adapter::KittyOld], + Self::Kitty => vec![Adapter::Kgp], + Self::Konsole => vec![Adapter::KgpOld], Self::Iterm2 => vec![Adapter::Iip, Adapter::Sixel], Self::WezTerm => vec![Adapter::Iip, Adapter::Sixel], Self::Foot => vec![Adapter::Sixel], - Self::Ghostty => vec![Adapter::Kitty], + Self::Ghostty => vec![Adapter::Kgp], Self::Microsoft => vec![Adapter::Sixel], Self::Rio => vec![Adapter::Iip, Adapter::Sixel], Self::BlackBox => vec![Adapter::Sixel], @@ -151,7 +151,7 @@ impl Emulator { let mut adapters = Vec::with_capacity(2); if resp.contains("\x1b_Gi=31;OK") { - adapters.push(Adapter::KittyOld); + adapters.push(Adapter::KgpOld); } if ["?4;", "?4c", ";4;", ";4c"].iter().any(|s| resp.contains(s)) { adapters.push(Adapter::Sixel); diff --git a/yazi-adapter/src/kitty.rs b/yazi-adapter/src/kgp.rs similarity index 98% rename from yazi-adapter/src/kitty.rs rename to yazi-adapter/src/kgp.rs index 3e3ce8fd..e6aa7e58 100644 --- a/yazi-adapter/src/kitty.rs +++ b/yazi-adapter/src/kgp.rs @@ -310,9 +310,9 @@ static DIACRITICS: [char; 297] = [ '\u{1D244}', ]; -pub(super) struct Kitty; +pub(super) struct Kgp; -impl Kitty { +impl Kgp { pub(super) async fn image_show(path: &Path, max: Rect) -> Result { let img = Image::downscale(path, max).await?; let area = Image::pixel_area((img.width(), img.height()), max); @@ -320,7 +320,7 @@ impl Kitty { let b1 = Self::encode(img).await?; let b2 = Self::place(&area)?; - Adapter::Kitty.image_hide()?; + Adapter::Kgp.image_hide()?; Adapter::shown_store(area); Emulator::move_lock((area.x, area.y), |stderr| { stderr.write_all(&b1)?; diff --git a/yazi-adapter/src/kitty_old.rs b/yazi-adapter/src/kgp_old.rs similarity index 96% rename from yazi-adapter/src/kitty_old.rs rename to yazi-adapter/src/kgp_old.rs index 1b82698a..3d483005 100644 --- a/yazi-adapter/src/kitty_old.rs +++ b/yazi-adapter/src/kgp_old.rs @@ -9,15 +9,15 @@ use ratatui::layout::Rect; use super::image::Image; use crate::{CLOSE, ESCAPE, Emulator, START, adapter::Adapter}; -pub(super) struct KittyOld; +pub(super) struct KgpOld; -impl KittyOld { +impl KgpOld { pub(super) async fn image_show(path: &Path, max: Rect) -> Result { let img = Image::downscale(path, max).await?; let area = Image::pixel_area((img.width(), img.height()), max); let b = Self::encode(img).await?; - Adapter::KittyOld.image_hide()?; + Adapter::KgpOld.image_hide()?; Adapter::shown_store(area); Emulator::move_lock((area.x, area.y), |stderr| { stderr.write_all(&b)?; diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index 20664691..763f796c 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -6,8 +6,8 @@ mod dimension; mod emulator; mod iip; mod image; -mod kitty; -mod kitty_old; +mod kgp; +mod kgp_old; mod sixel; mod ueberzug; @@ -16,8 +16,8 @@ use chafa::*; pub use dimension::*; pub use emulator::*; use iip::*; -use kitty::*; -use kitty_old::*; +use kgp::*; +use kgp_old::*; use sixel::*; use ueberzug::*; use yazi_shared::{RoCell, env_exists, in_wsl};