yazi/yazi-adapter/src/lib.rs
2024-11-20 15:50:38 +08:00

43 lines
1.2 KiB
Rust

#![allow(clippy::unit_arg)]
yazi_macro::mod_flat!(
adapter chafa dimension emulator iip image info kgp kgp_old mux sixel ueberzug
);
use yazi_shared::{RoCell, SyncCell, env_exists, in_wsl};
pub static ADAPTOR: RoCell<Adapter> = RoCell::new();
// Tmux support
pub static TMUX: RoCell<bool> = RoCell::new();
static ESCAPE: RoCell<&'static str> = RoCell::new();
static START: RoCell<&'static str> = RoCell::new();
static CLOSE: RoCell<&'static str> = RoCell::new();
// WSL support
pub static WSL: RoCell<bool> = RoCell::new();
// Image state
static SHOWN: SyncCell<Option<ratatui::layout::Rect>> = SyncCell::new(None);
pub fn init() {
// 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();
}
// WSL support
WSL.init(in_wsl());
ADAPTOR.init(Adapter::matches());
ADAPTOR.start();
}