From 90b1e525b8a28605bf0e88f472f78b325a06aa4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Wed, 28 Aug 2024 03:08:52 +0800 Subject: [PATCH] fix: `DECSET` and `DECRQM` tmux passthrough (#1564) --- cspell.json | 2 +- yazi-adapter/src/emulator.rs | 7 ++----- yazi-adapter/src/lib.rs | 15 ++++++++++++++- yazi-fm/src/term.rs | 8 ++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cspell.json b/cspell.json index f858aecd1..bf33423c0 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds"],"version":"0.2"} \ No newline at end of file +{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi"],"language":"en","version":"0.2"} \ No newline at end of file diff --git a/yazi-adapter/src/emulator.rs b/yazi-adapter/src/emulator.rs index 1d6cf1013..a201121ec 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -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::{tcsi, 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(tcsi("\x1b[>q\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\x1b[c")), RestorePosition )?; diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index a0fe43cc2..09f07985e 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -37,9 +37,9 @@ static SHOWN: RoCell> = RoCell::n 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") @@ -55,3 +55,16 @@ pub fn init() { ADAPTOR.init(Adapter::matches()); ADAPTOR.start(); } + +pub fn tcsi(s: &str) -> std::borrow::Cow { + if *TMUX { + std::borrow::Cow::Owned(format!( + "{}{}{}", + *START, + s.trim_start_matches('\x1b').replace('\x1b', *ESCAPE), + *CLOSE + )) + } else { + std::borrow::Cow::Borrowed(s) + } +} diff --git a/yazi-fm/src/term.rs b/yazi-fm/src/term.rs index f68cd61ec..e7490cbea 100644 --- a/yazi-fm/src/term.rs +++ b/yazi-fm/src/term.rs @@ -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::{tcsi, 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(tcsi("\x1b[?12$p")), // Request cursor blink status (DECSET) + Print(tcsi("\x1bP$q q\x1b\\")), // Request cursor shape (DECRQM) + Print(tcsi("\x1b[?u\x1b[c")), // Request keyboard enhancement flags (CSI u) EnterAlternateScreen, EnableBracketedPaste, mouse::SetMouse(true),