diff --git a/yazi-core/src/completion/commands/arrow.rs b/yazi-core/src/completion/commands/arrow.rs index 9368b5dd..998af286 100644 --- a/yazi-core/src/completion/commands/arrow.rs +++ b/yazi-core/src/completion/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::completion::Completion; @@ -13,10 +13,10 @@ impl From<&Exec> for Opt { } impl Completion { - fn next(&mut self, step: usize) -> bool { + fn next(&mut self, step: usize) { let len = self.cands.len(); if len == 0 { - return false; + return; } let old = self.cursor; @@ -27,10 +27,10 @@ impl Completion { self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old); } - old != self.cursor + render!(old != self.cursor); } - fn prev(&mut self, step: usize) -> bool { + fn prev(&mut self, step: usize) { let old = self.cursor; self.cursor = self.cursor.saturating_sub(step); @@ -38,11 +38,15 @@ impl Completion { self.offset = self.offset.saturating_sub(old - self.cursor); } - old != self.cursor + render!(old != self.cursor); } - pub fn arrow(&mut self, opt: impl Into) -> bool { + pub fn arrow(&mut self, opt: impl Into) { let opt = opt.into() as Opt; - if opt.step > 0 { self.next(opt.step as usize) } else { self.prev(opt.step.unsigned_abs()) } + if opt.step > 0 { + self.next(opt.step as usize); + } else { + self.prev(opt.step.unsigned_abs()); + } } } diff --git a/yazi-core/src/completion/commands/close.rs b/yazi-core/src/completion/commands/close.rs index fdd6f785..b5876c82 100644 --- a/yazi-core/src/completion/commands/close.rs +++ b/yazi-core/src/completion/commands/close.rs @@ -1,4 +1,4 @@ -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Exec, render, Layer}; use crate::{completion::Completion, input::Input}; @@ -16,7 +16,7 @@ impl Completion { emit!(Call(Exec::call("close", vec![]).vec(), Layer::Completion)); } - pub fn close(&mut self, opt: impl Into) -> bool { + pub fn close(&mut self, opt: impl Into) { let opt = opt.into() as Opt; if opt.submit { Input::_complete(self.selected(), self.ticket); @@ -24,6 +24,6 @@ impl Completion { self.caches.clear(); self.visible = false; - true + render!(); } } diff --git a/yazi-core/src/completion/commands/show.rs b/yazi-core/src/completion/commands/show.rs index 5454b289..609cebba 100644 --- a/yazi-core/src/completion/commands/show.rs +++ b/yazi-core/src/completion/commands/show.rs @@ -1,6 +1,6 @@ use std::{mem, ops::ControlFlow}; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::completion::Completion; @@ -54,28 +54,28 @@ impl Completion { prefixed.into_iter().map(ToOwned::to_owned).collect() } - pub fn show<'a>(&mut self, opt: impl Into>) -> bool { + pub fn show<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; if self.ticket != opt.ticket { - return false; + return; } if !opt.cache.is_empty() { self.caches.insert(opt.cache_name.to_owned(), opt.cache.clone()); } let Some(cache) = self.caches.get(opt.cache_name) else { - return false; + return; }; self.ticket = opt.ticket; self.cands = Self::match_candidates(opt.word, cache); if self.cands.is_empty() { - return mem::replace(&mut self.visible, false); + return render!(mem::replace(&mut self.visible, false)); } self.offset = 0; self.cursor = 0; self.visible = true; - true + render!(); } } diff --git a/yazi-core/src/completion/commands/trigger.rs b/yazi-core/src/completion/commands/trigger.rs index 14f4980b..85180bce 100644 --- a/yazi-core/src/completion/commands/trigger.rs +++ b/yazi-core/src/completion/commands/trigger.rs @@ -1,7 +1,7 @@ use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}}; use tokio::fs; -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Exec, render, Layer}; use crate::completion::Completion; @@ -28,10 +28,10 @@ impl Completion { )); } - pub fn trigger<'a>(&mut self, opt: impl Into>) -> bool { + pub fn trigger<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; if opt.ticket < self.ticket { - return false; + return; } self.ticket = opt.ticket; @@ -76,7 +76,7 @@ impl Completion { Ok::<(), anyhow::Error>(()) }); - mem::replace(&mut self.visible, false) + render!(mem::replace(&mut self.visible, false)); } #[inline] diff --git a/yazi-core/src/folder/files.rs b/yazi-core/src/folder/files.rs index 535341d4..24d744e1 100644 --- a/yazi-core/src/folder/files.rs +++ b/yazi-core/src/folder/files.rs @@ -391,6 +391,9 @@ impl Files { } // --- Filter + #[inline] + pub fn filter(&self) -> Option<&Filter> { self.filter.as_ref() } + pub fn set_filter(&mut self, filter: Option) -> bool { if self.filter == filter { return false; diff --git a/yazi-core/src/help/commands/arrow.rs b/yazi-core/src/help/commands/arrow.rs index b78dbfbb..df51e04b 100644 --- a/yazi-core/src/help/commands/arrow.rs +++ b/yazi-core/src/help/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::help::Help; @@ -17,19 +17,23 @@ impl From for Opt { impl Help { #[inline] - pub fn arrow(&mut self, opt: impl Into) -> bool { + pub fn arrow(&mut self, opt: impl Into) { let max = self.bindings.len().saturating_sub(1); self.offset = self.offset.min(max); self.cursor = self.cursor.min(max); let opt = opt.into() as Opt; - if opt.step > 0 { self.next(opt.step as usize) } else { self.prev(opt.step.unsigned_abs()) } + if opt.step > 0 { + self.next(opt.step as usize); + } else { + self.prev(opt.step.unsigned_abs()); + } } - fn next(&mut self, step: usize) -> bool { + fn next(&mut self, step: usize) { let len = self.bindings.len(); if len == 0 { - return false; + return; } let old = self.cursor; @@ -40,10 +44,10 @@ impl Help { self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old); } - old != self.cursor + render!(old != self.cursor); } - fn prev(&mut self, step: usize) -> bool { + fn prev(&mut self, step: usize) { let old = self.cursor; self.cursor = self.cursor.saturating_sub(step); @@ -51,6 +55,6 @@ impl Help { self.offset = self.offset.saturating_sub(old - self.cursor); } - old != self.cursor + render!(old != self.cursor); } } diff --git a/yazi-core/src/help/commands/escape.rs b/yazi-core/src/help/commands/escape.rs index d0569676..b85b4845 100644 --- a/yazi-core/src/help/commands/escape.rs +++ b/yazi-core/src/help/commands/escape.rs @@ -1,15 +1,15 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::help::Help; impl Help { - pub fn escape(&mut self, _: &Exec) -> bool { - if self.in_filter.is_some() { - self.in_filter = None; - self.filter_apply(); - true - } else { - self.toggle(self.layer) + pub fn escape(&mut self, _: &Exec) { + if self.in_filter.is_none() { + return self.toggle(self.layer); } + + self.in_filter = None; + self.filter_apply(); + render!(); } } diff --git a/yazi-core/src/help/commands/filter.rs b/yazi-core/src/help/commands/filter.rs index 5a93c07b..f559f8c5 100644 --- a/yazi-core/src/help/commands/filter.rs +++ b/yazi-core/src/help/commands/filter.rs @@ -1,15 +1,15 @@ use yazi_config::popup::{Offset, Origin, Position}; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::{help::Help, input::Input}; impl Help { - pub fn filter(&mut self, _: &Exec) -> bool { + pub fn filter(&mut self, _: &Exec) { let mut input = Input::default(); input.position = Position::new(Origin::BottomLeft, Offset::line()); self.in_filter = Some(input); self.filter_apply(); - true + render!(); } } diff --git a/yazi-core/src/help/help.rs b/yazi-core/src/help/help.rs index 455a2882..d4741b25 100644 --- a/yazi-core/src/help/help.rs +++ b/yazi-core/src/help/help.rs @@ -1,7 +1,7 @@ use crossterm::event::KeyCode; use unicode_width::UnicodeWidthStr; use yazi_config::{keymap::{Control, Key}, KEYMAP}; -use yazi_shared::{term::Term, Layer}; +use yazi_shared::{render, term::Term, Layer}; use super::HELP_MARGIN; use crate::input::Input; @@ -24,7 +24,7 @@ impl Help { #[inline] pub fn limit() -> usize { Term::size().rows.saturating_sub(HELP_MARGIN) as usize } - pub fn toggle(&mut self, layer: Layer) -> bool { + pub fn toggle(&mut self, layer: Layer) { self.visible = !self.visible; self.layer = layer; @@ -34,7 +34,7 @@ impl Help { self.offset = 0; self.cursor = 0; - true + render!(); } pub(super) fn filter_apply(&mut self) -> bool { @@ -61,17 +61,20 @@ impl Help { if key.is_enter() { self.in_filter = None; + render!(); return true; } - let b = match &key { + match &key { Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false } => { - input.backspace(false) + input.backspace(false); } - _ => input.type_(key), - }; - - if b { self.filter_apply() } else { false } + _ => { + input.type_(key); + } + } + self.filter_apply(); + true } } diff --git a/yazi-core/src/input/commands/backspace.rs b/yazi-core/src/input/commands/backspace.rs index 1bb89a86..51d17539 100644 --- a/yazi-core/src/input/commands/backspace.rs +++ b/yazi-core/src/input/commands/backspace.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::Input; @@ -14,14 +14,14 @@ impl From for Opt { } impl Input { - pub fn backspace(&mut self, opt: impl Into) -> bool { + pub fn backspace(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let snap = self.snaps.current_mut(); if !opt.under && snap.cursor < 1 { - return false; + return; } else if opt.under && snap.cursor >= snap.value.len() { - return false; + return; } if opt.under { @@ -33,6 +33,6 @@ impl Input { } self.flush_value(); - true + render!(); } } diff --git a/yazi-core/src/input/commands/backward.rs b/yazi-core/src/input/commands/backward.rs index 4131ad02..30d18af6 100644 --- a/yazi-core/src/input/commands/backward.rs +++ b/yazi-core/src/input/commands/backward.rs @@ -3,7 +3,7 @@ use yazi_shared::{event::Exec, CharKind}; use crate::input::Input; impl Input { - pub fn backward(&mut self, _: &Exec) -> bool { + pub fn backward(&mut self, _: &Exec) { let snap = self.snap(); if snap.cursor == 0 { return self.move_(0); @@ -21,8 +21,7 @@ impl Input { } if prev != CharKind::Space { - return self.move_(-(snap.len() as isize)); + self.move_(-(snap.len() as isize)); } - false } } diff --git a/yazi-core/src/input/commands/close.rs b/yazi-core/src/input/commands/close.rs index 594258af..1224c156 100644 --- a/yazi-core/src/input/commands/close.rs +++ b/yazi-core/src/input/commands/close.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, InputError}; +use yazi_shared::{event::Exec, render, InputError}; use crate::{completion::Completion, input::Input}; @@ -14,7 +14,7 @@ impl From for Opt { } impl Input { - pub fn close(&mut self, opt: impl Into) -> bool { + pub fn close(&mut self, opt: impl Into) { let opt = opt.into() as Opt; if self.completion { @@ -28,6 +28,6 @@ impl Input { self.ticket = self.ticket.wrapping_add(1); self.visible = false; - true + render!(); } } diff --git a/yazi-core/src/input/commands/complete.rs b/yazi-core/src/input/commands/complete.rs index 50752f8e..11cabf91 100644 --- a/yazi-core/src/input/commands/complete.rs +++ b/yazi-core/src/input/commands/complete.rs @@ -1,6 +1,6 @@ use std::path::MAIN_SEPARATOR; -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Exec, render, Layer}; use crate::input::Input; @@ -27,10 +27,10 @@ impl Input { )); } - pub fn complete<'a>(&mut self, opt: impl Into>) -> bool { + pub fn complete<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; if self.ticket != opt.ticket { - return false; + return; } let [before, after] = self.partition(); @@ -42,7 +42,7 @@ impl Input { let snap = self.snaps.current_mut(); if new == snap.value { - return false; + return; } let delta = new.chars().count() as isize - snap.value.chars().count() as isize; @@ -50,6 +50,6 @@ impl Input { self.move_(delta); self.flush_value(); - true + render!(); } } diff --git a/yazi-core/src/input/commands/delete.rs b/yazi-core/src/input/commands/delete.rs index a46f6585..4101bf5d 100644 --- a/yazi-core/src/input/commands/delete.rs +++ b/yazi-core/src/input/commands/delete.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::{op::InputOp, Input}; @@ -14,22 +14,22 @@ impl From<&Exec> for Opt { } impl Input { - pub fn delete(&mut self, opt: impl Into) -> bool { + pub fn delete(&mut self, opt: impl Into) { let opt = opt.into() as Opt; match self.snap().op { InputOp::None => { self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, self.snap().cursor); - false } InputOp::Select(start) => { self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, start); - return self.handle_op(self.snap().cursor, true).then(|| self.move_(0)).is_some(); + render!(self.handle_op(self.snap().cursor, true)); + self.move_(0); } InputOp::Delete(..) => { self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, 0); - return self.move_(self.snap().len() as isize); + self.move_(self.snap().len() as isize); } - _ => false, + _ => {} } } } diff --git a/yazi-core/src/input/commands/escape.rs b/yazi-core/src/input/commands/escape.rs index 4f09955f..ad713e22 100644 --- a/yazi-core/src/input/commands/escape.rs +++ b/yazi-core/src/input/commands/escape.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}}; @@ -12,7 +12,7 @@ impl From<()> for Opt { } impl Input { - pub fn escape(&mut self, _: impl Into) -> bool { + pub fn escape(&mut self, _: impl Into) { let snap = self.snap_mut(); match snap.mode { InputMode::Normal if snap.op == InputOp::None => { @@ -30,7 +30,8 @@ impl Input { } } } + self.snaps.tag(self.limit()); - true + render!(); } } diff --git a/yazi-core/src/input/commands/forward.rs b/yazi-core/src/input/commands/forward.rs index fc07a27d..bbaff4ab 100644 --- a/yazi-core/src/input/commands/forward.rs +++ b/yazi-core/src/input/commands/forward.rs @@ -11,7 +11,7 @@ impl From<&Exec> for Opt { } impl Input { - pub fn forward(&mut self, opt: impl Into) -> bool { + pub fn forward(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let snap = self.snap(); diff --git a/yazi-core/src/input/commands/insert.rs b/yazi-core/src/input/commands/insert.rs index db4d6c6e..d95226fa 100644 --- a/yazi-core/src/input/commands/insert.rs +++ b/yazi-core/src/input/commands/insert.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::{op::InputOp, Input, InputMode}; @@ -14,13 +14,13 @@ impl From for Opt { } impl Input { - pub fn insert(&mut self, opt: impl Into) -> bool { + pub fn insert(&mut self, opt: impl Into) { let snap = self.snap_mut(); if snap.mode == InputMode::Normal { snap.op = InputOp::None; snap.mode = InputMode::Insert; } else { - return false; + return; } let opt = opt.into() as Opt; @@ -28,6 +28,6 @@ impl Input { self.move_(1); } - true + render!(); } } diff --git a/yazi-core/src/input/commands/kill.rs b/yazi-core/src/input/commands/kill.rs index 759f8d22..db1af71c 100644 --- a/yazi-core/src/input/commands/kill.rs +++ b/yazi-core/src/input/commands/kill.rs @@ -1,6 +1,6 @@ use std::ops::RangeBounds; -use yazi_shared::{event::Exec, CharKind}; +use yazi_shared::{event::Exec, render, CharKind}; use crate::input::Input; @@ -15,7 +15,7 @@ impl<'a> From<&'a Exec> for Opt<'a> { } impl Input { - fn kill_range(&mut self, range: impl RangeBounds) -> bool { + fn kill_range(&mut self, range: impl RangeBounds) { let snap = self.snap_mut(); snap.cursor = match range.start_bound() { std::ops::Bound::Included(i) => *i, @@ -23,12 +23,12 @@ impl Input { std::ops::Bound::Unbounded => 0, }; if snap.value.drain(range).next().is_none() { - return false; + return; } self.move_(0); self.flush_value(); - true + render!(); } /// Searches for a word boundary and returns the movement in the cursor @@ -66,7 +66,7 @@ impl Input { spaces + count_characters(input.skip(spaces)) } - pub fn kill<'a>(&mut self, opt: impl Into>) -> bool { + pub fn kill<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; let snap = self.snap_mut(); @@ -89,7 +89,7 @@ impl Input { let end = start + Self::find_word_boundary(snap.value[start..].chars()); self.kill_range(start..end) } - _ => false, + _ => {} } } } diff --git a/yazi-core/src/input/commands/move_.rs b/yazi-core/src/input/commands/move_.rs index f2b20a3e..c056010e 100644 --- a/yazi-core/src/input/commands/move_.rs +++ b/yazi-core/src/input/commands/move_.rs @@ -1,5 +1,5 @@ use unicode_width::UnicodeWidthStr; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::{op::InputOp, snap::InputSnap, Input}; @@ -21,22 +21,22 @@ impl From for Opt { } impl Input { - pub fn move_(&mut self, opt: impl Into) -> bool { + pub fn move_(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let snap = self.snap(); if opt.in_operating && snap.op == InputOp::None { - return false; + return; } - let b = self.handle_op( + render!(self.handle_op( if opt.step <= 0 { snap.cursor.saturating_sub(opt.step.unsigned_abs()) } else { snap.count().min(snap.cursor + opt.step as usize) }, false, - ); + )); let (limit, snap) = (self.limit(), self.snap_mut()); if snap.offset > snap.cursor { @@ -51,7 +51,5 @@ impl Input { snap.offset = snap.cursor - InputSnap::find_window(&s, 0, limit).end.saturating_sub(delta); } } - - b } } diff --git a/yazi-core/src/input/commands/paste.rs b/yazi-core/src/input/commands/paste.rs index 18027875..59879910 100644 --- a/yazi-core/src/input/commands/paste.rs +++ b/yazi-core/src/input/commands/paste.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::{input::{op::InputOp, Input}, CLIPBOARD}; @@ -11,7 +11,7 @@ impl From<&Exec> for Opt { } impl Input { - pub fn paste(&mut self, opt: impl Into) -> bool { + pub fn paste(&mut self, opt: impl Into) { if let Some(start) = self.snap().op.start() { self.snap_mut().op = InputOp::Delete(false, false, start); self.handle_op(self.snap().cursor, true); @@ -19,13 +19,13 @@ impl Input { let s = futures::executor::block_on(CLIPBOARD.get()); if s.is_empty() { - return false; + return; } let opt = opt.into() as Opt; self.insert(!opt.before); self.type_str(&s.to_string_lossy()); self.escape(()); - true + render!(); } } diff --git a/yazi-core/src/input/commands/redo.rs b/yazi-core/src/input/commands/redo.rs index 135238e3..3ca7ca1c 100644 --- a/yazi-core/src/input/commands/redo.rs +++ b/yazi-core/src/input/commands/redo.rs @@ -1,7 +1,9 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::Input; impl Input { - pub fn redo(&mut self, _: &Exec) -> bool { self.snaps.redo() } + pub fn redo(&mut self, _: &Exec) { + render!(self.snaps.redo()); + } } diff --git a/yazi-core/src/input/commands/show.rs b/yazi-core/src/input/commands/show.rs index ba9f74b9..ce2a44b7 100644 --- a/yazi-core/src/input/commands/show.rs +++ b/yazi-core/src/input/commands/show.rs @@ -1,7 +1,7 @@ use anyhow::anyhow; use tokio::sync::mpsc; use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::Exec, InputError, Layer}; +use yazi_shared::{emit, event::Exec, render, InputError, Layer}; use crate::input::Input; @@ -25,9 +25,9 @@ impl Input { rx } - pub fn show(&mut self, opt: impl TryInto) -> bool { + pub fn show(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { - return false; + return; }; self.close(false); @@ -45,6 +45,6 @@ impl Input { // Reset snaps self.snaps.reset(opt.cfg.value, self.limit()); - true + render!(); } } diff --git a/yazi-core/src/input/commands/type_.rs b/yazi-core/src/input/commands/type_.rs index e693a825..81c88b25 100644 --- a/yazi-core/src/input/commands/type_.rs +++ b/yazi-core/src/input/commands/type_.rs @@ -16,9 +16,10 @@ impl Input { } if let Some(c) = key.plain() { - let mut bits = [0; 4]; - return self.type_str(c.encode_utf8(&mut bits)); + self.type_str(c.encode_utf8(&mut [0; 4])); + return true; } + false } } diff --git a/yazi-core/src/input/commands/undo.rs b/yazi-core/src/input/commands/undo.rs index 8ba4b729..e0001c9f 100644 --- a/yazi-core/src/input/commands/undo.rs +++ b/yazi-core/src/input/commands/undo.rs @@ -1,15 +1,15 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::{Input, InputMode}; impl Input { - pub fn undo(&mut self, _: &Exec) -> bool { + pub fn undo(&mut self, _: &Exec) { if !self.snaps.undo() { - return false; + return; } if self.snap().mode == InputMode::Insert { self.escape(()); } - true + render!(); } } diff --git a/yazi-core/src/input/commands/visual.rs b/yazi-core/src/input/commands/visual.rs index 67ba3fcb..bffdf6cd 100644 --- a/yazi-core/src/input/commands/visual.rs +++ b/yazi-core/src/input/commands/visual.rs @@ -1,18 +1,18 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::{op::InputOp, Input, InputMode}; impl Input { #[inline] - pub fn visual(&mut self, _: &Exec) -> bool { + pub fn visual(&mut self, _: &Exec) { let snap = self.snap_mut(); if snap.mode != InputMode::Normal { - return false; + return; } else if snap.value.is_empty() { - return false; + return; } snap.op = InputOp::Select(snap.cursor); - true + render!(); } } diff --git a/yazi-core/src/input/commands/yank.rs b/yazi-core/src/input/commands/yank.rs index 14ee9914..7ae6ebb4 100644 --- a/yazi-core/src/input/commands/yank.rs +++ b/yazi-core/src/input/commands/yank.rs @@ -1,24 +1,23 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::input::{op::InputOp, Input}; impl Input { - pub fn yank(&mut self, _: &Exec) -> bool { + pub fn yank(&mut self, _: &Exec) { match self.snap().op { InputOp::None => { self.snap_mut().op = InputOp::Yank(self.snap().cursor); - false } InputOp::Select(start) => { self.snap_mut().op = InputOp::Yank(start); - return self.handle_op(self.snap().cursor, true).then(|| self.move_(0)).is_some(); + render!(self.handle_op(self.snap().cursor, true)); + self.move_(0); } InputOp::Yank(_) => { self.snap_mut().op = InputOp::Yank(0); self.move_(self.snap().len() as isize); - false } - _ => false, + _ => {} } } } diff --git a/yazi-core/src/input/input.rs b/yazi-core/src/input/input.rs index 862ac3f4..91ce3484 100644 --- a/yazi-core/src/input/input.rs +++ b/yazi-core/src/input/input.rs @@ -3,7 +3,7 @@ use std::ops::Range; use tokio::sync::mpsc::UnboundedSender; use unicode_width::UnicodeWidthStr; use yazi_config::{popup::Position, INPUT}; -use yazi_shared::InputError; +use yazi_shared::{render, InputError}; use super::{mode::InputMode, op::InputOp, InputSnap, InputSnaps}; use crate::CLIPBOARD; @@ -32,7 +32,7 @@ impl Input { self.position.offset.width.saturating_sub(INPUT.border()) as usize } - pub fn type_str(&mut self, s: &str) -> bool { + pub fn type_str(&mut self, s: &str) { let snap = self.snaps.current_mut(); if snap.cursor < 1 { snap.value.insert_str(0, s); @@ -42,7 +42,7 @@ impl Input { self.move_(s.chars().count() as isize); self.flush_value(); - true + render!(); } pub(super) fn handle_op(&mut self, cursor: usize, include: bool) -> bool { diff --git a/yazi-core/src/manager/commands/close.rs b/yazi-core/src/manager/commands/close.rs index 47e9478e..53a7ffb9 100644 --- a/yazi-core/src/manager/commands/close.rs +++ b/yazi-core/src/manager/commands/close.rs @@ -3,10 +3,10 @@ use yazi_shared::event::Exec; 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); } - self.quit((), tasks) + self.quit((), tasks); } } diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index fb329ce6..7e46def5 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -15,7 +15,7 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn create(&self, opt: impl Into) -> bool { + pub fn create(&self, opt: impl Into) { let opt = opt.into() as Opt; let cwd = self.cwd().to_owned(); tokio::spawn(async move { @@ -47,6 +47,5 @@ impl Manager { } Ok::<(), anyhow::Error>(()) }); - false } } 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/link.rs b/yazi-core/src/manager/commands/link.rs index 2933aa6d..8046764d 100644 --- a/yazi-core/src/manager/commands/link.rs +++ b/yazi-core/src/manager/commands/link.rs @@ -14,9 +14,13 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn link(&mut self, opt: impl Into, tasks: &Tasks) -> bool { - let opt = opt.into() as Opt; + pub fn link(&mut self, opt: impl Into, tasks: &Tasks) { let (cut, ref src) = self.yanked; - !cut && tasks.file_link(src, self.cwd(), opt.relative, opt.force) + if cut { + return; + } + + let opt = opt.into() as Opt; + tasks.file_link(src, self.cwd(), opt.relative, opt.force); } } diff --git a/yazi-core/src/manager/commands/open.rs b/yazi-core/src/manager/commands/open.rs index 48bf0b89..a519d70c 100644 --- a/yazi-core/src/manager/commands/open.rs +++ b/yazi-core/src/manager/commands/open.rs @@ -20,12 +20,12 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn open(&mut self, opt: impl Into, tasks: &Tasks) -> bool { + pub fn open(&mut self, opt: impl Into, tasks: &Tasks) { let selected = self.selected(); if selected.is_empty() { - return false; + return; } else if Self::quit_with_selected(&selected) { - return false; + return; } let (mut done, mut todo) = (Vec::with_capacity(selected.len()), vec![]); @@ -53,7 +53,6 @@ impl Manager { Self::_open_do(opt.interactive, done); }); - false } #[inline] @@ -64,10 +63,10 @@ impl Manager { )); } - pub fn open_do(&mut self, opt: impl Into, tasks: &Tasks) -> bool { + pub fn open_do(&mut self, opt: impl Into, tasks: &Tasks) { let opt = opt.into() as Opt; let Some(targets) = opt.targets else { - return false; + return; }; let targets: Vec<_> = targets @@ -76,15 +75,15 @@ impl Manager { .collect(); if targets.is_empty() { - return false; + return; } else if !opt.interactive { tasks.file_open(&targets); - return false; + return; } let openers: Vec<_> = OPEN.common_openers(&targets).into_iter().cloned().collect(); if openers.is_empty() { - return false; + return; } let urls = targets.into_iter().map(|(u, _)| u).collect(); @@ -94,7 +93,6 @@ impl Manager { Tasks::_open(urls, openers[choice].clone()); } }); - false } fn quit_with_selected(selected: &[&File]) -> bool { diff --git a/yazi-core/src/manager/commands/paste.rs b/yazi-core/src/manager/commands/paste.rs index f1f11637..e12a670d 100644 --- a/yazi-core/src/manager/commands/paste.rs +++ b/yazi-core/src/manager/commands/paste.rs @@ -14,15 +14,15 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn paste(&mut self, opt: impl Into, tasks: &Tasks) -> bool { + pub fn paste(&mut self, opt: impl Into, tasks: &Tasks) { let dest = self.cwd(); let (cut, ref src) = self.yanked; let opt = opt.into() as Opt; if cut { - tasks.file_cut(src, dest, opt.force) + tasks.file_cut(src, dest, opt.force); } else { - tasks.file_copy(src, dest, opt.force, opt.follow) + tasks.file_copy(src, dest, opt.force, opt.follow); } } } diff --git a/yazi-core/src/manager/commands/peek.rs b/yazi-core/src/manager/commands/peek.rs index dd337d21..8bb8ffa1 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,20 +30,20 @@ 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; - } - let hovered = hovered.clone(); if !self.active().preview.same_url(&hovered.url) { self.active_mut().preview.skip = 0; - self.active_mut().preview.reset(); + 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; } if let Some(skip) = opt.skip { @@ -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(); + 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/remove.rs b/yazi-core/src/manager/commands/remove.rs index 6716688a..a3896e88 100644 --- a/yazi-core/src/manager/commands/remove.rs +++ b/yazi-core/src/manager/commands/remove.rs @@ -17,9 +17,9 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn remove(&mut self, opt: impl Into, tasks: &Tasks) -> bool { + pub fn remove(&mut self, opt: impl Into, tasks: &Tasks) { let opt = opt.into() as Opt; let targets = self.selected().into_iter().map(|f| f.url()).collect(); - tasks.file_remove(targets, opt.force, opt.permanently) + tasks.file_remove(targets, opt.force, opt.permanently); } } diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index 37fb527f..632e6092 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -29,13 +29,13 @@ impl Manager { Ok(Self::_hover(Some(new))) } - pub fn rename(&self, opt: impl Into) -> bool { + pub fn rename(&self, opt: impl Into) { if self.active().in_selecting() { return self.bulk_rename(); } let Some(hovered) = self.hovered().map(|h| h.url()) else { - return false; + return; }; let opt = opt.into() as Opt; @@ -60,10 +60,9 @@ impl Manager { } }; }); - false } - fn bulk_rename(&self) -> bool { + fn bulk_rename(&self) { let old: Vec<_> = self.selected().into_iter().map(|f| &f.url).collect(); let root = max_common_root(&old); @@ -104,8 +103,6 @@ impl Manager { let new: Vec<_> = fs::read_to_string(&tmp).await?.lines().map(PathBuf::from).collect(); Self::bulk_rename_do(root, old, new).await }); - - false } async fn bulk_rename_do(root: PathBuf, old: Vec, new: Vec) -> Result<()> { 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/tab_close.rs b/yazi-core/src/manager/commands/tab_close.rs index eb4083ca..356b4dc7 100644 --- a/yazi-core/src/manager/commands/tab_close.rs +++ b/yazi-core/src/manager/commands/tab_close.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::manager::Tabs; @@ -17,12 +17,12 @@ impl From for Opt { } impl Tabs { - pub fn close(&mut self, opt: impl Into) -> bool { + pub fn close(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let len = self.items.len(); if len < 2 || opt.idx >= len { - return false; + return; } self.items.remove(opt.idx); @@ -30,6 +30,6 @@ impl Tabs { self.set_idx(self.absolute(1)); } - true + render!(); } } diff --git a/yazi-core/src/manager/commands/tab_create.rs b/yazi-core/src/manager/commands/tab_create.rs index 8fa89d39..556dabe1 100644 --- a/yazi-core/src/manager/commands/tab_create.rs +++ b/yazi-core/src/manager/commands/tab_create.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, fs::Url}; +use yazi_shared::{event::Exec, fs::Url, render}; use crate::{manager::Tabs, tab::Tab}; @@ -21,9 +21,9 @@ impl From<&Exec> for Opt { } impl Tabs { - pub fn create(&mut self, opt: impl Into) -> bool { + pub fn create(&mut self, opt: impl Into) { if self.items.len() >= MAX_TABS { - return false; + return; } let opt = opt.into() as Opt; @@ -35,6 +35,6 @@ impl Tabs { self.items.insert(self.idx + 1, tab); self.set_idx(self.idx + 1); - true + render!(); } } diff --git a/yazi-core/src/manager/commands/tab_swap.rs b/yazi-core/src/manager/commands/tab_swap.rs index e7f02425..aae8300c 100644 --- a/yazi-core/src/manager/commands/tab_swap.rs +++ b/yazi-core/src/manager/commands/tab_swap.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::manager::Tabs; @@ -13,14 +13,14 @@ impl From<&Exec> for Opt { } impl Tabs { - pub fn swap(&mut self, opt: impl Into) -> bool { + pub fn swap(&mut self, opt: impl Into) { let idx = self.absolute(opt.into().step); if idx == self.idx { - return false; + return; } self.items.swap(self.idx, idx); self.set_idx(idx); - true + render!(); } } diff --git a/yazi-core/src/manager/commands/tab_switch.rs b/yazi-core/src/manager/commands/tab_switch.rs index 4eeb41fe..7cd134a6 100644 --- a/yazi-core/src/manager/commands/tab_switch.rs +++ b/yazi-core/src/manager/commands/tab_switch.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::manager::Tabs; @@ -17,7 +17,7 @@ impl From<&Exec> for Opt { } impl Tabs { - pub fn switch(&mut self, opt: impl Into) -> bool { + pub fn switch(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let idx = if opt.relative { (self.idx as isize + opt.step).rem_euclid(self.items.len() as isize) as usize @@ -26,10 +26,10 @@ impl Tabs { }; if idx == self.idx || idx >= self.items.len() { - return false; + return; } self.set_idx(idx); - true + render!(); } } 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/manager/commands/yank.rs b/yazi-core/src/manager/commands/yank.rs index cb07bea5..bb917e37 100644 --- a/yazi-core/src/manager/commands/yank.rs +++ b/yazi-core/src/manager/commands/yank.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::manager::Manager; @@ -11,11 +11,11 @@ impl From<&Exec> for Opt { } impl Manager { - pub fn yank(&mut self, opt: impl Into) -> bool { + pub fn yank(&mut self, opt: impl Into) { let opt = opt.into() as Opt; self.yanked.0 = opt.cut; self.yanked.1 = self.selected().into_iter().map(|f| f.url()).collect(); - true + render!(); } } diff --git a/yazi-core/src/select/commands/arrow.rs b/yazi-core/src/select/commands/arrow.rs index 66f51fa2..7948d965 100644 --- a/yazi-core/src/select/commands/arrow.rs +++ b/yazi-core/src/select/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::select::Select; @@ -13,10 +13,10 @@ impl From<&Exec> for Opt { } impl Select { - fn next(&mut self, step: usize) -> bool { + fn next(&mut self, step: usize) { let len = self.items.len(); if len == 0 { - return false; + return; } let old = self.cursor; @@ -27,10 +27,10 @@ impl Select { self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old); } - old != self.cursor + render!(old != self.cursor); } - fn prev(&mut self, step: usize) -> bool { + fn prev(&mut self, step: usize) { let old = self.cursor; self.cursor = self.cursor.saturating_sub(step); @@ -38,10 +38,10 @@ impl Select { self.offset = self.offset.saturating_sub(old - self.cursor); } - old != self.cursor + render!(old != self.cursor); } - pub fn arrow(&mut self, opt: impl Into) -> bool { + pub fn arrow(&mut self, opt: impl Into) { let opt = opt.into() as Opt; if opt.step > 0 { self.next(opt.step as usize) } else { self.prev(opt.step.unsigned_abs()) } } diff --git a/yazi-core/src/select/commands/close.rs b/yazi-core/src/select/commands/close.rs index 5977cc29..bdf0eb68 100644 --- a/yazi-core/src/select/commands/close.rs +++ b/yazi-core/src/select/commands/close.rs @@ -1,5 +1,5 @@ use anyhow::anyhow; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::select::Select; @@ -15,7 +15,7 @@ impl From for Opt { } impl Select { - pub fn close(&mut self, opt: impl Into) -> bool { + pub fn close(&mut self, opt: impl Into) { let opt = opt.into() as Opt; if let Some(cb) = self.callback.take() { _ = cb.send(if opt.submit { Ok(self.cursor) } else { Err(anyhow!("canceled")) }); @@ -24,6 +24,6 @@ impl Select { self.cursor = 0; self.offset = 0; self.visible = false; - true + render!(); } } diff --git a/yazi-core/src/select/commands/show.rs b/yazi-core/src/select/commands/show.rs index 5abf8d6d..617a209f 100644 --- a/yazi-core/src/select/commands/show.rs +++ b/yazi-core/src/select/commands/show.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Result}; use tokio::sync::oneshot; use yazi_config::popup::SelectCfg; -use yazi_shared::{emit, event::Exec, term::Term, Layer}; +use yazi_shared::{emit, event::Exec, render, term::Term, Layer}; use crate::select::Select; @@ -25,9 +25,9 @@ impl Select { rx.await.unwrap_or_else(|_| Term::goodbye(|| false)) } - pub fn show(&mut self, opt: impl TryInto) -> bool { + pub fn show(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { - return false; + return; }; self.close(false); @@ -37,6 +37,6 @@ impl Select { self.callback = Some(opt.tx); self.visible = true; - true + render!(); } } diff --git a/yazi-core/src/tab/commands/arrow.rs b/yazi-core/src/tab/commands/arrow.rs index 098c7f53..37c6f492 100644 --- a/yazi-core/src/tab/commands/arrow.rs +++ b/yazi-core/src/tab/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::{manager::Manager, tab::Tab, Step}; @@ -20,7 +20,7 @@ where } impl Tab { - pub fn arrow(&mut self, opt: impl Into) -> bool { + pub fn arrow(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let ok = if opt.step.is_positive() { self.current.next(opt.step) @@ -28,7 +28,7 @@ impl Tab { self.current.prev(opt.step) }; if !ok { - return false; + return; } // Visual selection @@ -42,6 +42,6 @@ impl Tab { } Manager::_hover(None); - true + render!(); } } diff --git a/yazi-core/src/tab/commands/backstack.rs b/yazi-core/src/tab/commands/backstack.rs index 0ddab3f5..7bd9cad1 100644 --- a/yazi-core/src/tab/commands/backstack.rs +++ b/yazi-core/src/tab/commands/backstack.rs @@ -11,17 +11,15 @@ impl From<&Exec> for Opt { } impl Tab { - pub fn back(&mut self, _: impl Into) -> bool { + pub fn back(&mut self, _: impl Into) { if let Some(url) = self.backstack.shift_backward().cloned() { self.cd(url); } - false } - pub fn forward(&mut self, _: impl Into) -> bool { + pub fn forward(&mut self, _: impl Into) { if let Some(url) = self.backstack.shift_forward().cloned() { self.cd(url); } - false } } diff --git a/yazi-core/src/tab/commands/cd.rs b/yazi-core/src/tab/commands/cd.rs index dc173f69..38b1b550 100644 --- a/yazi-core/src/tab/commands/cd.rs +++ b/yazi-core/src/tab/commands/cd.rs @@ -3,7 +3,7 @@ use std::{mem, time::Duration}; use tokio::{fs, pin}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::Exec, fs::{expand_path, Url}, Debounce, InputError, Layer}; +use yazi_shared::{emit, event::Exec, fs::{expand_path, Url}, render, Debounce, InputError, Layer}; use crate::{completion::Completion, input::Input, manager::Manager, tab::Tab}; @@ -32,14 +32,14 @@ impl Tab { emit!(Call(Exec::call("cd", vec![target.to_string()]).vec(), Layer::Manager)); } - pub fn cd(&mut self, opt: impl Into) -> bool { + pub fn cd(&mut self, opt: impl Into) { let opt = opt.into() as Opt; if opt.interactive { return self.cd_interactive(); } if self.current.cwd == opt.target { - return false; + return; } // Take parent to history @@ -65,10 +65,10 @@ impl Tab { } Manager::_refresh(); - true + render!(); } - fn cd_interactive(&mut self) -> bool { + fn cd_interactive(&mut self) { tokio::spawn(async move { let rx = Input::_show(InputCfg::cd()); @@ -96,6 +96,5 @@ impl Tab { } } }); - false } } diff --git a/yazi-core/src/tab/commands/copy.rs b/yazi-core/src/tab/commands/copy.rs index aae06fbe..ddc327f4 100644 --- a/yazi-core/src/tab/commands/copy.rs +++ b/yazi-core/src/tab/commands/copy.rs @@ -13,7 +13,7 @@ impl<'a> From<&'a Exec> for Opt<'a> { } impl Tab { - pub fn copy<'a>(&self, opt: impl Into>) -> bool { + pub fn copy<'a>(&self, opt: impl Into>) { let opt = opt.into() as Opt; let mut s = OsString::new(); @@ -24,7 +24,7 @@ impl Tab { "dirname" => f.url.parent().map_or(OsStr::new(""), |p| p.as_os_str()), "filename" => f.name().unwrap_or(OsStr::new("")), "name_without_ext" => f.stem().unwrap_or(OsStr::new("")), - _ => return false, + _ => return, }); if it.peek().is_some() { s.push("\n"); @@ -32,6 +32,5 @@ impl Tab { } futures::executor::block_on(CLIPBOARD.set(s)); - false } } diff --git a/yazi-core/src/tab/commands/enter.rs b/yazi-core/src/tab/commands/enter.rs index a8a04e2b..e84da7e3 100644 --- a/yazi-core/src/tab/commands/enter.rs +++ b/yazi-core/src/tab/commands/enter.rs @@ -1,6 +1,6 @@ use std::mem; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::{manager::Manager, tab::Tab}; @@ -13,9 +13,9 @@ impl From<&Exec> for Opt { } impl Tab { - pub fn enter(&mut self, _: impl Into) -> bool { + pub fn enter(&mut self, _: impl Into) { let Some(hovered) = self.current.hovered().filter(|h| h.is_dir()).map(|h| h.url()) else { - return false; + return; }; // Current @@ -35,6 +35,6 @@ impl Tab { self.backstack.push(hovered); Manager::_refresh(); - true + render!(); } } diff --git a/yazi-core/src/tab/commands/escape.rs b/yazi-core/src/tab/commands/escape.rs index fd552244..052443aa 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}; @@ -42,42 +42,48 @@ impl Tab { } #[inline] - fn escape_select(&mut self) -> bool { self.select_all(Some(false)) } + fn escape_select(&mut self) -> bool { self.current.files.select_all(Some(false)) } #[inline] fn escape_filter(&mut self) -> bool { - self.filter_do(super::filter::Opt { query: "", ..Default::default() }) + let b = self.current.files.filter().is_some(); + self.filter_do(super::filter::Opt { query: "", ..Default::default() }); + b } #[inline] - fn escape_search(&mut self) -> bool { self.search_stop() } - - pub fn escape(&mut self, opt: impl Into) -> bool { - 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(); - } - - let mut b = false; - if opt.contains(Opt::FIND) { - b |= self.escape_find(); - } - if opt.contains(Opt::VISUAL) { - b |= self.escape_visual(); - } - if opt.contains(Opt::SELECT) { - b |= self.escape_select(); - } - if opt.contains(Opt::FILTER) { - b |= self.escape_filter(); - } - if opt.contains(Opt::SEARCH) { - b |= self.escape_search(); - } + fn escape_search(&mut self) -> bool { + let b = self.current.cwd.is_search(); + self.search_stop(); b } + + pub fn escape(&mut self, opt: impl Into) { + let opt = opt.into() as Opt; + if opt.is_empty() { + return render!( + self.escape_find() + || self.escape_visual() + || self.escape_select() + || self.escape_filter() + || self.escape_search() + ); + } + + if opt.contains(Opt::FIND) { + render!(self.escape_find()); + } + if opt.contains(Opt::VISUAL) { + render!(self.escape_visual()); + } + if opt.contains(Opt::SELECT) { + render!(self.escape_select()); + } + if opt.contains(Opt::FILTER) { + render!(self.escape_filter()); + } + if opt.contains(Opt::SEARCH) { + render!(self.escape_search()); + } + } } diff --git a/yazi-core/src/tab/commands/filter.rs b/yazi-core/src/tab/commands/filter.rs index c471b40f..d0e79241 100644 --- a/yazi-core/src/tab/commands/filter.rs +++ b/yazi-core/src/tab/commands/filter.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::{Filter, FilterCase}, input::Input, manager::Manager, tab::Tab}; @@ -20,7 +20,7 @@ impl<'a> From<&'a Exec> for Opt<'a> { } impl Tab { - pub fn filter<'a>(&mut self, opt: impl Into>) -> bool { + pub fn filter<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; tokio::spawn(async move { let rx = Input::_show(InputCfg::filter()); @@ -38,10 +38,9 @@ impl Tab { )); } }); - false } - pub fn filter_do<'a>(&mut self, opt: impl Into>) -> bool { + pub fn filter_do<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; let filter = if opt.query.is_empty() { @@ -49,17 +48,17 @@ impl Tab { } else if let Ok(f) = Filter::new(opt.query, opt.case) { Some(f) } else { - return false; + return; }; let hovered = self.current.hovered().map(|f| f.url()); if !self.current.files.set_filter(filter) { - return false; + return; } if self.current.repos(hovered) { Manager::_hover(None); } - true + render!(); } } diff --git a/yazi-core/src/tab/commands/find.rs b/yazi-core/src/tab/commands/find.rs index dba8e3d3..f865c6d2 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}}; @@ -32,7 +32,7 @@ impl From<&Exec> for ArrowOpt { } impl Tab { - pub fn find<'a>(&mut self, opt: impl Into>) -> bool { + pub fn find<'a>(&mut self, opt: impl Into>) { let opt = opt.into() as Opt; tokio::spawn(async move { let rx = Input::_show(InputCfg::find(opt.prev)); @@ -51,23 +51,22 @@ 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,21 +80,19 @@ impl Tab { } self.finder = Some(finder); - true + render!(); } - pub fn find_arrow(&mut self, opt: impl Into) -> bool { + pub fn find_arrow(&mut self, opt: impl Into) { let Some(finder) = &mut self.finder else { - return false; + return; }; - let b = finder.catchup(&self.current.files); - let step = if opt.into().prev { - finder.prev(&self.current.files, self.current.cursor, false) + render!(finder.catchup(&self.current.files)); + if opt.into().prev { + finder.prev(&self.current.files, self.current.cursor, false).map(|s| self.arrow(s)); } else { - finder.next(&self.current.files, self.current.cursor, false) - }; - - b | step.is_some_and(|s| self.arrow(s)) + finder.next(&self.current.files, self.current.cursor, false).map(|s| self.arrow(s)); + } } } diff --git a/yazi-core/src/tab/commands/hidden.rs b/yazi-core/src/tab/commands/hidden.rs index 916e6ef1..8761865a 100644 --- a/yazi-core/src/tab/commands/hidden.rs +++ b/yazi-core/src/tab/commands/hidden.rs @@ -3,16 +3,14 @@ use yazi_shared::event::Exec; use crate::{manager::Manager, tab::Tab}; impl Tab { - pub fn hidden(&mut self, e: &Exec) -> bool { + pub fn hidden(&mut self, e: &Exec) { self.conf.show_hidden = match e.args.first().map(|s| s.as_bytes()) { Some(b"show") => true, Some(b"hide") => false, _ => !self.conf.show_hidden, }; - if self.apply_files_attrs(false) { - Manager::_hover(None); - return true; - } - false + + self.apply_files_attrs(false); + Manager::_hover(None); } } diff --git a/yazi-core/src/tab/commands/jump.rs b/yazi-core/src/tab/commands/jump.rs index 8a2913d9..e1876753 100644 --- a/yazi-core/src/tab/commands/jump.rs +++ b/yazi-core/src/tab/commands/jump.rs @@ -28,10 +28,10 @@ impl From<&Exec> for Opt { } impl Tab { - pub fn jump(&self, opt: impl Into) -> bool { + pub fn jump(&self, opt: impl Into) { let opt = opt.into() as Opt; if opt.type_ == OptType::None { - return false; + return; } let cwd = self.current.cwd.clone(); @@ -56,6 +56,5 @@ impl Tab { Tab::_cd(&url) } }); - false } } diff --git a/yazi-core/src/tab/commands/leave.rs b/yazi-core/src/tab/commands/leave.rs index 04769e1f..226a18fa 100644 --- a/yazi-core/src/tab/commands/leave.rs +++ b/yazi-core/src/tab/commands/leave.rs @@ -1,6 +1,6 @@ use std::mem; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::{manager::Manager, tab::Tab}; @@ -13,7 +13,7 @@ impl From<&Exec> for Opt { } impl Tab { - pub fn leave(&mut self, _: impl Into) -> bool { + pub fn leave(&mut self, _: impl Into) { let current = self .current .hovered() @@ -22,7 +22,7 @@ impl Tab { .or_else(|| self.current.cwd.parent_url()); let Some(current) = current else { - return false; + return; }; // Parent @@ -44,6 +44,6 @@ impl Tab { self.backstack.push(current); Manager::_refresh(); - true + render!(); } } diff --git a/yazi-core/src/tab/commands/linemode.rs b/yazi-core/src/tab/commands/linemode.rs index 12a1049c..7e66fda5 100644 --- a/yazi-core/src/tab/commands/linemode.rs +++ b/yazi-core/src/tab/commands/linemode.rs @@ -1,16 +1,16 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tab::Tab; impl Tab { - pub fn linemode(&mut self, e: &Exec) -> bool { - self.conf.patch(|c| { + pub fn linemode(&mut self, e: &Exec) { + render!(self.conf.patch(|c| { let Some(mode) = e.args.first() else { return; }; if !mode.is_empty() && mode.len() <= 20 { c.linemode = mode.to_owned(); } - }) + })); } } diff --git a/yazi-core/src/tab/commands/preview.rs b/yazi-core/src/tab/commands/preview.rs index a23ae3c2..291e327d 100644 --- a/yazi-core/src/tab/commands/preview.rs +++ b/yazi-core/src/tab/commands/preview.rs @@ -1,6 +1,6 @@ use anyhow::anyhow; use yazi_plugin::utils::PreviewLock; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tab::Tab; @@ -17,20 +17,20 @@ impl TryFrom<&Exec> for Opt { } impl Tab { - pub fn preview(&mut self, opt: impl TryInto) -> bool { + pub fn preview(&mut self, opt: impl TryInto) { let Some(hovered) = self.current.hovered().map(|h| &h.url) else { - return self.preview.reset(); + return render!(self.preview.reset()); }; let Ok(opt) = opt.try_into() else { - return false; + return; }; if hovered != &opt.lock.url { - return false; + return; } self.preview.lock = Some(opt.lock); - true + render!(); } } diff --git a/yazi-core/src/tab/commands/reveal.rs b/yazi-core/src/tab/commands/reveal.rs index f75832a2..ff0e51ab 100644 --- a/yazi-core/src/tab/commands/reveal.rs +++ b/yazi-core/src/tab/commands/reveal.rs @@ -26,16 +26,15 @@ impl Tab { emit!(Call(Exec::call("reveal", vec![target.to_string()]).vec(), Layer::Manager)); } - pub fn reveal(&mut self, opt: impl Into) -> bool { + pub fn reveal(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let Some(parent) = opt.target.parent_url() else { - return false; + return; }; - let b = self.cd(parent.clone()); + self.cd(parent.clone()); FilesOp::Creating(parent, vec![File::from_dummy(opt.target.clone())]).emit(); Manager::_hover(Some(opt.target)); - b } } diff --git a/yazi-core/src/tab/commands/search.rs b/yazi-core/src/tab/commands/search.rs index 59635de5..b5cd4ee1 100644 --- a/yazi-core/src/tab/commands/search.rs +++ b/yazi-core/src/tab/commands/search.rs @@ -5,7 +5,7 @@ use tokio::pin; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use yazi_config::popup::InputCfg; use yazi_plugin::external; -use yazi_shared::{event::Exec, fs::FilesOp}; +use yazi_shared::{event::Exec, fs::FilesOp, render}; use crate::{input::Input, manager::Manager, tab::Tab}; @@ -33,7 +33,7 @@ impl From<&Exec> for Opt { } impl Tab { - pub fn search(&mut self, opt: impl Into) -> bool { + pub fn search(&mut self, opt: impl Into) { let opt = opt.into() as Opt; if opt.type_ == OptType::None { return self.search_stop(); @@ -70,10 +70,11 @@ impl Tab { } Ok(()) })); - true + + render!(); } - pub(super) fn search_stop(&mut self) -> bool { + pub(super) fn search_stop(&mut self) { if let Some(handle) = self.search.take() { handle.abort(); } @@ -82,6 +83,5 @@ impl Tab { drop(mem::replace(&mut self.current, rep)); Manager::_refresh(); } - false } } diff --git a/yazi-core/src/tab/commands/select.rs b/yazi-core/src/tab/commands/select.rs index eb18b091..0170f0d5 100644 --- a/yazi-core/src/tab/commands/select.rs +++ b/yazi-core/src/tab/commands/select.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tab::Tab; @@ -9,9 +9,9 @@ pub struct Opt { impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { Self { - state: match e.named.get("state").map(|s| s.as_bytes()) { - Some(b"true") => Some(true), - Some(b"false") => Some(false), + state: match e.named.get("state").map(|s| s.as_str()) { + Some("true") => Some(true), + Some("false") => Some(false), _ => None, }, } @@ -22,14 +22,13 @@ impl From> for Opt { } impl Tab { - pub fn select(&mut self, opt: impl Into) -> bool { + pub fn select(&mut self, opt: impl Into) { if let Some(u) = self.current.hovered().map(|h| h.url()) { - return self.current.files.select(&u, opt.into().state); + render!(self.current.files.select(&u, opt.into().state)); } - false } - pub fn select_all(&mut self, opt: impl Into) -> bool { - self.current.files.select_all(opt.into().state) + pub fn select_all(&mut self, opt: impl Into) { + render!(self.current.files.select_all(opt.into().state)); } } diff --git a/yazi-core/src/tab/commands/shell.rs b/yazi-core/src/tab/commands/shell.rs index e6454a11..94d0aaff 100644 --- a/yazi-core/src/tab/commands/shell.rs +++ b/yazi-core/src/tab/commands/shell.rs @@ -20,7 +20,7 @@ impl<'a> From<&'a Exec> for Opt { } impl Tab { - pub fn shell(&self, opt: impl Into) -> bool { + pub fn shell(&self, opt: impl Into) { let mut opt = opt.into() as Opt; let selected: Vec<_> = self.selected().into_iter().map(|f| f.url()).collect(); @@ -42,6 +42,5 @@ impl Tab { spread: true, }); }); - false } } diff --git a/yazi-core/src/tab/commands/sort.rs b/yazi-core/src/tab/commands/sort.rs index 7def15ce..56a53292 100644 --- a/yazi-core/src/tab/commands/sort.rs +++ b/yazi-core/src/tab/commands/sort.rs @@ -6,7 +6,7 @@ use yazi_shared::event::Exec; use crate::tab::Tab; impl Tab { - pub fn sort(&mut self, e: &Exec) -> bool { + pub fn sort(&mut self, e: &Exec) { if let Some(by) = e.args.first() { self.conf.sort_by = SortBy::from_str(by).unwrap_or_default(); } @@ -14,6 +14,6 @@ impl Tab { self.conf.sort_reverse = e.named.contains_key("reverse"); self.conf.sort_dir_first = e.named.contains_key("dir-first"); - self.apply_files_attrs(false) + self.apply_files_attrs(false); } } diff --git a/yazi-core/src/tab/commands/visual_mode.rs b/yazi-core/src/tab/commands/visual_mode.rs index 470f6649..b5b1386e 100644 --- a/yazi-core/src/tab/commands/visual_mode.rs +++ b/yazi-core/src/tab/commands/visual_mode.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tab::{Mode, Tab}; @@ -13,7 +13,7 @@ impl From<&Exec> for Opt { } impl Tab { - pub fn visual_mode(&mut self, opt: impl Into) -> bool { + pub fn visual_mode(&mut self, opt: impl Into) { let opt = opt.into() as Opt; let idx = self.current.cursor; @@ -22,6 +22,6 @@ impl Tab { } else { self.mode = Mode::Select(idx, BTreeSet::from([idx])); }; - true + render!(); } } diff --git a/yazi-core/src/tab/tab.rs b/yazi-core/src/tab/tab.rs index c493ca38..15ee5534 100644 --- a/yazi-core/src/tab/tab.rs +++ b/yazi-core/src/tab/tab.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, collections::BTreeMap}; use anyhow::Result; use tokio::task::JoinHandle; -use yazi_shared::fs::{File, Url}; +use yazi_shared::{fs::{File, Url}, render}; use super::{Backstack, Config, Finder, Mode, Preview}; use crate::folder::Folder; @@ -72,30 +72,28 @@ impl Tab { self.history.remove(url).unwrap_or_else(|| Folder::from(url)) } - pub fn apply_files_attrs(&mut self, just_preview: bool) -> bool { + pub fn apply_files_attrs(&mut self, just_preview: bool) { let apply = |f: &mut Folder| { let hovered = f.hovered().map(|h| h.url()); f.files.set_show_hidden(self.conf.show_hidden); f.files.set_sorter(self.conf.sorter()); - f.files.catchup_revision() | f.repos(hovered) + render!(f.files.catchup_revision()); + render!(f.repos(hovered)); }; - let mut b = false; if let Some(f) = self.current.hovered().filter(|h| h.is_dir()).and_then(|h| self.history.get_mut(&h.url)) { - b |= apply(f); + apply(f); } if just_preview { - return b; + return; } - b |= apply(&mut self.current); + apply(&mut self.current); if let Some(parent) = self.parent.as_mut() { - b |= apply(parent); + apply(parent); } - - b } } diff --git a/yazi-core/src/tasks/commands/arrow.rs b/yazi-core/src/tasks/commands/arrow.rs index a662f5fe..c62059e8 100644 --- a/yazi-core/src/tasks/commands/arrow.rs +++ b/yazi-core/src/tasks/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tasks::Tasks; @@ -14,23 +14,28 @@ impl From<&Exec> for Opt { impl Tasks { #[allow(clippy::should_implement_trait)] - fn next(&mut self) -> bool { + fn next(&mut self) { let limit = Self::limit().min(self.len()); let old = self.cursor; self.cursor = limit.saturating_sub(1).min(self.cursor + 1); - old != self.cursor + render!(old != self.cursor); } - fn prev(&mut self) -> bool { + fn prev(&mut self) { let old = self.cursor; self.cursor = self.cursor.saturating_sub(1); - old != self.cursor + + render!(old != self.cursor); } - pub fn arrow(&mut self, opt: impl Into) -> bool { + pub fn arrow(&mut self, opt: impl Into) { let opt = opt.into() as Opt; - if opt.step > 0 { self.next() } else { self.prev() } + if opt.step > 0 { + self.next(); + } else { + self.prev(); + } } } diff --git a/yazi-core/src/tasks/commands/cancel.rs b/yazi-core/src/tasks/commands/cancel.rs index 6800b175..6dd32977 100644 --- a/yazi-core/src/tasks/commands/cancel.rs +++ b/yazi-core/src/tasks/commands/cancel.rs @@ -1,16 +1,16 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tasks::Tasks; impl Tasks { - pub fn cancel(&mut self, _: &Exec) -> bool { + pub fn cancel(&mut self, _: &Exec) { let id = self.scheduler.running.read().get_id(self.cursor); if id.map(|id| self.scheduler.cancel(id)) != Some(true) { - return false; + return; } let len = self.scheduler.running.read().len(); self.cursor = self.cursor.min(len.saturating_sub(1)); - true + render!(); } } diff --git a/yazi-core/src/tasks/commands/inspect.rs b/yazi-core/src/tasks/commands/inspect.rs index 8c5d1782..7842c975 100644 --- a/yazi-core/src/tasks/commands/inspect.rs +++ b/yazi-core/src/tasks/commands/inspect.rs @@ -8,9 +8,9 @@ use yazi_shared::{event::Exec, term::Term, Defer}; use crate::tasks::Tasks; impl Tasks { - pub fn inspect(&self, _: &Exec) -> bool { + pub fn inspect(&self, _: &Exec) { let Some(id) = self.scheduler.running.read().get_id(self.cursor) else { - return false; + return; }; let scheduler = self.scheduler.clone(); @@ -66,6 +66,5 @@ impl Tasks { stdin.read(&mut quit).await.ok(); } }); - false } } diff --git a/yazi-core/src/tasks/commands/open.rs b/yazi-core/src/tasks/commands/open.rs index 5b831e31..a29d92d8 100644 --- a/yazi-core/src/tasks/commands/open.rs +++ b/yazi-core/src/tasks/commands/open.rs @@ -22,10 +22,9 @@ impl Tasks { emit!(Call(Exec::call("open", vec![]).with_data(Opt { targets, opener }).vec(), Layer::Tasks)); } - pub fn open(&mut self, opt: impl TryInto) -> bool { + pub fn open(&mut self, opt: impl TryInto) { if let Ok(opt) = opt.try_into() { self.file_open_with(&opt.opener, &opt.targets); } - false } } diff --git a/yazi-core/src/tasks/commands/toggle.rs b/yazi-core/src/tasks/commands/toggle.rs index b97c5ba5..57534395 100644 --- a/yazi-core/src/tasks/commands/toggle.rs +++ b/yazi-core/src/tasks/commands/toggle.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::{event::Exec, render}; use crate::tasks::Tasks; @@ -12,8 +12,8 @@ impl From<()> for Opt { } impl Tasks { - pub fn toggle(&mut self, _: impl Into) -> bool { + pub fn toggle(&mut self, _: impl Into) { self.visible = !self.visible; - true + render!(); } } diff --git a/yazi-core/src/tasks/commands/update.rs b/yazi-core/src/tasks/commands/update.rs index 8f3d0f57..0cdcdb13 100644 --- a/yazi-core/src/tasks/commands/update.rs +++ b/yazi-core/src/tasks/commands/update.rs @@ -1,5 +1,5 @@ use anyhow::anyhow; -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Exec, render, Layer}; use crate::tasks::{Tasks, TasksProgress}; @@ -20,12 +20,12 @@ impl Tasks { emit!(Call(Exec::call("update", vec![]).with_data(Opt { progress }).vec(), Layer::Tasks)); } - pub fn update(&mut self, opt: impl TryInto) -> bool { + pub fn update(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { - return false; + return; }; self.progress = opt.progress; - true + render!(); } } diff --git a/yazi-core/src/tasks/tasks.rs b/yazi-core/src/tasks/tasks.rs index e60afd4a..3830f4ad 100644 --- a/yazi-core/src/tasks/tasks.rs +++ b/yazi-core/src/tasks/tasks.rs @@ -77,7 +77,7 @@ impl Tasks { false } - pub fn file_cut(&self, src: &HashSet, dest: &Url, force: bool) -> bool { + pub fn file_cut(&self, src: &HashSet, dest: &Url, force: bool) { for u in src { let to = dest.join(u.file_name().unwrap()); if force && u == &to { @@ -86,10 +86,9 @@ impl Tasks { self.scheduler.file_cut(u.clone(), to, force); } } - false } - pub fn file_copy(&self, src: &HashSet, dest: &Url, force: bool, follow: bool) -> bool { + pub fn file_copy(&self, src: &HashSet, dest: &Url, force: bool, follow: bool) { for u in src { let to = dest.join(u.file_name().unwrap()); if force && u == &to { @@ -98,10 +97,9 @@ impl Tasks { self.scheduler.file_copy(u.clone(), to, force, follow); } } - false } - pub fn file_link(&self, src: &HashSet, dest: &Url, relative: bool, force: bool) -> bool { + pub fn file_link(&self, src: &HashSet, dest: &Url, relative: bool, force: bool) { for u in src { let to = dest.join(u.file_name().unwrap()); if force && *u == to { @@ -110,10 +108,9 @@ impl Tasks { self.scheduler.file_link(u.clone(), to, relative, force); } } - false } - pub fn file_remove(&self, targets: Vec, force: bool, permanently: bool) -> bool { + pub fn file_remove(&self, targets: Vec, force: bool, permanently: bool) { if force { for u in targets { if permanently { @@ -122,7 +119,7 @@ impl Tasks { self.scheduler.file_trash(u); } } - return false; + return; } let scheduler = self.scheduler.clone(); @@ -146,18 +143,11 @@ 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/app/app.rs b/yazi-fm/src/app/app.rs index bb1ca4c3..15059a7b 100644 --- a/yazi-fm/src/app/app.rs +++ b/yazi-fm/src/app/app.rs @@ -1,8 +1,10 @@ +use std::sync::atomic::Ordering; + use anyhow::{Ok, Result}; use crossterm::event::KeyEvent; -use yazi_config::{keymap::Key, ARGS}; +use yazi_config::keymap::Key; use yazi_core::input::InputMode; -use yazi_shared::{emit, event::{Event, Exec}, term::Term, Layer}; +use yazi_shared::{event::{Event, Exec, NEED_RENDER}, term::Term, Layer}; use crate::{lives::Lives, Ctx, Executor, Logs, Panic, Signals}; @@ -16,51 +18,44 @@ impl App { pub(crate) async fn run() -> Result<()> { Panic::install(); let _log = Logs::init()?; - let term = Term::start()?; let signals = Signals::start()?; Lives::register()?; let mut app = Self { cx: Ctx::make(), term: Some(term), signals }; - app.render()?; - while let Some(event) = app.signals.recv().await { - match event { - Event::Quit(no_cwd_file) => { - app.dispatch_quit(no_cwd_file); - break; + + let mut events = Vec::with_capacity(10); + while app.signals.rx.recv_many(&mut events, 10).await > 0 { + for event in events.drain(..) { + match event { + Event::Quit(no_cwd_file) => { + app.quit(no_cwd_file)?; + break; + } + Event::Key(key) => app.dispatch_key(key), + Event::Paste(str) => app.dispatch_paste(str), + Event::Resize(cols, rows) => app.dispatch_resize(cols, rows)?, + Event::Call(exec, layer) => app.dispatch_call(exec, layer), + event => app.dispatch_module(event), } - Event::Key(key) => app.dispatch_key(key), - Event::Paste(str) => app.dispatch_paste(str), - Event::Render(_) => app.render()?, - Event::Resize(cols, rows) => app.dispatch_resize(cols, rows)?, - Event::Call(exec, layer) => app.dispatch_call(exec, layer), - event => app.dispatch_module(event), + } + + if NEED_RENDER.swap(false, Ordering::Relaxed) { + app.render()?; } } Ok(()) } - fn dispatch_quit(&mut self, no_cwd_file: bool) { - if let Some(p) = ARGS.cwd_file.as_ref().filter(|_| !no_cwd_file) { - let cwd = self.cx.manager.cwd().as_os_str(); - std::fs::write(p, cwd.as_encoded_bytes()).ok(); - } - Term::goodbye(|| false); - } - - fn dispatch_key(&mut self, key: KeyEvent) { - let key = Key::from(key); - if Executor::new(self).handle(key) { - emit!(Render); - } - } + #[inline] + fn dispatch_key(&mut self, key: KeyEvent) { Executor::new(self).handle(Key::from(key)); } fn dispatch_paste(&mut self, str: String) { if self.cx.input.visible { let input = &mut self.cx.input; - if input.mode() == InputMode::Insert && input.type_str(&str) { - emit!(Render); + if input.mode() == InputMode::Insert { + input.type_str(&str); } } } @@ -76,9 +71,7 @@ impl App { #[inline] fn dispatch_call(&mut self, exec: Vec, layer: Layer) { - if Executor::new(self).dispatch(&exec, layer) { - emit!(Render); - } + Executor::new(self).dispatch(&exec, layer); } fn dispatch_module(&mut self, event: Event) { diff --git a/yazi-fm/src/app/commands/mod.rs b/yazi-fm/src/app/commands/mod.rs index c12ef5df..f5d96232 100644 --- a/yazi-fm/src/app/commands/mod.rs +++ b/yazi-fm/src/app/commands/mod.rs @@ -1,3 +1,4 @@ mod plugin; +mod quit; mod render; mod stop; diff --git a/yazi-fm/src/app/commands/plugin.rs b/yazi-fm/src/app/commands/plugin.rs index 53a171f2..2a5adcb5 100644 --- a/yazi-fm/src/app/commands/plugin.rs +++ b/yazi-fm/src/app/commands/plugin.rs @@ -6,9 +6,9 @@ use yazi_shared::{emit, event::Exec, Layer}; use crate::{app::App, lives::Lives}; impl App { - pub(crate) fn plugin(&mut self, opt: impl TryInto) -> bool { + pub(crate) fn plugin(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { - return false; + return; }; if !opt.sync { @@ -24,12 +24,11 @@ impl App { emit!(Call(Exec::call("plugin_do", vec![opt.name]).with_data(opt.data).vec(), Layer::App)); } }); - false } - pub(crate) fn plugin_do(&mut self, opt: impl TryInto) -> bool { + pub(crate) fn plugin_do(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { - return false; + return; }; let args = Variadic::from_iter(opt.data.args.into_iter().filter_map(|v| v.into_lua(&LUA).ok())); @@ -51,16 +50,15 @@ impl App { if let Err(e) = ret { error!("{e}"); - return false; + return; } let Some(tx) = opt.data.tx else { - return false; + return; }; if let Ok(v) = ret.and_then(|v| v.try_into().into_lua_err()) { tx.send(v).ok(); } - false } } diff --git a/yazi-fm/src/app/commands/quit.rs b/yazi-fm/src/app/commands/quit.rs new file mode 100644 index 00000000..758f5036 --- /dev/null +++ b/yazi-fm/src/app/commands/quit.rs @@ -0,0 +1,26 @@ +use anyhow::Result; +use yazi_config::ARGS; +use yazi_shared::term::Term; + +use crate::app::App; + +pub struct Opt { + no_cwd_file: bool, +} + +impl From for Opt { + fn from(no_cwd_file: bool) -> Self { Self { no_cwd_file } } +} + +impl App { + pub(crate) fn quit(&mut self, opt: impl Into) -> Result<()> { + let opt = opt.into() as Opt; + + if let Some(p) = ARGS.cwd_file.as_ref().filter(|_| !opt.no_cwd_file) { + let cwd = self.cx.manager.cwd().as_os_str(); + std::fs::write(p, cwd.as_encoded_bytes()).ok(); + } + + Term::goodbye(|| false); + } +} diff --git a/yazi-fm/src/app/commands/render.rs b/yazi-fm/src/app/commands/render.rs index 0e2e3118..38cb5921 100644 --- a/yazi-fm/src/app/commands/render.rs +++ b/yazi-fm/src/app/commands/render.rs @@ -2,9 +2,8 @@ use std::sync::atomic::Ordering; use anyhow::Result; use ratatui::backend::Backend; -use yazi_shared::COLLISION; -use crate::{app::App, lives::Lives, root::Root}; +use crate::{app::App, lives::Lives, root::{Root, COLLISION}}; impl App { pub(crate) fn render(&mut self) -> Result<()> { diff --git a/yazi-fm/src/app/commands/stop.rs b/yazi-fm/src/app/commands/stop.rs index dd78f85e..bffe882c 100644 --- a/yazi-fm/src/app/commands/stop.rs +++ b/yazi-fm/src/app/commands/stop.rs @@ -18,9 +18,9 @@ impl TryFrom<&Exec> for Opt { } impl App { - pub(crate) fn stop(&mut self, opt: impl TryInto) -> bool { + pub(crate) fn stop(&mut self, opt: impl TryInto) { let Ok(opt) = opt.try_into() else { - return false; + return; }; self.cx.manager.active_mut().preview.reset_image(); @@ -38,6 +38,5 @@ impl App { if let Some(tx) = opt.tx { tx.send(()).ok(); } - false } } diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index 17a327d2..dd1b8bce 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,31 +37,30 @@ 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] - pub(super) fn dispatch(&mut self, exec: &[Exec], layer: Layer) -> bool { - let mut render = false; + pub(super) fn dispatch(&mut self, exec: &[Exec], layer: Layer) { for e in exec { - render |= match layer { + match layer { Layer::App => self.app(e), Layer::Manager => self.manager(e), Layer::Tasks => self.tasks(e), @@ -72,10 +71,9 @@ impl<'a> Executor<'a> { Layer::Which => unreachable!(), }; } - render } - fn app(&mut self, exec: &Exec) -> bool { + fn app(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -87,11 +85,9 @@ impl<'a> Executor<'a> { on!(plugin); on!(plugin_do); on!(stop); - - false } - 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,11 +171,11 @@ impl<'a> Executor<'a> { b"tasks_show" => self.app.cx.tasks.toggle(()), // Help b"help" => self.app.cx.help.toggle(Layer::Manager), - _ => false, + _ => {} } } - fn tasks(&mut self, exec: &Exec) -> bool { + fn tasks(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -202,11 +198,11 @@ impl<'a> Executor<'a> { match exec.cmd.as_str() { "help" => self.app.cx.help.toggle(Layer::Tasks), - _ => false, + _ => {} } } - fn select(&mut self, exec: &Exec) -> bool { + fn select(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -221,11 +217,11 @@ impl<'a> Executor<'a> { match exec.cmd.as_str() { "help" => self.app.cx.help.toggle(Layer::Select), - _ => false, + _ => {} } } - fn input(&mut self, exec: &Exec) -> bool { + fn input(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -268,19 +264,17 @@ impl<'a> Executor<'a> { match exec.cmd.as_str() { "help" => self.app.cx.help.toggle(Layer::Input), - _ => false, + _ => {} } } InputMode::Insert => { on!(backspace); on!(kill); - - false } } } - fn help(&mut self, exec: &Exec) -> bool { + fn help(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -295,11 +289,11 @@ impl<'a> Executor<'a> { match exec.cmd.as_str() { "close" => self.app.cx.help.toggle(Layer::Help), - _ => false, + _ => {} } } - fn completion(&mut self, exec: &Exec) -> bool { + fn completion(&mut self, exec: &Exec) { macro_rules! on { ($name:ident) => { if exec.cmd == stringify!($name) { @@ -315,7 +309,7 @@ impl<'a> Executor<'a> { match exec.cmd.as_str() { "help" => self.app.cx.help.toggle(Layer::Completion), - _ => false, + _ => {} } } } diff --git a/yazi-fm/src/root.rs b/yazi-fm/src/root.rs index fbcf106c..12ff2074 100644 --- a/yazi-fm/src/root.rs +++ b/yazi-fm/src/root.rs @@ -1,8 +1,12 @@ +use std::sync::atomic::AtomicBool; + use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, widgets::Widget}; use super::{completion, input, select, tasks, which}; use crate::{components, help, Ctx}; +pub(super) static COLLISION: AtomicBool = AtomicBool::new(false); + pub(super) struct Root<'a> { cx: &'a Ctx, } diff --git a/yazi-fm/src/signals.rs b/yazi-fm/src/signals.rs index 450eeda4..17fdfda1 100644 --- a/yazi-fm/src/signals.rs +++ b/yazi-fm/src/signals.rs @@ -5,8 +5,8 @@ use tokio::{select, sync::{mpsc::{self, UnboundedReceiver, UnboundedSender}, one use yazi_shared::event::Event; pub(super) struct Signals { - tx: UnboundedSender, - rx: UnboundedReceiver, + tx: UnboundedSender, + pub(super) rx: UnboundedReceiver, term_stop_tx: Option>, term_stop_rx: Option>, @@ -27,9 +27,6 @@ impl Signals { Ok(signals) } - #[inline] - pub(super) async fn recv(&mut self) -> Option { self.rx.recv().await } - pub(super) fn stop_term(&mut self, state: bool) { if state == self.term_stop_tx.is_none() { return; diff --git a/yazi-fm/src/widgets/clear.rs b/yazi-fm/src/widgets/clear.rs index ef68110f..013cd5c5 100644 --- a/yazi-fm/src/widgets/clear.rs +++ b/yazi-fm/src/widgets/clear.rs @@ -3,7 +3,8 @@ use std::sync::atomic::Ordering; use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; use yazi_adaptor::ADAPTOR; use yazi_config::LAYOUT; -use yazi_shared::COLLISION; + +use crate::root::COLLISION; pub(crate) struct Clear; diff --git a/yazi-plugin/src/elements/bar.rs b/yazi-plugin/src/elements/bar.rs index d0993787..7a19f55f 100644 --- a/yazi-plugin/src/elements/bar.rs +++ b/yazi-plugin/src/elements/bar.rs @@ -7,9 +7,9 @@ use super::{RectRef, Renderable, Style}; pub struct Bar { area: ratatui::layout::Rect, - position: ratatui::widgets::Borders, - symbol: String, - style: Option, + direction: ratatui::widgets::Borders, + symbol: String, + style: Option, } impl Bar { @@ -18,13 +18,14 @@ impl Bar { Ok(Self { area: *area, - position: Borders::from_bits_truncate(direction), - symbol: Default::default(), - style: Default::default(), + direction: Borders::from_bits_truncate(direction), + symbol: Default::default(), + style: Default::default(), }) })?; let bar = lua.create_table_from([ + // Direction ("NONE", Borders::NONE.bits().into_lua(lua)?), ("TOP", Borders::TOP.bits().into_lua(lua)?), ("RIGHT", Borders::RIGHT.bits().into_lua(lua)?), @@ -68,15 +69,15 @@ impl Renderable for Bar { let symbol = if !self.symbol.is_empty() { &self.symbol - } else if self.position.intersects(Borders::TOP | Borders::BOTTOM) { + } else if self.direction.intersects(Borders::TOP | Borders::BOTTOM) { "─" - } else if self.position.intersects(Borders::LEFT | Borders::RIGHT) { + } else if self.direction.intersects(Borders::LEFT | Borders::RIGHT) { "│" } else { " " }; - if self.position.contains(Borders::LEFT) { + if self.direction.contains(Borders::LEFT) { for y in self.area.top()..self.area.bottom() { let cell = buf.get_mut(self.area.left(), y).set_symbol(symbol); if let Some(style) = self.style { @@ -84,7 +85,7 @@ impl Renderable for Bar { } } } - if self.position.contains(Borders::TOP) { + if self.direction.contains(Borders::TOP) { for x in self.area.left()..self.area.right() { let cell = buf.get_mut(x, self.area.top()).set_symbol(symbol); if let Some(style) = self.style { @@ -92,7 +93,7 @@ impl Renderable for Bar { } } } - if self.position.contains(Borders::RIGHT) { + if self.direction.contains(Borders::RIGHT) { let x = self.area.right() - 1; for y in self.area.top()..self.area.bottom() { let cell = buf.get_mut(x, y).set_symbol(symbol); @@ -101,7 +102,7 @@ impl Renderable for Bar { } } } - if self.position.contains(Borders::BOTTOM) { + if self.direction.contains(Borders::BOTTOM) { let y = self.area.bottom() - 1; for x in self.area.left()..self.area.right() { let cell = buf.get_mut(x, y).set_symbol(symbol); diff --git a/yazi-plugin/src/elements/border.rs b/yazi-plugin/src/elements/border.rs index bbea576c..8c8ddae5 100644 --- a/yazi-plugin/src/elements/border.rs +++ b/yazi-plugin/src/elements/border.rs @@ -1,8 +1,9 @@ use mlua::{AnyUserData, ExternalError, IntoLua, Lua, Table, UserData, Value}; -use ratatui::widgets::Widget; +use ratatui::widgets::{Borders, Widget}; use super::{RectRef, Renderable, Style}; +// Type const PLAIN: u8 = 0; const ROUNDED: u8 = 1; const DOUBLE: u8 = 2; @@ -30,7 +31,14 @@ impl Border { })?; let border = lua.create_table_from([ - // Border type + // Position + ("NONE", Borders::NONE.bits().into_lua(lua)?), + ("TOP", Borders::TOP.bits().into_lua(lua)?), + ("RIGHT", Borders::RIGHT.bits().into_lua(lua)?), + ("BOTTOM", Borders::BOTTOM.bits().into_lua(lua)?), + ("LEFT", Borders::LEFT.bits().into_lua(lua)?), + ("ALL", Borders::ALL.bits().into_lua(lua)?), + // Type ("PLAIN", PLAIN.into_lua(lua)?), ("ROUNDED", ROUNDED.into_lua(lua)?), ("DOUBLE", DOUBLE.into_lua(lua)?), diff --git a/yazi-shared/src/event/event.rs b/yazi-shared/src/event/event.rs index 8df486c4..3a410a4d 100644 --- a/yazi-shared/src/event/event.rs +++ b/yazi-shared/src/event/event.rs @@ -10,7 +10,6 @@ pub enum Event { Quit(bool), // no-cwd-file Key(KeyEvent), Paste(String), - Render(String), Resize(u16, u16), Call(Vec, Layer), @@ -36,9 +35,6 @@ macro_rules! emit { (Quit($no_cwd_file:expr)) => { $crate::event::Event::Quit($no_cwd_file).emit(); }; - (Render) => { - $crate::event::Event::Render(format!("{}:{}", file!(), line!())).emit(); - }; (Call($exec:expr, $layer:expr)) => { $crate::event::Event::Call($exec, $layer).emit(); }; diff --git a/yazi-shared/src/event/mod.rs b/yazi-shared/src/event/mod.rs index b85f499c..643d570c 100644 --- a/yazi-shared/src/event/mod.rs +++ b/yazi-shared/src/event/mod.rs @@ -2,6 +2,8 @@ mod event; mod exec; +mod render; pub use event::*; pub use exec::*; +pub use render::*; diff --git a/yazi-shared/src/event/render.rs b/yazi-shared/src/event/render.rs new file mode 100644 index 00000000..c616f9c5 --- /dev/null +++ b/yazi-shared/src/event/render.rs @@ -0,0 +1,15 @@ +use std::sync::atomic::AtomicBool; + +pub static NEED_RENDER: AtomicBool = AtomicBool::new(false); + +#[macro_export] +macro_rules! render { + () => { + $crate::event::NEED_RENDER.store(true, std::sync::atomic::Ordering::Relaxed); + }; + ($expr:expr) => { + if $expr { + render!(); + } + }; +} diff --git a/yazi-shared/src/lib.rs b/yazi-shared/src/lib.rs index efd304e0..27fb956c 100644 --- a/yazi-shared/src/lib.rs +++ b/yazi-shared/src/lib.rs @@ -30,6 +30,3 @@ pub use number::*; pub use ro_cell::*; pub use throttle::*; pub use time::*; - -// TODO: remove this -pub static COLLISION: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);