mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
adapter: allow kitty passthrough under zellij
This commit is contained in:
parent
b37be0529a
commit
70b072080e
2 changed files with 81 additions and 2 deletions
|
|
@ -9,6 +9,9 @@ use yazi_shared::env_exists;
|
|||
|
||||
use crate::{Adapters, SHOWN, drivers};
|
||||
|
||||
const ZELLIJ_SESSION_NAME_ENV: &str = "ZELLIJ_SESSION_NAME";
|
||||
pub const ZELLIJ_KITTY_PASSTHROUGH_ENV: &str = "YAZI_ZELLIJ_KITTY_PASSTHROUGH";
|
||||
|
||||
#[derive(Clone, Copy, Debug, Display, Eq, IntoStaticStr, PartialEq)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum Adapter {
|
||||
|
|
@ -75,8 +78,8 @@ impl Adapter {
|
|||
impl Adapter {
|
||||
pub fn matches(emulator: &Emulator) -> Self {
|
||||
let mut adapters: Adapters = emulator.into();
|
||||
if env_exists("ZELLIJ_SESSION_NAME") {
|
||||
adapters.retain(|p| *p == Self::Sixel);
|
||||
if env_exists(ZELLIJ_SESSION_NAME_ENV) {
|
||||
adapters.retain(|p| p.supported_in_zellij());
|
||||
} else if TMUX.get() {
|
||||
adapters.retain(|p| *p != Self::KgpOld);
|
||||
}
|
||||
|
|
@ -102,4 +105,74 @@ impl Adapter {
|
|||
warn!("[Adapter] Falling back to chafa");
|
||||
Self::Chafa
|
||||
}
|
||||
|
||||
fn supported_in_zellij(self) -> bool {
|
||||
self == Self::Sixel
|
||||
|| (env_exists(ZELLIJ_KITTY_PASSTHROUGH_ENV)
|
||||
&& matches!(self, Self::Kgp | Self::KgpOld))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{env, ffi::OsString, sync::Mutex};
|
||||
|
||||
use super::*;
|
||||
|
||||
static ENV_LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
struct EnvVarGuard {
|
||||
name: &'static str,
|
||||
old: Option<OsString>,
|
||||
}
|
||||
|
||||
impl EnvVarGuard {
|
||||
fn set(name: &'static str, value: &str) -> Self {
|
||||
let old = env::var_os(name);
|
||||
unsafe { env::set_var(name, value) };
|
||||
Self { name, old }
|
||||
}
|
||||
|
||||
fn remove(name: &'static str) -> Self {
|
||||
let old = env::var_os(name);
|
||||
unsafe { env::remove_var(name) };
|
||||
Self { name, old }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for EnvVarGuard {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
if let Some(value) = self.old.take() {
|
||||
env::set_var(self.name, value);
|
||||
} else {
|
||||
env::remove_var(self.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zellij_uses_sixel_by_default() {
|
||||
let _lock = ENV_LOCK.lock().unwrap();
|
||||
let _session = EnvVarGuard::set(ZELLIJ_SESSION_NAME_ENV, "test-session");
|
||||
let _passthrough = EnvVarGuard::remove(ZELLIJ_KITTY_PASSTHROUGH_ENV);
|
||||
|
||||
assert!(Adapter::Sixel.supported_in_zellij());
|
||||
assert!(!Adapter::Kgp.supported_in_zellij());
|
||||
assert!(!Adapter::KgpOld.supported_in_zellij());
|
||||
assert!(!Adapter::Iip.supported_in_zellij());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zellij_kitty_passthrough_adds_kitty_adapters_only() {
|
||||
let _lock = ENV_LOCK.lock().unwrap();
|
||||
let _session = EnvVarGuard::set(ZELLIJ_SESSION_NAME_ENV, "test-session");
|
||||
let _passthrough = EnvVarGuard::set(ZELLIJ_KITTY_PASSTHROUGH_ENV, "1");
|
||||
|
||||
assert!(Adapter::Sixel.supported_in_zellij());
|
||||
assert!(Adapter::Kgp.supported_in_zellij());
|
||||
assert!(Adapter::KgpOld.supported_in_zellij());
|
||||
assert!(!Adapter::Iip.supported_in_zellij());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
yazi-cli/src/env/env.rs
vendored
6
yazi-cli/src/env/env.rs
vendored
|
|
@ -86,6 +86,12 @@ impl Env {
|
|||
writeln!(s, " tmux version : {}", Self::dep_version("tmux", "-V"))?;
|
||||
writeln!(s, " tmux build flags : enable-sixel={}", Mux::tmux_sixel_flag())?;
|
||||
writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?;
|
||||
writeln!(
|
||||
s,
|
||||
" {}: {:?}",
|
||||
yazi_adapter::ZELLIJ_KITTY_PASSTHROUGH_ENV,
|
||||
env::var_os(yazi_adapter::ZELLIJ_KITTY_PASSTHROUGH_ENV)
|
||||
)?;
|
||||
writeln!(s, " Zellij version : {}", Self::dep_version("zellij", "--version"))?;
|
||||
|
||||
writeln!(s, "\nDependencies")?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue