From 60ed6c9b3fea9ac2ca38bda8ccc4df375eed6d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Mon, 9 Dec 2024 02:24:40 +0800 Subject: [PATCH] fix: disable passthrough when the user launches Yazi in Neovim inside tmux (#2014) --- scripts/publish.sh | 8 ++++++-- yazi-adapter/src/brand.rs | 4 ++-- yazi-adapter/src/lib.rs | 6 ++++++ yazi-adapter/src/mux.rs | 4 ++-- yazi-boot/src/actions/debug.rs | 4 ++++ yazi-codegen/Cargo.toml | 2 +- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/publish.sh b/scripts/publish.sh index 637f436af..49368e6f3 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,11 +1,15 @@ +cargo publish -p yazi-macro +sleep 30 +cargo publish -p yazi-codegen +sleep 30 cargo publish -p yazi-shared sleep 30 +cargo publish -p yazi-fs +sleep 30 cargo publish -p yazi-config sleep 30 cargo publish -p yazi-proxy sleep 30 -cargo publish -p yazi-fs -sleep 30 cargo publish -p yazi-adapter sleep 30 cargo publish -p yazi-boot diff --git a/yazi-adapter/src/brand.rs b/yazi-adapter/src/brand.rs index 5aa7b69e3..0a87e058e 100644 --- a/yazi-adapter/src/brand.rs +++ b/yazi-adapter/src/brand.rs @@ -1,7 +1,7 @@ use tracing::warn; use yazi_shared::env_exists; -use crate::Mux; +use crate::{Mux, NVIM}; #[derive(Clone, Copy, Debug)] pub enum Brand { @@ -27,7 +27,7 @@ impl Brand { pub fn from_env() -> Option { use Brand as B; - if env_exists("NVIM_LOG_FILE") && env_exists("NVIM") { + if *NVIM { return Some(Self::Neovim); } diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index 1b177e54e..536ab5bcb 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -21,6 +21,9 @@ static CLOSE: RoCell<&'static str> = RoCell::new(); // WSL support pub static WSL: RoCell = RoCell::new(); +// Neovim support +pub static NVIM: RoCell = RoCell::new(); + pub fn init() -> anyhow::Result<()> { // Tmux support TMUX.init(env_exists("TMUX_PANE") && env_exists("TMUX")); @@ -40,6 +43,9 @@ pub fn init() -> anyhow::Result<()> { // WSL support WSL.init(in_wsl()); + // Neovim support + NVIM.init(env_exists("NVIM_LOG_FILE") && env_exists("NVIM")); + EMULATOR.init(Emulator::detect()); yazi_config::init_flavor(EMULATOR.light)?; diff --git a/yazi-adapter/src/mux.rs b/yazi-adapter/src/mux.rs index abd095c5b..695eb5dc6 100644 --- a/yazi-adapter/src/mux.rs +++ b/yazi-adapter/src/mux.rs @@ -1,10 +1,10 @@ -use crate::{CLOSE, ESCAPE, START, TMUX}; +use crate::{CLOSE, ESCAPE, NVIM, START, TMUX}; pub struct Mux; impl Mux { pub fn csi(s: &str) -> std::borrow::Cow { - if *TMUX { + if *TMUX && !*NVIM { std::borrow::Cow::Owned(format!( "{}{}{}", *START, diff --git a/yazi-boot/src/actions/debug.rs b/yazi-boot/src/actions/debug.rs index ced554edb..e597840b7 100644 --- a/yazi-boot/src/actions/debug.rs +++ b/yazi-boot/src/actions/debug.rs @@ -41,6 +41,10 @@ impl Actions { writeln!(s, "\nWSL")?; writeln!(s, " WSL: {:?}", *yazi_adapter::WSL)?; + writeln!(s, "\nNVIM")?; + writeln!(s, " NVIM : {:?}", *yazi_adapter::NVIM)?; + writeln!(s, " Neovim version: {:?}", Self::process_output("nvim", "--version"))?; + writeln!(s, "\nVariables")?; writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?; writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?; diff --git a/yazi-codegen/Cargo.toml b/yazi-codegen/Cargo.toml index d4397a0b9..4a8905bc4 100644 --- a/yazi-codegen/Cargo.toml +++ b/yazi-codegen/Cargo.toml @@ -13,5 +13,5 @@ proc-macro = true [dependencies] # External dependencies -syn = "2.0.90" +syn = { version = "2.0.90", features = [ "full" ] } quote = "1.0.37"