Skip to content

Commit

Permalink
fix: disable passthrough when the user launches Yazi in Neovim inside…
Browse files Browse the repository at this point in the history
… tmux (#2014)
  • Loading branch information
sxyazi committed Dec 9, 2024
1 parent b8b3ab9 commit 3000d45
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
8 changes: 6 additions & 2 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions yazi-adapter/src/brand.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -27,7 +27,7 @@ impl Brand {
pub fn from_env() -> Option<Self> {
use Brand as B;

if env_exists("NVIM_LOG_FILE") && env_exists("NVIM") {
if *NVIM {
return Some(Self::Neovim);
}

Expand Down
6 changes: 3 additions & 3 deletions yazi-adapter/src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
12 changes: 11 additions & 1 deletion yazi-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ static CLOSE: RoCell<&'static str> = RoCell::new();
// WSL support
pub static WSL: RoCell<bool> = RoCell::new();

// Neovim support
pub static NVIM: RoCell<bool> = RoCell::new();

pub fn init() -> anyhow::Result<()> {
// Tmux support
TMUX.init(env_exists("TMUX_PANE") && env_exists("TMUX"));
Expand All @@ -29,17 +32,24 @@ pub fn init() -> anyhow::Result<()> {
CLOSE.init(if *TMUX { "\x1b\\" } else { "" });

if *TMUX {
_ = std::process::Command::new("tmux")
let status = 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();

if !status.as_ref().is_ok_and(|s| s.success()) {
tracing::error!("Failed to enable tmux passthrough: {:?}", status);
}
}

// 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)?;

Expand Down
4 changes: 2 additions & 2 deletions yazi-adapter/src/mux.rs
Original file line number Diff line number Diff line change
@@ -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<str> {
if *TMUX {
if *TMUX && !*NVIM {
std::borrow::Cow::Owned(format!(
"{}{}{}",
*START,
Expand Down
4 changes: 4 additions & 0 deletions yazi-boot/src/actions/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))?;
Expand Down
2 changes: 1 addition & 1 deletion yazi-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 3000d45

Please sign in to comment.