fix: DECSET and DECRQM tmux passthrough

This commit is contained in:
sxyazi 2024-08-28 02:24:35 +08:00
parent caacd15110
commit a18a5e6957
No known key found for this signature in database
4 changed files with 26 additions and 13 deletions

View file

@ -7,7 +7,7 @@ use tokio::{io::{AsyncReadExt, BufReader}, time::timeout};
use tracing::{error, warn};
use yazi_shared::env_exists;
use crate::{Adapter, CLOSE, ESCAPE, START, TMUX};
use crate::{tmux, Adapter, TMUX};
#[derive(Clone, Debug)]
pub enum Emulator {
@ -123,10 +123,7 @@ impl Emulator {
execute!(
LineWriter::new(stderr()),
SavePosition,
Print(format!(
"{}[>q{}_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA{}\\{}[c{}",
START, ESCAPE, ESCAPE, ESCAPE, CLOSE
)),
Print(tmux!("\x1b[>q\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\x1b[c")),
RestorePosition
)?;

View file

@ -8,6 +8,7 @@ mod image;
mod iterm2;
mod kitty;
mod kitty_old;
mod macros;
mod sixel;
mod ueberzug;
@ -28,18 +29,18 @@ 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();
pub static ESCAPE: RoCell<&'static str> = RoCell::new();
pub static START: RoCell<&'static str> = RoCell::new();
pub static CLOSE: RoCell<&'static str> = RoCell::new();
// Image state
static SHOWN: RoCell<arc_swap::ArcSwapOption<ratatui::layout::Rect>> = RoCell::new();
pub fn init() {
TMUX.init(env_exists("TMUX") && env_exists("TMUX_PANE"));
ESCAPE.init(if *TMUX { "\x1b\x1b" } else { "\x1b" });
START.init(if *TMUX { "\x1bPtmux;\x1b\x1b" } else { "\x1b" });
CLOSE.init(if *TMUX { "\x1b\\" } else { "" });
ESCAPE.init(if *TMUX { "\x1b\x1b" } else { "\x1b" });
if *TMUX {
_ = std::process::Command::new("tmux")

View file

@ -0,0 +1,15 @@
#[macro_export]
macro_rules! tmux {
($s:literal) => {
if *$crate::TMUX {
std::borrow::Cow::Owned(format!(
"{}{}{}",
*$crate::START,
$s.trim_start_matches('\x1b').replace('\x1b', *$crate::ESCAPE),
*$crate::CLOSE
))
} else {
std::borrow::Cow::Borrowed($s)
}
};
}

View file

@ -4,7 +4,7 @@ use anyhow::Result;
use crossterm::{event::{DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, execute, queue, style::Print, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen, SetTitle}};
use cursor::RestoreCursor;
use ratatui::{backend::CrosstermBackend, buffer::Buffer, layout::Rect, CompletedFrame, Frame, Terminal};
use yazi_adapter::Emulator;
use yazi_adapter::{tmux, Emulator};
use yazi_config::{INPUT, MANAGER};
static CSI_U: AtomicBool = AtomicBool::new(false);
@ -28,9 +28,9 @@ impl Term {
enable_raw_mode()?;
execute!(
BufWriter::new(stderr()),
Print("\x1b[?12$p"), // Request cursor blink status (DECSET)
Print("\x1bP$q q\x1b\\"), // Request cursor shape (DECRQM)
Print("\x1b[?u\x1b[c"), // Request keyboard enhancement flags (CSI u)
Print(tmux!("\x1b[?12$p")), // Request cursor blink status (DECSET)
Print(tmux!("\x1bP$q q\x1b\\")), // Request cursor shape (DECRQM)
Print(tmux!("\x1b[?u\x1b[c")), // Request keyboard enhancement flags (CSI u)
EnterAlternateScreen,
EnableBracketedPaste,
mouse::SetMouse(true),