mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
refactor: use Kgp instead of Kitty since "Kitty" is a terminal emulator not a protocol name (#1732)
This commit is contained in:
parent
3150fb10f7
commit
3321f47d46
6 changed files with 27 additions and 27 deletions
|
|
@ -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 |
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ impl Emulator {
|
|||
pub fn adapters(self) -> Vec<Adapter> {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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<Rect> {
|
||||
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)?;
|
||||
|
|
@ -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<Rect> {
|
||||
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)?;
|
||||
|
|
@ -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};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue