From e940d81d2a0a100fee41c1a59af7e2a14b49077f Mon Sep 17 00:00:00 2001 From: e82eric Date: Sun, 1 Sep 2024 23:47:30 -0400 Subject: [PATCH] feat: support image preview in Windows Terminal (#1588) Co-authored-by: sxyazi --- README.md | 31 ++++++++++++++++--------------- yazi-adapter/src/adapter.rs | 7 ++++++- yazi-adapter/src/emulator.rs | 3 +++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7abd004b..e0742a7f 100644 --- a/README.md +++ b/README.md @@ -38,21 +38,22 @@ https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265 ## Image Preview -| 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 | -| [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 | -| [foot](https://codeberg.org/dnkl/foot) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | -| [Ghostty](https://mitchellh.com/ghostty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in | -| [Black Box](https://gitlab.gnome.org/raggesilver/blackbox) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | -| [VSCode](https://github.com/microsoft/vscode) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | -| [Tabby](https://github.com/Eugeny/tabby) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | -| [Hyper](https://github.com/vercel/hyper) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | -| X11 / Wayland | Window system protocol | ☑️ [Überzug++](https://github.com/jstkdng/ueberzugpp) required | -| Fallback | [ASCII art (Unicode block)](https://en.wikipedia.org/wiki/ASCII_art) | ☑️ [Chafa](https://hpjansson.org/chafa/) required | +| 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 | +| [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 | +| [foot](https://codeberg.org/dnkl/foot) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | +| [Ghostty](https://mitchellh.com/ghostty) | [Kitty unicode placeholders](https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders) | ✅ Built-in | +| [Windows Terminal](https://github.com/microsoft/terminal) (>= v1.22.2362.0) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | +| [Black Box](https://gitlab.gnome.org/raggesilver/blackbox) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.html) | ✅ Built-in | +| [VSCode](https://github.com/microsoft/vscode) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | +| [Tabby](https://github.com/Eugeny/tabby) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | +| [Hyper](https://github.com/vercel/hyper) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in | +| X11 / Wayland | Window system protocol | ☑️ [Überzug++](https://github.com/jstkdng/ueberzugpp) required | +| Fallback | [ASCII art (Unicode block)](https://en.wikipedia.org/wiki/ASCII_art) | ☑️ [Chafa](https://hpjansson.org/chafa/) required | See https://yazi-rs.github.io/docs/image-preview for details. diff --git a/yazi-adapter/src/adapter.rs b/yazi-adapter/src/adapter.rs index 4f5234cb..b9fdad1d 100644 --- a/yazi-adapter/src/adapter.rs +++ b/yazi-adapter/src/adapter.rs @@ -82,8 +82,13 @@ impl Adapter { impl Adapter { pub fn matches() -> Self { - let mut protocols = Emulator::detect().adapters(); + let emulator = Emulator::detect(); + #[cfg(windows)] + if matches!(emulator, Emulator::Microsoft) { + return Self::Sixel; + } + let mut protocols = emulator.adapters(); #[cfg(windows)] protocols.retain(|p| *p == Self::Iterm2); if env_exists("ZELLIJ_SESSION_NAME") { diff --git a/yazi-adapter/src/emulator.rs b/yazi-adapter/src/emulator.rs index a201121e..3a1e2ebe 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -18,6 +18,7 @@ pub enum Emulator { WezTerm, Foot, Ghostty, + Microsoft, BlackBox, VSCode, Tabby, @@ -38,6 +39,7 @@ impl Emulator { Self::WezTerm => vec![Adapter::Iterm2, Adapter::Sixel], Self::Foot => vec![Adapter::Sixel], Self::Ghostty => vec![Adapter::Kitty], + Self::Microsoft => vec![Adapter::Sixel], Self::BlackBox => vec![Adapter::Sixel], Self::VSCode => vec![Adapter::Iterm2, Adapter::Sixel], Self::Tabby => vec![Adapter::Iterm2, Adapter::Sixel], @@ -62,6 +64,7 @@ impl Emulator { ("ITERM_SESSION_ID", Self::Iterm2), ("WEZTERM_EXECUTABLE", Self::WezTerm), ("GHOSTTY_RESOURCES_DIR", Self::Ghostty), + ("WT_Session", Self::Microsoft), ("VSCODE_INJECTION", Self::VSCode), ("TABBY_CONFIG_DIRECTORY", Self::Tabby), ];