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/adapter.rs b/yazi-adapter/src/adapter.rs index a3537ea7d..a606925cf 100644 --- a/yazi-adapter/src/adapter.rs +++ b/yazi-adapter/src/adapter.rs @@ -92,7 +92,7 @@ impl Adapter { protocols.retain(|p| *p == Self::Iip); if env_exists("ZELLIJ_SESSION_NAME") { protocols.retain(|p| *p == Self::Sixel); - } else if *TMUX { + } else if *TMUX != 0 { protocols.retain(|p| *p != Self::KgpOld); } if let Some(p) = protocols.first() { 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/emulator.rs b/yazi-adapter/src/emulator.rs index faea3aa97..5a80c0cf8 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -82,7 +82,7 @@ impl Emulator { // I really don't want to add this, // But tmux and ConPTY sometimes cause the cursor position to get out of sync. - if *TMUX || cfg!(windows) { + if *TMUX != 0 || cfg!(windows) { execute!(buf, SavePosition, MoveTo(x, y), Show)?; execute!(buf, MoveTo(x, y), Show)?; execute!(buf, MoveTo(x, y), Show)?; @@ -92,7 +92,7 @@ impl Emulator { } let result = cb(&mut buf); - if *TMUX || cfg!(windows) { + if *TMUX != 0 || cfg!(windows) { queue!(buf, Hide, RestorePosition)?; } else { queue!(buf, RestorePosition)?; @@ -136,9 +136,9 @@ impl Emulator { execute!( LineWriter::new(stderr()), - Print("\x1b[16t"), // Request cell size - Print("\x1b]11;?\x07"), // Request background color - Print(Mux::csi("\x1b[0c")), // Request device attributes + Print("\x1b[16t"), // Request cell size + Print("\x1b]11;?\x07"), // Request background color + Print("\x1b[0c"), // Request device attributes )?; let resp = futures::executor::block_on(Self::read_until_da1()); diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index 1b177e54e..60c243d9b 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -13,7 +13,7 @@ pub static ADAPTOR: RoCell = RoCell::new(); static SHOWN: SyncCell> = SyncCell::new(None); // Tmux support -pub static TMUX: RoCell = RoCell::new(); +pub static TMUX: RoCell = RoCell::new(); static ESCAPE: RoCell<&'static str> = RoCell::new(); static START: RoCell<&'static str> = RoCell::new(); static CLOSE: RoCell<&'static str> = RoCell::new(); @@ -21,25 +21,22 @@ 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")); - ESCAPE.init(if *TMUX { "\x1b\x1b" } else { "\x1b" }); - START.init(if *TMUX { "\x1bPtmux;\x1b\x1b" } else { "\x1b" }); - CLOSE.init(if *TMUX { "\x1b\\" } else { "" }); - - if *TMUX { - _ = std::process::Command::new("tmux") - .args(["set", "-p", "allow-passthrough", "all"]) - .stdin(std::process::Stdio::null()) - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) - .status(); - } + TMUX.init(Mux::tmux_passthrough()); + ESCAPE.init(if *TMUX == 2 { "\x1b\x1b" } else { "\x1b" }); + START.init(if *TMUX == 2 { "\x1bPtmux;\x1b\x1b" } else { "\x1b" }); + CLOSE.init(if *TMUX == 2 { "\x1b\\" } else { "" }); // 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..0565f72f1 100644 --- a/yazi-adapter/src/mux.rs +++ b/yazi-adapter/src/mux.rs @@ -1,10 +1,13 @@ -use crate::{CLOSE, ESCAPE, START, TMUX}; +use tracing::error; +use yazi_shared::env_exists; + +use crate::{CLOSE, ESCAPE, NVIM, START, TMUX}; pub struct Mux; impl Mux { pub fn csi(s: &str) -> std::borrow::Cow { - if *TMUX { + if *TMUX == 2 && !*NVIM { std::borrow::Cow::Owned(format!( "{}{}{}", *START, @@ -16,6 +19,34 @@ impl Mux { } } + pub fn tmux_passthrough() -> u8 { + if !env_exists("TMUX_PANE") || !env_exists("TMUX") { + return 0; + } + + let child = std::process::Command::new("tmux") + .args(["set", "-p", "allow-passthrough", "all"]) + .stdin(std::process::Stdio::null()) + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::piped()) + .spawn(); + + match child.and_then(|c| c.wait_with_output()) { + Ok(output) if output.status.success() => return 2, + Ok(output) => { + error!( + "Running `tmux set -p allow-passthrough all` failed: {:?}, {}", + output.status, + String::from_utf8_lossy(&output.stderr) + ); + } + Err(err) => { + error!("Failed to spawn `tmux set -p allow-passthrough all`: {err}"); + } + } + 1 + } + pub fn tmux_sixel_flag() -> &'static str { let stdout = std::process::Command::new("tmux") .args(["-LwU0dju1is5", "-f/dev/null", "start", ";", "display", "-p", "#{sixel_support}"]) @@ -33,7 +64,7 @@ impl Mux { pub(super) fn term_program() -> (Option, Option) { let (mut term, mut program) = (None, None); - if !*TMUX { + if *TMUX == 0 { return (term, program); } let Ok(output) = std::process::Command::new("tmux").arg("show-environment").output() else { diff --git a/yazi-boot/src/actions/debug.rs b/yazi-boot/src/actions/debug.rs index ced554edb..97160c149 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"))?; @@ -68,7 +72,7 @@ impl Actions { )?; writeln!(s, "\nMultiplexers")?; - writeln!(s, " TMUX : {:?}", *yazi_adapter::TMUX)?; + writeln!(s, " TMUX : {}", *yazi_adapter::TMUX)?; writeln!(s, " tmux version : {}", Self::process_output("tmux", "-V"))?; writeln!(s, " tmux build flags : enable-sixel={}", Mux::tmux_sixel_flag())?; writeln!(s, " ZELLIJ_SESSION_NAME: {:?}", env::var_os("ZELLIJ_SESSION_NAME"))?; 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" diff --git a/yazi-fs/src/fns.rs b/yazi-fs/src/fns.rs index 3487afc43..70872ca26 100644 --- a/yazi-fs/src/fns.rs +++ b/yazi-fs/src/fns.rs @@ -258,7 +258,7 @@ async fn _copy_with_progress(from: PathBuf, to: PathBuf, cha: Cha) -> io::Result tokio::task::spawn_blocking(move || { let mut reader = std::fs::File::open(from)?; let mut writer = std::fs::OpenOptions::new() - .mode(cha.mode) + .mode(cha.mode as u32) // Do not remove `as u32`, https://github.com/termux/termux-packages/pull/22481 .write(true) .create(true) .truncate(true)