From df3d8af854e62f77001853f99c3169de66b956da Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 28 Aug 2024 03:08:17 +0800 Subject: [PATCH] .. --- cspell.json | 2 +- yazi-adapter/src/emulator.rs | 4 ++-- yazi-adapter/src/lib.rs | 20 ++++++++++++++++---- yazi-adapter/src/macros.rs | 15 --------------- yazi-fm/src/term.rs | 8 ++++---- 5 files changed, 23 insertions(+), 26 deletions(-) delete mode 100644 yazi-adapter/src/macros.rs diff --git a/cspell.json b/cspell.json index f858aecd..bf33423c 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 3045adc8..a201121e 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::{tmux, Adapter, TMUX}; +use crate::{tcsi, Adapter, TMUX}; #[derive(Clone, Debug)] pub enum Emulator { @@ -123,7 +123,7 @@ impl Emulator { execute!( LineWriter::new(stderr()), SavePosition, - Print(tmux!("\x1b[>q\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\x1b[c")), + 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 29a66888..09f07985 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -8,7 +8,6 @@ mod image; mod iterm2; mod kitty; mod kitty_old; -mod macros; mod sixel; mod ueberzug; @@ -29,9 +28,9 @@ pub static ADAPTOR: RoCell = RoCell::new(); // Tmux support pub static TMUX: RoCell = 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(); +static ESCAPE: RoCell<&'static str> = RoCell::new(); +static START: RoCell<&'static str> = RoCell::new(); +static CLOSE: RoCell<&'static str> = RoCell::new(); // Image state static SHOWN: RoCell> = RoCell::new(); @@ -56,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-adapter/src/macros.rs b/yazi-adapter/src/macros.rs deleted file mode 100644 index 49256c99..00000000 --- a/yazi-adapter/src/macros.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[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) - } - }; -} diff --git a/yazi-fm/src/term.rs b/yazi-fm/src/term.rs index 5eaf130e..e7490cbe 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::{tmux, 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(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) + 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),