mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-18 06:11:31 +03:00
feat: detect terminal type in tmux with CSI sequence in passthrough mode (#977)
This commit is contained in:
parent
0016876dc9
commit
4c35f26e1f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2704,6 +2704,7 @@ dependencies = [
|
||||
"imagesize",
|
||||
"kamadak-exif",
|
||||
"ratatui",
|
||||
"scopeguard",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"yazi-config",
|
||||
|
@ -23,6 +23,7 @@ image = "0.24.9"
|
||||
imagesize = "0.12.0"
|
||||
kamadak-exif = "0.5.5"
|
||||
ratatui = "=0.26.1"
|
||||
scopeguard = "1.2.0"
|
||||
tokio = { version = "1.37.0", features = [ "full" ] }
|
||||
|
||||
# Logging
|
||||
|
@ -2,10 +2,11 @@ use std::{env, io::{stderr, LineWriter}};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use crossterm::{cursor::{RestorePosition, SavePosition}, execute, style::Print, terminal::{disable_raw_mode, enable_raw_mode}};
|
||||
use scopeguard::defer;
|
||||
use tracing::warn;
|
||||
use yazi_shared::{env_exists, term::Term};
|
||||
|
||||
use crate::{Adaptor, TMUX};
|
||||
use crate::{Adaptor, CLOSE, ESCAPE, START, TMUX};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Emulator {
|
||||
@ -112,17 +113,20 @@ impl Emulator {
|
||||
}
|
||||
|
||||
pub fn via_csi() -> Result<Self> {
|
||||
defer! { disable_raw_mode().ok(); }
|
||||
enable_raw_mode()?;
|
||||
|
||||
execute!(
|
||||
LineWriter::new(stderr()),
|
||||
SavePosition,
|
||||
Print("\x1b[>q\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\x1b[c"),
|
||||
Print(format!(
|
||||
"{}[>q{}_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA{}\\{}[c{}",
|
||||
START, ESCAPE, ESCAPE, ESCAPE, CLOSE
|
||||
)),
|
||||
RestorePosition
|
||||
)?;
|
||||
|
||||
let resp = futures::executor::block_on(Term::read_until_da1())?;
|
||||
disable_raw_mode().ok();
|
||||
|
||||
let names = [
|
||||
("kitty", Self::Kitty),
|
||||
("Konsole", Self::Konsole),
|
||||
|
@ -31,22 +31,22 @@ static CLOSE: RoCell<&'static str> = RoCell::new();
|
||||
static SHOWN: RoCell<arc_swap::ArcSwapOption<ratatui::layout::Rect>> = RoCell::new();
|
||||
|
||||
pub fn init() {
|
||||
TMUX.init(env_exists("TMUX"));
|
||||
TMUX.init(env_exists("TMUX") && env_exists("TMUX_PANE"));
|
||||
START.init(if *TMUX { "\x1bPtmux;\x1b\x1b" } else { "\x1b" });
|
||||
CLOSE.init(if *TMUX { "\x1b\\" } else { "" });
|
||||
ESCAPE.init(if *TMUX { "\x1b\x1b" } else { "\x1b" });
|
||||
|
||||
SHOWN.with(Default::default);
|
||||
|
||||
ADAPTOR.init(Adaptor::matches());
|
||||
ADAPTOR.start();
|
||||
|
||||
if *TMUX {
|
||||
_ = std::process::Command::new("tmux")
|
||||
.args(["set", "-p", "allow-passthrough", "on"])
|
||||
.stdin(std::process::Stdio::null())
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.spawn();
|
||||
.status();
|
||||
}
|
||||
|
||||
SHOWN.with(Default::default);
|
||||
|
||||
ADAPTOR.init(Adaptor::matches());
|
||||
ADAPTOR.start();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user