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 |
|
| Platform | Protocol | Support |
|
||||||
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
||||||
| [kitty](https://github.com/kovidgoyal/kitty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in |
|
| [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 |
|
| [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 |
|
| [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 |
|
| [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 tracing::warn;
|
||||||
use yazi_shared::env_exists;
|
use yazi_shared::env_exists;
|
||||||
|
|
||||||
use super::{Iip, Kitty, KittyOld};
|
use super::{Iip, Kgp, KgpOld};
|
||||||
use crate::{Chafa, Emulator, SHOWN, Sixel, TMUX, Ueberzug, WSL};
|
use crate::{Chafa, Emulator, SHOWN, Sixel, TMUX, Ueberzug, WSL};
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
pub enum Adapter {
|
pub enum Adapter {
|
||||||
Kitty,
|
Kgp,
|
||||||
KittyOld,
|
KgpOld,
|
||||||
Iip,
|
Iip,
|
||||||
Sixel,
|
Sixel,
|
||||||
|
|
||||||
|
|
@ -24,8 +24,8 @@ pub enum Adapter {
|
||||||
impl Display for Adapter {
|
impl Display for Adapter {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Kitty => write!(f, "kitty"),
|
Self::Kgp => write!(f, "kgp"),
|
||||||
Self::KittyOld => write!(f, "kitty"),
|
Self::KgpOld => write!(f, "kgp-old"),
|
||||||
Self::Iip => write!(f, "iip"),
|
Self::Iip => write!(f, "iip"),
|
||||||
Self::Sixel => write!(f, "sixel"),
|
Self::Sixel => write!(f, "sixel"),
|
||||||
Self::X11 => write!(f, "x11"),
|
Self::X11 => write!(f, "x11"),
|
||||||
|
|
@ -42,8 +42,8 @@ impl Adapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Self::Kitty => Kitty::image_show(path, max).await,
|
Self::Kgp => Kgp::image_show(path, max).await,
|
||||||
Self::KittyOld => KittyOld::image_show(path, max).await,
|
Self::KgpOld => KgpOld::image_show(path, max).await,
|
||||||
Self::Iip => Iip::image_show(path, max).await,
|
Self::Iip => Iip::image_show(path, max).await,
|
||||||
Self::Sixel => Sixel::image_show(path, max).await,
|
Self::Sixel => Sixel::image_show(path, max).await,
|
||||||
Self::X11 | Self::Wayland => Ueberzug::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<()> {
|
pub fn image_erase(self, area: Rect) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::Kitty => Kitty::image_erase(area),
|
Self::Kgp => Kgp::image_erase(area),
|
||||||
Self::KittyOld => KittyOld::image_erase(area),
|
Self::KgpOld => KgpOld::image_erase(area),
|
||||||
Self::Iip => Iip::image_erase(area),
|
Self::Iip => Iip::image_erase(area),
|
||||||
Self::Sixel => Sixel::image_erase(area),
|
Self::Sixel => Sixel::image_erase(area),
|
||||||
Self::X11 | Self::Wayland => Ueberzug::image_erase(area),
|
Self::X11 | Self::Wayland => Ueberzug::image_erase(area),
|
||||||
|
|
@ -76,7 +76,7 @@ impl Adapter {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn needs_ueberzug(self) -> bool {
|
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") {
|
if env_exists("ZELLIJ_SESSION_NAME") {
|
||||||
protocols.retain(|p| *p == Self::Sixel);
|
protocols.retain(|p| *p == Self::Sixel);
|
||||||
} else if *TMUX {
|
} else if *TMUX {
|
||||||
protocols.retain(|p| *p != Self::KittyOld);
|
protocols.retain(|p| *p != Self::KgpOld);
|
||||||
}
|
}
|
||||||
if let Some(p) = protocols.first() {
|
if let Some(p) = protocols.first() {
|
||||||
return *p;
|
return *p;
|
||||||
|
|
@ -114,7 +114,7 @@ impl Adapter {
|
||||||
return Self::X11;
|
return Self::X11;
|
||||||
}
|
}
|
||||||
if *WSL {
|
if *WSL {
|
||||||
return Self::KittyOld;
|
return Self::KgpOld;
|
||||||
}
|
}
|
||||||
|
|
||||||
warn!("[Adapter] Falling back to chafa");
|
warn!("[Adapter] Falling back to chafa");
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@ impl Emulator {
|
||||||
pub fn adapters(self) -> Vec<Adapter> {
|
pub fn adapters(self) -> Vec<Adapter> {
|
||||||
match self {
|
match self {
|
||||||
Self::Unknown(adapters) => adapters,
|
Self::Unknown(adapters) => adapters,
|
||||||
Self::Kitty => vec![Adapter::Kitty],
|
Self::Kitty => vec![Adapter::Kgp],
|
||||||
Self::Konsole => vec![Adapter::KittyOld],
|
Self::Konsole => vec![Adapter::KgpOld],
|
||||||
Self::Iterm2 => vec![Adapter::Iip, Adapter::Sixel],
|
Self::Iterm2 => vec![Adapter::Iip, Adapter::Sixel],
|
||||||
Self::WezTerm => vec![Adapter::Iip, Adapter::Sixel],
|
Self::WezTerm => vec![Adapter::Iip, Adapter::Sixel],
|
||||||
Self::Foot => vec![Adapter::Sixel],
|
Self::Foot => vec![Adapter::Sixel],
|
||||||
Self::Ghostty => vec![Adapter::Kitty],
|
Self::Ghostty => vec![Adapter::Kgp],
|
||||||
Self::Microsoft => vec![Adapter::Sixel],
|
Self::Microsoft => vec![Adapter::Sixel],
|
||||||
Self::Rio => vec![Adapter::Iip, Adapter::Sixel],
|
Self::Rio => vec![Adapter::Iip, Adapter::Sixel],
|
||||||
Self::BlackBox => vec![Adapter::Sixel],
|
Self::BlackBox => vec![Adapter::Sixel],
|
||||||
|
|
@ -151,7 +151,7 @@ impl Emulator {
|
||||||
|
|
||||||
let mut adapters = Vec::with_capacity(2);
|
let mut adapters = Vec::with_capacity(2);
|
||||||
if resp.contains("\x1b_Gi=31;OK") {
|
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)) {
|
if ["?4;", "?4c", ";4;", ";4c"].iter().any(|s| resp.contains(s)) {
|
||||||
adapters.push(Adapter::Sixel);
|
adapters.push(Adapter::Sixel);
|
||||||
|
|
|
||||||
|
|
@ -310,9 +310,9 @@ static DIACRITICS: [char; 297] = [
|
||||||
'\u{1D244}',
|
'\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> {
|
pub(super) async fn image_show(path: &Path, max: Rect) -> Result<Rect> {
|
||||||
let img = Image::downscale(path, max).await?;
|
let img = Image::downscale(path, max).await?;
|
||||||
let area = Image::pixel_area((img.width(), img.height()), max);
|
let area = Image::pixel_area((img.width(), img.height()), max);
|
||||||
|
|
@ -320,7 +320,7 @@ impl Kitty {
|
||||||
let b1 = Self::encode(img).await?;
|
let b1 = Self::encode(img).await?;
|
||||||
let b2 = Self::place(&area)?;
|
let b2 = Self::place(&area)?;
|
||||||
|
|
||||||
Adapter::Kitty.image_hide()?;
|
Adapter::Kgp.image_hide()?;
|
||||||
Adapter::shown_store(area);
|
Adapter::shown_store(area);
|
||||||
Emulator::move_lock((area.x, area.y), |stderr| {
|
Emulator::move_lock((area.x, area.y), |stderr| {
|
||||||
stderr.write_all(&b1)?;
|
stderr.write_all(&b1)?;
|
||||||
|
|
@ -9,15 +9,15 @@ use ratatui::layout::Rect;
|
||||||
use super::image::Image;
|
use super::image::Image;
|
||||||
use crate::{CLOSE, ESCAPE, Emulator, START, adapter::Adapter};
|
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> {
|
pub(super) async fn image_show(path: &Path, max: Rect) -> Result<Rect> {
|
||||||
let img = Image::downscale(path, max).await?;
|
let img = Image::downscale(path, max).await?;
|
||||||
let area = Image::pixel_area((img.width(), img.height()), max);
|
let area = Image::pixel_area((img.width(), img.height()), max);
|
||||||
let b = Self::encode(img).await?;
|
let b = Self::encode(img).await?;
|
||||||
|
|
||||||
Adapter::KittyOld.image_hide()?;
|
Adapter::KgpOld.image_hide()?;
|
||||||
Adapter::shown_store(area);
|
Adapter::shown_store(area);
|
||||||
Emulator::move_lock((area.x, area.y), |stderr| {
|
Emulator::move_lock((area.x, area.y), |stderr| {
|
||||||
stderr.write_all(&b)?;
|
stderr.write_all(&b)?;
|
||||||
|
|
@ -6,8 +6,8 @@ mod dimension;
|
||||||
mod emulator;
|
mod emulator;
|
||||||
mod iip;
|
mod iip;
|
||||||
mod image;
|
mod image;
|
||||||
mod kitty;
|
mod kgp;
|
||||||
mod kitty_old;
|
mod kgp_old;
|
||||||
mod sixel;
|
mod sixel;
|
||||||
mod ueberzug;
|
mod ueberzug;
|
||||||
|
|
||||||
|
|
@ -16,8 +16,8 @@ use chafa::*;
|
||||||
pub use dimension::*;
|
pub use dimension::*;
|
||||||
pub use emulator::*;
|
pub use emulator::*;
|
||||||
use iip::*;
|
use iip::*;
|
||||||
use kitty::*;
|
use kgp::*;
|
||||||
use kitty_old::*;
|
use kgp_old::*;
|
||||||
use sixel::*;
|
use sixel::*;
|
||||||
use ueberzug::*;
|
use ueberzug::*;
|
||||||
use yazi_shared::{RoCell, env_exists, in_wsl};
|
use yazi_shared::{RoCell, env_exists, in_wsl};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue