Skip to content

Commit

Permalink
feat: add support portrait orientation preview for EXIF image (#1412)
Browse files Browse the repository at this point in the history
Co-authored-by: sxyazi <sxyazi@gmail.com>
  • Loading branch information
TobisLee and sxyazi authored Aug 5, 2024
1 parent cc50f94 commit cda7d3f
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -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"}
{"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":[]}
4 changes: 2 additions & 2 deletions yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" },
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/manager/commands/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Manager {
self.current_mut().tracing = true;
}

// Re-peek
// Repeek
self.peek(false);

// Refresh watcher
Expand Down
5 changes: 4 additions & 1 deletion yazi-core/src/manager/commands/update_mimetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/manager/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Watcher {

async fn fan_out(rx: UnboundedReceiver<Url>) {
// 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 {
Expand Down
24 changes: 5 additions & 19 deletions yazi-core/src/tab/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
11 changes: 5 additions & 6 deletions yazi-fs/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
}

Expand Down
1 change: 1 addition & 0 deletions yazi-plugin/preset/plugins/magick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function M:preload()
string.format("%dx%d^", PREVIEW.max_width, PREVIEW.max_height),
"-quality",
tostring(PREVIEW.image_quality),
"-auto-orient",
"JPG:" .. tostring(cache),
}):spawn()

Expand Down
14 changes: 14 additions & 0 deletions yazi-shared/src/fs/cha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions yazi-shared/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ impl AsRef<File> 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<Self> {
Expand Down

0 comments on commit cda7d3f

Please sign in to comment.