diff --git a/yazi-core/src/manager/commands/close.rs b/yazi-core/src/manager/commands/close.rs index 47e9478e..0c7dbb8b 100644 --- a/yazi-core/src/manager/commands/close.rs +++ b/yazi-core/src/manager/commands/close.rs @@ -1,12 +1,12 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::{manager::Manager, tasks::Tasks}; impl Manager { - pub fn close(&mut self, _: &Exec, tasks: &Tasks) -> bool { + pub fn close(&mut self, _: &Exec, tasks: &Tasks) { if self.tabs.len() > 1 { - return self.tabs.close(self.tabs.idx); + return render!(self.tabs.close(self.tabs.idx)); } - self.quit((), tasks) + self.quit((), tasks); } } diff --git a/yazi-core/src/manager/commands/hover.rs b/yazi-core/src/manager/commands/hover.rs index 75144d76..78760c43 100644 --- a/yazi-core/src/manager/commands/hover.rs +++ b/yazi-core/src/manager/commands/hover.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; -use yazi_shared::{emit, event::Exec, fs::Url, Layer}; +use yazi_shared::{emit, event::Exec, fs::Url, render, Layer}; use crate::manager::Manager; @@ -24,13 +24,13 @@ impl Manager { )); } - pub fn hover(&mut self, opt: impl Into) -> bool { + pub fn hover(&mut self, opt: impl Into) { // Hover on the file let opt = opt.into() as Opt; - let mut b = self.current_mut().repos(opt.url); + render!(self.current_mut().repos(opt.url)); // Re-peek - b |= self.peek(false); + self.peek(false); // Refresh watcher let mut to_watch = BTreeSet::new(); @@ -44,7 +44,5 @@ impl Manager { } } self.watcher.watch(to_watch); - - b } } diff --git a/yazi-core/src/manager/commands/peek.rs b/yazi-core/src/manager/commands/peek.rs index dd337d21..c73e094d 100644 --- a/yazi-core/src/manager/commands/peek.rs +++ b/yazi-core/src/manager/commands/peek.rs @@ -1,4 +1,4 @@ -use yazi_shared::{emit, event::Exec, fs::Url, Layer, MIME_DIR}; +use yazi_shared::{emit, event::Exec, fs::Url, render, Layer, MIME_DIR}; use crate::manager::Manager; @@ -30,14 +30,14 @@ impl Manager { emit!(Call(Exec::call("peek", vec![]).with_bool("force", force).vec(), Layer::Manager)); } - pub fn peek(&mut self, opt: impl Into) -> bool { + pub fn peek(&mut self, opt: impl Into) { let Some(hovered) = self.hovered() else { - return self.active_mut().preview.reset(); + return render!(self.active_mut().preview.reset()); }; let opt = opt.into() as Opt; if matches!(opt.only_if, Some(ref u) if *u != hovered.url) { - return false; + return; } let hovered = hovered.clone(); @@ -61,14 +61,13 @@ impl Manager { } else { self.active_mut().preview.go_folder(hovered, opt.force); } - return false; + return; } if let Some(s) = self.mimetype.get(&hovered.url).cloned() { self.active_mut().preview.go(hovered, &s, opt.force); } else { - return self.active_mut().preview.reset(); + return render!(self.active_mut().preview.reset()); } - false } } diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index 4a77f6cb..d47b4fca 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -15,13 +15,13 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn quit(&self, opt: impl Into, tasks: &Tasks) -> bool { + pub fn quit(&self, opt: impl Into, tasks: &Tasks) { let opt = opt.into() as Opt; let tasks = tasks.len(); if tasks == 0 { emit!(Quit(opt.no_cwd_file)); - return false; + return; } tokio::spawn(async move { @@ -32,6 +32,5 @@ impl Manager { } } }); - false } } diff --git a/yazi-core/src/manager/commands/refresh.rs b/yazi-core/src/manager/commands/refresh.rs index 8b56efd8..27d7f54c 100644 --- a/yazi-core/src/manager/commands/refresh.rs +++ b/yazi-core/src/manager/commands/refresh.rs @@ -10,7 +10,7 @@ impl Manager { emit!(Call(Exec::call("refresh", vec![]).vec(), Layer::Manager)); } - pub fn refresh(&mut self, _: &Exec) -> bool { + pub fn refresh(&mut self, _: &Exec) { env::set_current_dir(self.cwd()).ok(); env::set_var("PWD", self.cwd()); @@ -22,6 +22,6 @@ impl Manager { self.watcher.trigger_dirs(&[self.cwd()]); } - self.hover(None) + self.hover(None); } } diff --git a/yazi-core/src/manager/commands/seek.rs b/yazi-core/src/manager/commands/seek.rs index 8687e8f5..ecfb7c26 100644 --- a/yazi-core/src/manager/commands/seek.rs +++ b/yazi-core/src/manager/commands/seek.rs @@ -1,6 +1,6 @@ use yazi_config::PLUGIN; use yazi_plugin::isolate; -use yazi_shared::{event::Exec, MIME_DIR}; +use yazi_shared::{event::Exec, render, MIME_DIR}; use crate::manager::Manager; @@ -16,9 +16,9 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn seek(&mut self, opt: impl Into) -> bool { + pub fn seek(&mut self, opt: impl Into) { let Some(hovered) = self.hovered() else { - return self.active_mut().preview.reset(); + return render!(self.active_mut().preview.reset()); }; let mime = if hovered.is_dir() { @@ -26,15 +26,14 @@ impl Manager { } else if let Some(s) = self.mimetype.get(&hovered.url) { s } else { - return self.active_mut().preview.reset(); + return render!(self.active_mut().preview.reset()); }; let Some(previewer) = PLUGIN.previewer(&hovered.url, mime) else { - return self.active_mut().preview.reset(); + return render!(self.active_mut().preview.reset()); }; let opt = opt.into() as Opt; isolate::seek_sync(&previewer.exec, hovered.clone(), opt.units); - false } } diff --git a/yazi-core/src/manager/commands/suspend.rs b/yazi-core/src/manager/commands/suspend.rs index b1865de1..6218993f 100644 --- a/yazi-core/src/manager/commands/suspend.rs +++ b/yazi-core/src/manager/commands/suspend.rs @@ -4,12 +4,11 @@ use yazi_shared::event::Exec; use crate::manager::Manager; impl Manager { - pub fn suspend(&mut self, _: &Exec) -> bool { + pub fn suspend(&mut self, _: &Exec) { #[cfg(unix)] tokio::spawn(async move { Scheduler::app_stop().await; unsafe { libc::raise(libc::SIGTSTP) }; }); - false } } diff --git a/yazi-core/src/manager/commands/update_files.rs b/yazi-core/src/manager/commands/update_files.rs index 7c2917d5..19f79ad3 100644 --- a/yazi-core/src/manager/commands/update_files.rs +++ b/yazi-core/src/manager/commands/update_files.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, fs::FilesOp}; +use yazi_shared::{event::Exec, fs::FilesOp, render}; use crate::{folder::Folder, manager::Manager, tasks::Tasks}; @@ -13,51 +13,49 @@ impl TryFrom<&Exec> for Opt { } impl Manager { - fn handle_read(&mut self, op: FilesOp) -> bool { + // TODO: refactor this + fn handle_read(&mut self, op: FilesOp) { let url = op.url().clone(); let cwd = self.cwd().to_owned(); let hovered = self.hovered().map(|h| h.url()); - let mut b = if cwd == url { - self.current_mut().update(op) + if cwd == url { + render!(self.current_mut().update(op)); } else if matches!(self.parent(), Some(p) if p.cwd == url) { - self.active_mut().parent.as_mut().unwrap().update(op) + render!(self.active_mut().parent.as_mut().unwrap().update(op)); } else if matches!(self.hovered(), Some(h) if h.url == url) { self.active_mut().history.entry(url.clone()).or_insert_with(|| Folder::from(&url)); self.active_mut().apply_files_attrs(true); - self.active_mut().history.get_mut(&url).unwrap().update(op) | self.peek(true) + render!(self.active_mut().history.get_mut(&url).unwrap().update(op)); + self.peek(true); } else { self.active_mut().history.entry(url.clone()).or_insert_with(|| Folder::from(&url)).update(op); - false - }; + } - b |= self.active_mut().parent.as_mut().is_some_and(|p| p.hover(&cwd)); - b |= hovered.as_ref().is_some_and(|h| self.current_mut().hover(h)); + render!(self.active_mut().parent.as_mut().is_some_and(|p| p.hover(&cwd))); + render!(hovered.as_ref().is_some_and(|h| self.current_mut().hover(h))); if hovered.as_ref() != self.hovered().map(|h| &h.url) { - b |= self.hover(None); + self.hover(None); } - b } - fn handle_ioerr(&mut self, op: FilesOp) -> bool { + fn handle_ioerr(&mut self, op: FilesOp) { let url = op.url(); let op = FilesOp::Full(url.clone(), vec![]); if url == self.cwd() { self.current_mut().update(op); self.active_mut().leave(()); - true + render!(); } else if matches!(self.parent(), Some(p) if &p.cwd == url) { - self.active_mut().parent.as_mut().unwrap().update(op) - } else { - false + render!(self.active_mut().parent.as_mut().unwrap().update(op)); } } - pub fn update_files(&mut self, opt: impl TryInto, tasks: &Tasks) -> bool { + pub fn update_files(&mut self, opt: impl TryInto, tasks: &Tasks) { let Ok(opt) = opt.try_into() else { - return false; + return; }; let calc = !matches!(opt.op, FilesOp::Size(..) | FilesOp::IOErr(_) | FilesOp::Deleting(..)); @@ -66,9 +64,8 @@ impl Manager { ops.push(ops[0].chroot(u)); } - let mut b = false; for op in ops { - b |= match op { + match op { FilesOp::IOErr(..) => self.handle_ioerr(op), _ => self.handle_read(op), }; @@ -77,6 +74,5 @@ impl Manager { if calc { tasks.preload_sorted(&self.current().files); } - b } } diff --git a/yazi-core/src/manager/commands/update_mimetype.rs b/yazi-core/src/manager/commands/update_mimetype.rs index ffe15949..63e84151 100644 --- a/yazi-core/src/manager/commands/update_mimetype.rs +++ b/yazi-core/src/manager/commands/update_mimetype.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use yazi_plugin::ValueSendable; -use yazi_shared::{event::Exec, fs::Url}; +use yazi_shared::{event::Exec, fs::Url, render}; use crate::{manager::Manager, tasks::Tasks}; @@ -16,9 +16,9 @@ impl TryFrom<&Exec> for Opt { } impl Manager { - pub fn update_mimetype(&mut self, opt: impl TryInto, tasks: &Tasks) -> bool { + pub fn update_mimetype(&mut self, opt: impl TryInto, tasks: &Tasks) { let Ok(opt) = opt.try_into() else { - return false; + return; }; let linked = self.watcher.linked.read(); @@ -38,7 +38,7 @@ impl Manager { drop(linked); if updates.is_empty() { - return false; + return; } let affected: Vec<_> = self @@ -53,6 +53,6 @@ impl Manager { self.peek(false); tasks.preload_affected(&affected, &self.mimetype); - true + render!(); } } diff --git a/yazi-core/src/tab/commands/escape.rs b/yazi-core/src/tab/commands/escape.rs index fd552244..043a38b2 100644 --- a/yazi-core/src/tab/commands/escape.rs +++ b/yazi-core/src/tab/commands/escape.rs @@ -1,5 +1,5 @@ use bitflags::bitflags; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tab::{Mode, Tab}; @@ -52,32 +52,32 @@ impl Tab { #[inline] fn escape_search(&mut self) -> bool { self.search_stop() } - pub fn escape(&mut self, opt: impl Into) -> bool { + pub fn escape(&mut self, opt: impl Into) { let opt = opt.into() as Opt; if opt.is_empty() { - return self.escape_find() - || self.escape_visual() - || self.escape_select() - || self.escape_filter() - || self.escape_search(); + return render!( + self.escape_find() + || self.escape_visual() + || self.escape_select() + || self.escape_filter() + || self.escape_search() + ); } - let mut b = false; if opt.contains(Opt::FIND) { - b |= self.escape_find(); + render!(self.escape_find()); } if opt.contains(Opt::VISUAL) { - b |= self.escape_visual(); + render!(self.escape_visual()); } if opt.contains(Opt::SELECT) { - b |= self.escape_select(); + render!(self.escape_select()); } if opt.contains(Opt::FILTER) { - b |= self.escape_filter(); + render!(self.escape_filter()); } if opt.contains(Opt::SEARCH) { - b |= self.escape_search(); + render!(self.escape_search()); } - b } } diff --git a/yazi-core/src/tab/commands/find.rs b/yazi-core/src/tab/commands/find.rs index dba8e3d3..6db158a8 100644 --- a/yazi-core/src/tab/commands/find.rs +++ b/yazi-core/src/tab/commands/find.rs @@ -3,7 +3,7 @@ use std::time::Duration; use tokio::pin; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::Exec, Debounce, InputError, Layer}; +use yazi_shared::{emit, event::Exec, render, Debounce, InputError, Layer}; use crate::{folder::FilterCase, input::Input, tab::{Finder, Tab}}; @@ -54,20 +54,20 @@ impl Tab { false } - pub fn find_do<'a>(&mut self, opt: impl Into>) -> bool { + pub fn find_do<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; let Some(query) = opt.query else { - return false; + return; }; if query.is_empty() { return self.escape(super::escape::Opt::FIND); } let Ok(finder) = Finder::new(query, opt.case) else { - return false; + return; }; if matches!(&self.finder, Some(f) if f.filter == finder.filter) { - return false; + return; } let step = if opt.prev { @@ -81,7 +81,7 @@ impl Tab { } self.finder = Some(finder); - true + render!(); } pub fn find_arrow(&mut self, opt: impl Into) -> bool { diff --git a/yazi-core/src/tasks/tasks.rs b/yazi-core/src/tasks/tasks.rs index e60afd4a..683629a5 100644 --- a/yazi-core/src/tasks/tasks.rs +++ b/yazi-core/src/tasks/tasks.rs @@ -149,15 +149,9 @@ impl Tasks { false } - pub fn plugin_micro(&self, name: &str) -> bool { - self.scheduler.plugin_micro(name.to_owned()); - false - } + pub fn plugin_micro(&self, name: &str) { self.scheduler.plugin_micro(name.to_owned()); } - pub fn plugin_macro(&self, name: &str) -> bool { - self.scheduler.plugin_macro(name.to_owned()); - false - } + pub fn plugin_macro(&self, name: &str) { self.scheduler.plugin_macro(name.to_owned()); } pub fn preload_paged(&self, paged: &[File], mimetype: &HashMap) { let mut single_tasks = Vec::with_capacity(paged.len()); diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index 0e74233b..16a7fb09 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -25,8 +25,8 @@ impl<'a> Executor<'a> { return true; } - let b = if cx.completion.visible { - self.matches(Layer::Completion, key).or_else(|| self.matches(Layer::Input, key)) + if cx.completion.visible { + self.matches(Layer::Completion, key) || self.matches(Layer::Input, key) } else if cx.help.visible { self.matches(Layer::Help, key) } else if cx.input.visible { @@ -37,24 +37,24 @@ impl<'a> Executor<'a> { self.matches(Layer::Tasks, key) } else { self.matches(Layer::Manager, key) - }; - b == Some(true) + } } #[inline] - fn matches(&mut self, layer: Layer, key: Key) -> Option { + fn matches(&mut self, layer: Layer, key: Key) -> bool { for Control { on, exec, .. } in KEYMAP.get(layer) { if on.is_empty() || on[0] != key { continue; } - return Some(if on.len() > 1 { - self.app.cx.which.show(&key, layer) + if on.len() > 1 { + self.app.cx.which.show(&key, layer); } else { - self.dispatch(exec, layer) - }); + self.dispatch(exec, layer); + } + return true; } - None + false } #[inline] @@ -87,7 +87,7 @@ impl<'a> Executor<'a> { on!(stop); } - fn manager(&mut self, exec: &Exec) -> bool { + fn manager(&mut self, exec: &Exec) { macro_rules! on { (MANAGER, $name:ident $(,$args:expr)*) => { if exec.cmd == stringify!($name) { @@ -175,7 +175,7 @@ impl<'a> Executor<'a> { } } - fn tasks(&mut self, exec: &Exec) -> bool { + fn tasks(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -202,7 +202,7 @@ impl<'a> Executor<'a> { } } - fn select(&mut self, exec: &Exec) -> bool { + fn select(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -221,7 +221,7 @@ impl<'a> Executor<'a> { } } - fn input(&mut self, exec: &Exec) -> bool { + fn input(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -276,7 +276,7 @@ impl<'a> Executor<'a> { } } - fn help(&mut self, exec: &Exec) -> bool { + fn help(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -295,7 +295,7 @@ impl<'a> Executor<'a> { } } - fn completion(&mut self, exec: &Exec) -> bool { + fn completion(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { diff --git a/yazi-shared/src/event/render.rs b/yazi-shared/src/event/render.rs index 7f709414..c616f9c5 100644 --- a/yazi-shared/src/event/render.rs +++ b/yazi-shared/src/event/render.rs @@ -7,4 +7,9 @@ macro_rules! render { () => { $crate::event::NEED_RENDER.store(true, std::sync::atomic::Ordering::Relaxed); }; + ($expr:expr) => { + if $expr { + render!(); + } + }; }