mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: CSI-based Vim and Neovim built-in terminal detection for better accuracy (#2327)
This commit is contained in:
parent
e2c841cca4
commit
f506849fb5
5 changed files with 9 additions and 22 deletions
|
|
@ -1 +1 @@
|
||||||
{"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","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","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","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","Sysinfo","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR"],"flagWords":[],"version":"0.2"}
|
{"version":"0.2","language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","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","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","Konsole","Alacritty","Überzug","pkgs","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","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","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR","libvterm"]}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
use yazi_shared::env_exists;
|
use yazi_shared::env_exists;
|
||||||
|
|
||||||
use crate::{Mux, NVIM};
|
use crate::Mux;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum Brand {
|
pub enum Brand {
|
||||||
|
|
@ -20,7 +20,7 @@ pub enum Brand {
|
||||||
Hyper,
|
Hyper,
|
||||||
Mintty,
|
Mintty,
|
||||||
Tmux,
|
Tmux,
|
||||||
Neovim,
|
VTerm,
|
||||||
Apple,
|
Apple,
|
||||||
Urxvt,
|
Urxvt,
|
||||||
Bobcat,
|
Bobcat,
|
||||||
|
|
@ -36,6 +36,7 @@ impl Brand {
|
||||||
("foot", Self::Foot),
|
("foot", Self::Foot),
|
||||||
("ghostty", Self::Ghostty),
|
("ghostty", Self::Ghostty),
|
||||||
("tmux ", Self::Tmux),
|
("tmux ", Self::Tmux),
|
||||||
|
("libvterm", Self::VTerm),
|
||||||
("Bobcat", Self::Bobcat),
|
("Bobcat", Self::Bobcat),
|
||||||
];
|
];
|
||||||
names.into_iter().find(|&(n, _)| resp.contains(n)).map(|(_, b)| b)
|
names.into_iter().find(|&(n, _)| resp.contains(n)).map(|(_, b)| b)
|
||||||
|
|
@ -44,10 +45,6 @@ impl Brand {
|
||||||
pub fn from_env() -> Option<Self> {
|
pub fn from_env() -> Option<Self> {
|
||||||
use Brand as B;
|
use Brand as B;
|
||||||
|
|
||||||
if NVIM.get() {
|
|
||||||
return Some(Self::Neovim);
|
|
||||||
}
|
|
||||||
|
|
||||||
let vars = [
|
let vars = [
|
||||||
("KITTY_WINDOW_ID", B::Kitty),
|
("KITTY_WINDOW_ID", B::Kitty),
|
||||||
("KONSOLE_VERSION", B::Konsole),
|
("KONSOLE_VERSION", B::Konsole),
|
||||||
|
|
@ -112,7 +109,7 @@ impl Brand {
|
||||||
B::Hyper => &[A::Iip, A::Sixel],
|
B::Hyper => &[A::Iip, A::Sixel],
|
||||||
B::Mintty => &[A::Iip],
|
B::Mintty => &[A::Iip],
|
||||||
B::Tmux => &[],
|
B::Tmux => &[],
|
||||||
B::Neovim => &[],
|
B::VTerm => &[],
|
||||||
B::Apple => &[],
|
B::Apple => &[],
|
||||||
B::Urxvt => &[],
|
B::Urxvt => &[],
|
||||||
B::Bobcat => &[A::Iip, A::Sixel],
|
B::Bobcat => &[A::Iip, A::Sixel],
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ yazi_macro::mod_pub!(drivers);
|
||||||
|
|
||||||
yazi_macro::mod_flat!(adapter brand dimension emulator image info mux unknown);
|
yazi_macro::mod_flat!(adapter brand dimension emulator image info mux unknown);
|
||||||
|
|
||||||
use yazi_shared::{SyncCell, env_exists, in_wsl};
|
use yazi_shared::{SyncCell, in_wsl};
|
||||||
|
|
||||||
pub static EMULATOR: SyncCell<Emulator> = SyncCell::new(Emulator::unknown());
|
pub static EMULATOR: SyncCell<Emulator> = SyncCell::new(Emulator::unknown());
|
||||||
pub static ADAPTOR: SyncCell<Adapter> = SyncCell::new(Adapter::Chafa);
|
pub static ADAPTOR: SyncCell<Adapter> = SyncCell::new(Adapter::Chafa);
|
||||||
|
|
@ -15,9 +15,6 @@ static SHOWN: SyncCell<Option<ratatui::layout::Rect>> = SyncCell::new(None);
|
||||||
// WSL support
|
// WSL support
|
||||||
pub static WSL: SyncCell<bool> = SyncCell::new(false);
|
pub static WSL: SyncCell<bool> = SyncCell::new(false);
|
||||||
|
|
||||||
// Neovim support
|
|
||||||
pub static NVIM: SyncCell<bool> = SyncCell::new(false);
|
|
||||||
|
|
||||||
// Tmux support
|
// Tmux support
|
||||||
pub static TMUX: SyncCell<bool> = SyncCell::new(false);
|
pub static TMUX: SyncCell<bool> = SyncCell::new(false);
|
||||||
static ESCAPE: SyncCell<&'static str> = SyncCell::new("\x1b");
|
static ESCAPE: SyncCell<&'static str> = SyncCell::new("\x1b");
|
||||||
|
|
@ -28,9 +25,6 @@ pub fn init() -> anyhow::Result<()> {
|
||||||
// WSL support
|
// WSL support
|
||||||
WSL.set(in_wsl());
|
WSL.set(in_wsl());
|
||||||
|
|
||||||
// Neovim support
|
|
||||||
NVIM.set(env_exists("NVIM_LOG_FILE") && env_exists("NVIM"));
|
|
||||||
|
|
||||||
// Emulator detection
|
// Emulator detection
|
||||||
EMULATOR.set(Emulator::detect().unwrap_or_default());
|
EMULATOR.set(Emulator::detect().unwrap_or_default());
|
||||||
TMUX.set(EMULATOR.get().kind.is_left_and(|&b| b == Brand::Tmux));
|
TMUX.set(EMULATOR.get().kind.is_left_and(|&b| b == Brand::Tmux));
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{CLOSE, ESCAPE, Emulator, NVIM, START, TMUX};
|
use crate::{CLOSE, ESCAPE, Emulator, START, TMUX};
|
||||||
|
|
||||||
pub struct Mux;
|
pub struct Mux;
|
||||||
|
|
||||||
impl Mux {
|
impl Mux {
|
||||||
pub fn csi(s: &str) -> std::borrow::Cow<str> {
|
pub fn csi(s: &str) -> std::borrow::Cow<str> {
|
||||||
if TMUX.get() && !NVIM.get() {
|
if TMUX.get() {
|
||||||
std::borrow::Cow::Owned(format!(
|
std::borrow::Cow::Owned(format!(
|
||||||
"{START}{}{CLOSE}",
|
"{START}{}{CLOSE}",
|
||||||
s.trim_start_matches('\x1b').replace('\x1b', ESCAPE.get()),
|
s.trim_start_matches('\x1b').replace('\x1b', ESCAPE.get()),
|
||||||
|
|
@ -41,7 +41,7 @@ impl Mux {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tmux_drain() -> Result<()> {
|
pub fn tmux_drain() -> Result<()> {
|
||||||
if TMUX.get() && !NVIM.get() {
|
if TMUX.get() {
|
||||||
crossterm::execute!(std::io::stderr(), crossterm::style::Print(Mux::csi("\x1b[5n")))?;
|
crossterm::execute!(std::io::stderr(), crossterm::style::Print(Mux::csi("\x1b[5n")))?;
|
||||||
_ = futures::executor::block_on(Emulator::read_until_dsr());
|
_ = futures::executor::block_on(Emulator::read_until_dsr());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,6 @@ impl Actions {
|
||||||
writeln!(s, "\nWSL")?;
|
writeln!(s, "\nWSL")?;
|
||||||
writeln!(s, " WSL: {:?}", yazi_adapter::WSL.get())?;
|
writeln!(s, " WSL: {:?}", yazi_adapter::WSL.get())?;
|
||||||
|
|
||||||
writeln!(s, "\nNeovim")?;
|
|
||||||
writeln!(s, " NVIM : {}", yazi_adapter::NVIM.get())?;
|
|
||||||
writeln!(s, " Neovim version: {}", Self::process_output("nvim", "--version"))?;
|
|
||||||
|
|
||||||
writeln!(s, "\nVariables")?;
|
writeln!(s, "\nVariables")?;
|
||||||
writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?;
|
writeln!(s, " SHELL : {:?}", env::var_os("SHELL"))?;
|
||||||
writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?;
|
writeln!(s, " EDITOR : {:?}", env::var_os("EDITOR"))?;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue