Fix check for Windows Terminal

This commit is contained in:
sxyazi 2024-09-02 11:42:17 +08:00
parent 921fc0bdae
commit 8995572dd1
No known key found for this signature in database
3 changed files with 30 additions and 27 deletions

View file

@ -39,7 +39,7 @@ https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265
## Image Preview ## Image Preview
| 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/kitty_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 |
@ -47,6 +47,7 @@ https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265
| [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 |
| [foot](https://codeberg.org/dnkl/foot) | [Sixel graphics format](https://www.vt100.net/docs/vt3xx-gp/chapter14.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 | | [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 | | [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 | | [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 | | [Tabby](https://github.com/Eugeny/tabby) | [Inline images protocol](https://iterm2.com/documentation-images.html) | ✅ Built-in |

View file

@ -83,17 +83,19 @@ impl Adapter {
impl Adapter { impl Adapter {
pub fn matches() -> Self { pub fn matches() -> Self {
let emulator = Emulator::detect(); let emulator = Emulator::detect();
let mut protocols = emulator.clone().adapters();
#[cfg(windows)] #[cfg(windows)]
if !matches!(emulator, Emulator::WindowsTerminal) { if matches!(emulator, Emulator::Microsoft) {
return Self::Sixel;
}
let mut protocols = emulator.adapters();
#[cfg(windows)]
protocols.retain(|p| *p == Self::Iterm2); protocols.retain(|p| *p == Self::Iterm2);
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::KittyOld);
} }
}
if let Some(p) = protocols.first() { if let Some(p) = protocols.first() {
return *p; return *p;
} }

View file

@ -18,6 +18,7 @@ pub enum Emulator {
WezTerm, WezTerm,
Foot, Foot,
Ghostty, Ghostty,
Microsoft,
BlackBox, BlackBox,
VSCode, VSCode,
Tabby, Tabby,
@ -26,7 +27,6 @@ pub enum Emulator {
Neovim, Neovim,
Apple, Apple,
Urxvt, Urxvt,
WindowsTerminal
} }
impl Emulator { impl Emulator {
@ -39,6 +39,7 @@ impl Emulator {
Self::WezTerm => vec![Adapter::Iterm2, Adapter::Sixel], Self::WezTerm => vec![Adapter::Iterm2, Adapter::Sixel],
Self::Foot => vec![Adapter::Sixel], Self::Foot => vec![Adapter::Sixel],
Self::Ghostty => vec![Adapter::Kitty], Self::Ghostty => vec![Adapter::Kitty],
Self::Microsoft => vec![Adapter::Sixel],
Self::BlackBox => vec![Adapter::Sixel], Self::BlackBox => vec![Adapter::Sixel],
Self::VSCode => vec![Adapter::Iterm2, Adapter::Sixel], Self::VSCode => vec![Adapter::Iterm2, Adapter::Sixel],
Self::Tabby => vec![Adapter::Iterm2, Adapter::Sixel], Self::Tabby => vec![Adapter::Iterm2, Adapter::Sixel],
@ -47,7 +48,6 @@ impl Emulator {
Self::Neovim => vec![], Self::Neovim => vec![],
Self::Apple => vec![], Self::Apple => vec![],
Self::Urxvt => vec![], Self::Urxvt => vec![],
Self::WindowsTerminal => vec![Adapter::Sixel]
} }
} }
} }
@ -64,9 +64,9 @@ impl Emulator {
("ITERM_SESSION_ID", Self::Iterm2), ("ITERM_SESSION_ID", Self::Iterm2),
("WEZTERM_EXECUTABLE", Self::WezTerm), ("WEZTERM_EXECUTABLE", Self::WezTerm),
("GHOSTTY_RESOURCES_DIR", Self::Ghostty), ("GHOSTTY_RESOURCES_DIR", Self::Ghostty),
("WT_Session", Self::Microsoft),
("VSCODE_INJECTION", Self::VSCode), ("VSCODE_INJECTION", Self::VSCode),
("TABBY_CONFIG_DIRECTORY", Self::Tabby), ("TABBY_CONFIG_DIRECTORY", Self::Tabby),
("WT_Session", Self::WindowsTerminal),
]; ];
match vars.into_iter().find(|v| env_exists(v.0)) { match vars.into_iter().find(|v| env_exists(v.0)) {
Some(var) => return var.1, Some(var) => return var.1,