From 87406b11222587b79a466f11bd457b3f8225012d Mon Sep 17 00:00:00 2001 From: Lipman Date: Sun, 4 Aug 2024 22:13:42 +0800 Subject: [PATCH 1/2] feat: add support portrait orientation preview for EXIF image --- yazi-plugin/preset/plugins/magick.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/yazi-plugin/preset/plugins/magick.lua b/yazi-plugin/preset/plugins/magick.lua index 75ba7a380..7debe836b 100644 --- a/yazi-plugin/preset/plugins/magick.lua +++ b/yazi-plugin/preset/plugins/magick.lua @@ -24,6 +24,7 @@ function M:preload() "-density", "200", tostring(self.file.url), + "-auto-orient", "-resize", string.format("%dx%d^", PREVIEW.max_width, PREVIEW.max_height), "-quality", From d16c3515d9fed5e7d71108d79efc3d6ebdfb46a5 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 5 Aug 2024 17:12:28 +0800 Subject: [PATCH 2/2] .. --- cspell.json | 2 +- yazi-config/preset/yazi.toml | 4 ++-- yazi-core/src/manager/commands/hover.rs | 2 +- .../src/manager/commands/update_mimetype.rs | 5 +++- yazi-core/src/manager/watcher.rs | 2 +- yazi-core/src/tab/preview.rs | 24 ++++--------------- yazi-fs/src/files.rs | 11 ++++----- yazi-plugin/preset/plugins/magick.lua | 2 +- yazi-shared/src/fs/cha.rs | 14 +++++++++++ yazi-shared/src/fs/file.rs | 7 ------ 10 files changed, 34 insertions(+), 39 deletions(-) diff --git a/cspell.json b/cspell.json index 50a7b5b47..ee4662c75 100644 --- a/cspell.json +++ b/cspell.json @@ -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","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"],"language":"en","version":"0.2"} \ No newline at end of file +{"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"],"version":"0.2","language":"en","flagWords":[]} \ No newline at end of file diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 180134414..cd8a3f52d 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -92,7 +92,7 @@ fetchers = [ ] preloaders = [ # Image - { mime = "image/{avif,heic,jxl,svg+xml}", run = "magick" }, + { mime = "image/{avif,hei?,jxl,svg+xml}", run = "magick" }, { mime = "image/*", run = "image" }, # Video { mime = "video/*", run = "video" }, @@ -110,7 +110,7 @@ previewers = [ # JSON { mime = "application/{json,x-ndjson}", run = "json" }, # Image - { mime = "image/{avif,heic,jxl,svg+xml}", run = "magick" }, + { mime = "image/{avif,hei?,jxl,svg+xml}", run = "magick" }, { mime = "image/*", run = "image" }, # Video { mime = "video/*", run = "video" }, diff --git a/yazi-core/src/manager/commands/hover.rs b/yazi-core/src/manager/commands/hover.rs index 78b9c7384..cfcc23311 100644 --- a/yazi-core/src/manager/commands/hover.rs +++ b/yazi-core/src/manager/commands/hover.rs @@ -28,7 +28,7 @@ impl Manager { self.current_mut().tracing = true; } - // Re-peek + // Repeek self.peek(false); // Refresh watcher diff --git a/yazi-core/src/manager/commands/update_mimetype.rs b/yazi-core/src/manager/commands/update_mimetype.rs index c3720a01a..2953e3f31 100644 --- a/yazi-core/src/manager/commands/update_mimetype.rs +++ b/yazi-core/src/manager/commands/update_mimetype.rs @@ -50,9 +50,12 @@ impl Manager { .cloned() .collect(); + let repeek = self.hovered().is_some_and(|f| updates.contains_key(&f.url)); self.mimetype.extend(updates); - self.peek(false); + if repeek { + self.peek(false); + } tasks.prework_affected(&affected, &self.mimetype); render!(); } diff --git a/yazi-core/src/manager/watcher.rs b/yazi-core/src/manager/watcher.rs index d417936a8..968e6d622 100644 --- a/yazi-core/src/manager/watcher.rs +++ b/yazi-core/src/manager/watcher.rs @@ -111,7 +111,7 @@ impl Watcher { async fn fan_out(rx: UnboundedReceiver) { // TODO: revert this once a new notification is implemented - let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(50)); + let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(100)); pin!(rx); while let Some(chunk) = rx.next().await { diff --git a/yazi-core/src/tab/preview.rs b/yazi-core/src/tab/preview.rs index 11d77528f..e25bad2eb 100644 --- a/yazi-core/src/tab/preview.rs +++ b/yazi-core/src/tab/preview.rs @@ -89,25 +89,11 @@ impl Preview { matches!(self.lock, Some(ref lock) if lock.url == *url) } + #[inline] fn content_unchanged(&self, url: &Url, cha: &Cha) -> bool { - let Some(lock) = &self.lock else { - return false; - }; - - *url == lock.url - && self.skip == lock.skip - && cha.len == lock.cha.len - && cha.mtime == lock.cha.mtime - && cha.kind == lock.cha.kind - && { - #[cfg(unix)] - { - cha.perm == lock.cha.perm - } - #[cfg(windows)] - { - true - } - } + match &self.lock { + Some(l) => *url == l.url && self.skip == l.skip && cha.hits(l.cha), + None => false, + } } } diff --git a/yazi-fs/src/files.rs b/yazi-fs/src/files.rs index 78cebe572..b0ee40f0a 100644 --- a/yazi-fs/src/files.rs +++ b/yazi-fs/src/files.rs @@ -264,19 +264,18 @@ impl Files { macro_rules! go { ($dist:expr, $src:expr, $inc:literal) => { - let mut b = false; + let mut b = true; for i in 0..$dist.len() { if let Some(f) = $src.remove(&$dist[i].url) { - if $dist[i] != f { - b = true; - $dist[i] = f; - } + b &= $dist[i].cha.hits(f.cha); + $dist[i] = f; + if $src.is_empty() { break; } } } - self.revision += if b { $inc } else { 0 }; + self.revision += if b { 0 } else { $inc }; }; } diff --git a/yazi-plugin/preset/plugins/magick.lua b/yazi-plugin/preset/plugins/magick.lua index 7debe836b..dbe1aa9d9 100644 --- a/yazi-plugin/preset/plugins/magick.lua +++ b/yazi-plugin/preset/plugins/magick.lua @@ -24,11 +24,11 @@ function M:preload() "-density", "200", tostring(self.file.url), - "-auto-orient", "-resize", string.format("%dx%d^", PREVIEW.max_width, PREVIEW.max_height), "-quality", tostring(PREVIEW.image_quality), + "-auto-orient", "JPG:" .. tostring(cache), }):spawn() diff --git a/yazi-shared/src/fs/cha.rs b/yazi-shared/src/fs/cha.rs index 10f09edb9..82d1d64e0 100644 --- a/yazi-shared/src/fs/cha.rs +++ b/yazi-shared/src/fs/cha.rs @@ -120,6 +120,20 @@ impl Cha { self.kind |= kind; self } + + #[inline] + pub fn hits(self, c: Self) -> bool { + self.len == c.len && self.mtime == c.mtime && self.ctime == c.ctime && self.kind == c.kind && { + #[cfg(unix)] + { + self.perm == c.perm + } + #[cfg(windows)] + { + true + } + } + } } impl Cha { diff --git a/yazi-shared/src/fs/file.rs b/yazi-shared/src/fs/file.rs index 5ab7456d0..b32b877ad 100644 --- a/yazi-shared/src/fs/file.rs +++ b/yazi-shared/src/fs/file.rs @@ -25,13 +25,6 @@ impl AsRef for File { fn as_ref(&self) -> &File { self } } -impl PartialEq for File { - #[inline] - fn eq(&self, other: &Self) -> bool { - self.cha == other.cha && self.url == other.url && self.link_to == other.link_to - } -} - impl File { #[inline] pub async fn from(url: Url) -> Result {