feat: better Zellij support with multi-factor detection involving emulator types (#336)

This commit is contained in:
三咲雅 · Misaki Masa 2023-11-06 08:10:57 +08:00 committed by GitHub
parent dcb4944974
commit 1f744810f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 20 deletions

View file

@ -1 +1 @@
{"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","USERPROFILE"],"version":"0.2","language":"en"}
{"language":"en","version":"0.2","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"]}

View file

@ -15,7 +15,7 @@ static IMAGE_SHOWN: AtomicBool = AtomicBool::new(false);
#[allow(clippy::type_complexity)]
static UEBERZUG: RoCell<Option<UnboundedSender<Option<(PathBuf, Rect)>>>> = RoCell::new();
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Adaptor {
Kitty,
Iterm2,
@ -27,37 +27,78 @@ pub enum Adaptor {
Chafa,
}
#[derive(Clone, Copy)]
enum Emulator {
Unknown,
Kitty,
Konsole,
Iterm2,
WezTerm,
Foot,
BlackBox,
VSCode,
Hyper,
Mintty,
}
impl Adaptor {
pub(super) fn detect() -> Self {
fn emulator() -> Emulator {
let vars = [
("ZELLIJ_SESSION_NAME", Self::Sixel),
("KITTY_WINDOW_ID", Self::Kitty),
("KONSOLE_VERSION", Self::Kitty),
("ITERM_SESSION_ID", Self::Iterm2),
("WEZTERM_EXECUTABLE", cfg!(windows).then_some(Self::Iterm2).unwrap_or(Self::Kitty)),
("VSCODE_INJECTION", Self::Sixel),
("KITTY_WINDOW_ID", Emulator::Kitty),
("KONSOLE_VERSION", Emulator::Konsole),
("ITERM_SESSION_ID", Emulator::Iterm2),
("WEZTERM_EXECUTABLE", Emulator::WezTerm),
("VSCODE_INJECTION", Emulator::VSCode),
];
match vars.iter().find(|v| env::var_os(v.0).is_some_and(|s| !s.is_empty())) {
match vars.into_iter().find(|v| env::var_os(v.0).is_some_and(|s| !s.is_empty())) {
Some(var) => return var.1,
None => warn!("[Adaptor] No special environment variables detected"),
}
let (term, program) = Self::term_program();
match program.as_str() {
"iTerm.app" => return Self::Iterm2,
"WezTerm" => return cfg!(windows).then_some(Self::Iterm2).unwrap_or(Self::Kitty),
"BlackBox" => return Self::Sixel,
"vscode" => return Self::Sixel,
"Hyper" => return Self::Sixel,
"mintty" => return Self::Iterm2,
"iTerm.app" => return Emulator::Iterm2,
"WezTerm" => return Emulator::WezTerm,
"BlackBox" => return Emulator::BlackBox,
"vscode" => return Emulator::VSCode,
"Hyper" => return Emulator::Hyper,
"mintty" => return Emulator::Mintty,
_ => warn!("[Adaptor] Unknown TERM_PROGRAM: {program}"),
}
match term.as_str() {
"xterm-kitty" => return Self::Kitty,
"foot" => return Self::Sixel,
"foot-extra" => return Self::Sixel,
"xterm-kitty" => return Emulator::Kitty,
"foot" => return Emulator::Foot,
"foot-extra" => return Emulator::Foot,
_ => warn!("[Adaptor] Unknown TERM: {term}"),
}
Emulator::Unknown
}
pub(super) fn detect() -> Self {
let mut protocols = match Self::emulator() {
Emulator::Unknown => vec![],
Emulator::Kitty => vec![Self::Kitty],
Emulator::Konsole => vec![Self::Kitty, Self::Iterm2, Self::Sixel],
Emulator::Iterm2 => vec![Self::Iterm2, Self::Sixel],
Emulator::WezTerm => vec![Self::Kitty, Self::Iterm2, Self::Sixel],
Emulator::Foot => vec![Self::Sixel],
Emulator::BlackBox => vec![Self::Sixel],
Emulator::VSCode => vec![Self::Sixel],
Emulator::Hyper => vec![Self::Sixel],
Emulator::Mintty => vec![Self::Iterm2],
};
#[cfg(windows)]
protocols.retain(|p| *p == Self::Iterm2);
if env::var_os("ZELLIJ_SESSION_NAME").is_some_and(|s| !s.is_empty()) {
protocols.retain(|p| *p == Self::Sixel);
}
if *TMUX && protocols.len() > 1 {
protocols.retain(|p| *p != Self::Kitty);
}
if let Some(p) = protocols.first() {
return *p;
}
match env::var("XDG_SESSION_TYPE").unwrap_or_default().as_str() {
"x11" => return Self::X11,

View file

@ -68,7 +68,7 @@ impl Highlighter {
break;
}
if !plain && line.len() > 10000 {
if !plain && line.len() > 6000 {
mem::take(&mut before);
plain = true;
}