This commit is contained in:
sxyazi 2024-01-02 01:21:32 +08:00
parent 159d59a0ea
commit a54af2e66f
No known key found for this signature in database
43 changed files with 199 additions and 201 deletions

View file

@ -1,6 +1,6 @@
use std::{mem, ops::ControlFlow}; use std::{mem, ops::ControlFlow};
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::completion::Completion; use crate::completion::Completion;
@ -54,28 +54,28 @@ impl Completion {
prefixed.into_iter().map(ToOwned::to_owned).collect() prefixed.into_iter().map(ToOwned::to_owned).collect()
} }
pub fn show<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool { pub fn show<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if self.ticket != opt.ticket { if self.ticket != opt.ticket {
return false; return;
} }
if !opt.cache.is_empty() { if !opt.cache.is_empty() {
self.caches.insert(opt.cache_name.to_owned(), opt.cache.clone()); self.caches.insert(opt.cache_name.to_owned(), opt.cache.clone());
} }
let Some(cache) = self.caches.get(opt.cache_name) else { let Some(cache) = self.caches.get(opt.cache_name) else {
return false; return;
}; };
self.ticket = opt.ticket; self.ticket = opt.ticket;
self.cands = Self::match_candidates(opt.word, cache); self.cands = Self::match_candidates(opt.word, cache);
if self.cands.is_empty() { if self.cands.is_empty() {
return mem::replace(&mut self.visible, false); return render!(mem::replace(&mut self.visible, false));
} }
self.offset = 0; self.offset = 0;
self.cursor = 0; self.cursor = 0;
self.visible = true; self.visible = true;
true render!();
} }
} }

View file

@ -1,7 +1,7 @@
use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}}; use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}};
use tokio::fs; use tokio::fs;
use yazi_shared::{emit, event::Exec, Layer}; use yazi_shared::{emit, event::Exec, render, Layer};
use crate::completion::Completion; use crate::completion::Completion;
@ -28,10 +28,10 @@ impl Completion {
)); ));
} }
pub fn trigger<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool { pub fn trigger<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if opt.ticket < self.ticket { if opt.ticket < self.ticket {
return false; return;
} }
self.ticket = opt.ticket; self.ticket = opt.ticket;
@ -76,7 +76,7 @@ impl Completion {
Ok::<(), anyhow::Error>(()) Ok::<(), anyhow::Error>(())
}); });
mem::replace(&mut self.visible, false) render!(mem::replace(&mut self.visible, false));
} }
#[inline] #[inline]

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::help::Help; use crate::help::Help;
@ -17,19 +17,23 @@ impl From<isize> for Opt {
impl Help { impl Help {
#[inline] #[inline]
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool { pub fn arrow(&mut self, opt: impl Into<Opt>) {
let max = self.bindings.len().saturating_sub(1); let max = self.bindings.len().saturating_sub(1);
self.offset = self.offset.min(max); self.offset = self.offset.min(max);
self.cursor = self.cursor.min(max); self.cursor = self.cursor.min(max);
let opt = opt.into() as Opt; 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(); let len = self.bindings.len();
if len == 0 { if len == 0 {
return false; return;
} }
let old = self.cursor; let old = self.cursor;
@ -40,10 +44,10 @@ impl Help {
self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old); 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; let old = self.cursor;
self.cursor = self.cursor.saturating_sub(step); self.cursor = self.cursor.saturating_sub(step);
@ -51,6 +55,6 @@ impl Help {
self.offset = self.offset.saturating_sub(old - self.cursor); self.offset = self.offset.saturating_sub(old - self.cursor);
} }
old != self.cursor render!(old != self.cursor);
} }
} }

View file

@ -1,15 +1,15 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::help::Help; use crate::help::Help;
impl Help { impl Help {
pub fn escape(&mut self, _: &Exec) -> bool { pub fn escape(&mut self, _: &Exec) {
if self.in_filter.is_some() { if self.in_filter.is_none() {
return self.toggle(self.layer);
}
self.in_filter = None; self.in_filter = None;
self.filter_apply(); self.filter_apply();
true render!();
} else {
self.toggle(self.layer)
}
} }
} }

View file

@ -1,7 +1,7 @@
use crossterm::event::KeyCode; use crossterm::event::KeyCode;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use yazi_config::{keymap::{Control, Key}, KEYMAP}; 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 super::HELP_MARGIN;
use crate::input::Input; use crate::input::Input;
@ -24,7 +24,7 @@ impl Help {
#[inline] #[inline]
pub fn limit() -> usize { Term::size().rows.saturating_sub(HELP_MARGIN) as usize } 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.visible = !self.visible;
self.layer = layer; self.layer = layer;
@ -34,7 +34,7 @@ impl Help {
self.offset = 0; self.offset = 0;
self.cursor = 0; self.cursor = 0;
true render!();
} }
pub(super) fn filter_apply(&mut self) -> bool { pub(super) fn filter_apply(&mut self) -> bool {
@ -54,24 +54,23 @@ impl Help {
true true
} }
pub fn type_(&mut self, key: &Key) -> bool { pub fn type_(&mut self, key: &Key) {
let Some(input) = &mut self.in_filter else { let Some(input) = &mut self.in_filter else {
return false; return;
}; };
if key.is_enter() { if key.is_enter() {
self.in_filter = None; self.in_filter = None;
return true; return render!();
} }
let b = match &key { match &key {
Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false } => { Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false } => {
input.backspace(false) input.backspace(false)
} }
_ => input.type_(key), _ => input.type_(key),
}; }
self.filter_apply();
if b { self.filter_apply() } else { false }
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::input::Input; use crate::input::Input;
@ -14,14 +14,14 @@ impl From<bool> for Opt {
} }
impl Input { impl Input {
pub fn backspace(&mut self, opt: impl Into<Opt>) -> bool { pub fn backspace(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let snap = self.snaps.current_mut(); let snap = self.snaps.current_mut();
if !opt.under && snap.cursor < 1 { if !opt.under && snap.cursor < 1 {
return false; return;
} else if opt.under && snap.cursor >= snap.value.len() { } else if opt.under && snap.cursor >= snap.value.len() {
return false; return;
} }
if opt.under { if opt.under {
@ -33,6 +33,6 @@ impl Input {
} }
self.flush_value(); self.flush_value();
true render!();
} }
} }

View file

@ -3,7 +3,7 @@ use yazi_shared::{event::Exec, CharKind};
use crate::input::Input; use crate::input::Input;
impl Input { impl Input {
pub fn backward(&mut self, _: &Exec) -> bool { pub fn backward(&mut self, _: &Exec) {
let snap = self.snap(); let snap = self.snap();
if snap.cursor == 0 { if snap.cursor == 0 {
return self.move_(0); return self.move_(0);
@ -23,6 +23,5 @@ impl Input {
if prev != CharKind::Space { if prev != CharKind::Space {
return self.move_(-(snap.len() as isize)); return self.move_(-(snap.len() as isize));
} }
false
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::{event::Exec, InputError}; use yazi_shared::{event::Exec, render, InputError};
use crate::{completion::Completion, input::Input}; use crate::{completion::Completion, input::Input};
@ -14,7 +14,7 @@ impl From<bool> for Opt {
} }
impl Input { impl Input {
pub fn close(&mut self, opt: impl Into<Opt>) -> bool { pub fn close(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if self.completion { if self.completion {
@ -28,6 +28,6 @@ impl Input {
self.ticket = self.ticket.wrapping_add(1); self.ticket = self.ticket.wrapping_add(1);
self.visible = false; self.visible = false;
true render!();
} }
} }

View file

@ -1,6 +1,6 @@
use std::path::MAIN_SEPARATOR; use std::path::MAIN_SEPARATOR;
use yazi_shared::{emit, event::Exec, Layer}; use yazi_shared::{emit, event::Exec, render, Layer};
use crate::input::Input; use crate::input::Input;
@ -27,10 +27,10 @@ impl Input {
)); ));
} }
pub fn complete<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool { pub fn complete<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if self.ticket != opt.ticket { if self.ticket != opt.ticket {
return false; return;
} }
let [before, after] = self.partition(); let [before, after] = self.partition();
@ -42,7 +42,7 @@ impl Input {
let snap = self.snaps.current_mut(); let snap = self.snaps.current_mut();
if new == snap.value { if new == snap.value {
return false; return;
} }
let delta = new.chars().count() as isize - snap.value.chars().count() as isize; let delta = new.chars().count() as isize - snap.value.chars().count() as isize;
@ -50,6 +50,6 @@ impl Input {
self.move_(delta); self.move_(delta);
self.flush_value(); self.flush_value();
true render!();
} }
} }

View file

@ -14,22 +14,24 @@ impl From<&Exec> for Opt {
} }
impl Input { impl Input {
pub fn delete(&mut self, opt: impl Into<Opt>) -> bool { pub fn delete(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
match self.snap().op { match self.snap().op {
InputOp::None => { InputOp::None => {
self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, self.snap().cursor); self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, self.snap().cursor);
false
} }
InputOp::Select(start) => { InputOp::Select(start) => {
self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, 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(); // TODO: render
todo!();
// return self.handle_op(self.snap().cursor, true).then(||
// self.move_(0)).is_some();
} }
InputOp::Delete(..) => { InputOp::Delete(..) => {
self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, 0); 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, _ => {}
} }
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}}; use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}};
@ -12,7 +12,7 @@ impl From<()> for Opt {
} }
impl Input { impl Input {
pub fn escape(&mut self, _: impl Into<Opt>) -> bool { pub fn escape(&mut self, _: impl Into<Opt>) {
let snap = self.snap_mut(); let snap = self.snap_mut();
match snap.mode { match snap.mode {
InputMode::Normal if snap.op == InputOp::None => { InputMode::Normal if snap.op == InputOp::None => {
@ -31,6 +31,6 @@ impl Input {
} }
} }
self.snaps.tag(self.limit()); self.snaps.tag(self.limit());
true render!();
} }
} }

View file

@ -11,7 +11,7 @@ impl From<&Exec> for Opt {
} }
impl Input { impl Input {
pub fn forward(&mut self, opt: impl Into<Opt>) -> bool { pub fn forward(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let snap = self.snap(); let snap = self.snap();

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::input::{op::InputOp, Input, InputMode}; use crate::input::{op::InputOp, Input, InputMode};
@ -14,13 +14,13 @@ impl From<bool> for Opt {
} }
impl Input { impl Input {
pub fn insert(&mut self, opt: impl Into<Opt>) -> bool { pub fn insert(&mut self, opt: impl Into<Opt>) {
let snap = self.snap_mut(); let snap = self.snap_mut();
if snap.mode == InputMode::Normal { if snap.mode == InputMode::Normal {
snap.op = InputOp::None; snap.op = InputOp::None;
snap.mode = InputMode::Insert; snap.mode = InputMode::Insert;
} else { } else {
return false; return;
} }
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
@ -28,6 +28,6 @@ impl Input {
self.move_(1); self.move_(1);
} }
true render!();
} }
} }

View file

@ -1,6 +1,6 @@
use std::ops::RangeBounds; use std::ops::RangeBounds;
use yazi_shared::{event::Exec, CharKind}; use yazi_shared::{event::Exec, render, CharKind};
use crate::input::Input; use crate::input::Input;
@ -15,7 +15,7 @@ impl<'a> From<&'a Exec> for Opt<'a> {
} }
impl Input { impl Input {
fn kill_range(&mut self, range: impl RangeBounds<usize>) -> bool { fn kill_range(&mut self, range: impl RangeBounds<usize>) {
let snap = self.snap_mut(); let snap = self.snap_mut();
snap.cursor = match range.start_bound() { snap.cursor = match range.start_bound() {
std::ops::Bound::Included(i) => *i, std::ops::Bound::Included(i) => *i,
@ -23,12 +23,12 @@ impl Input {
std::ops::Bound::Unbounded => 0, std::ops::Bound::Unbounded => 0,
}; };
if snap.value.drain(range).next().is_none() { if snap.value.drain(range).next().is_none() {
return false; return;
} }
self.move_(0); self.move_(0);
self.flush_value(); self.flush_value();
true render!();
} }
/// Searches for a word boundary and returns the movement in the cursor /// Searches for a word boundary and returns the movement in the cursor
@ -66,7 +66,7 @@ impl Input {
spaces + count_characters(input.skip(spaces)) spaces + count_characters(input.skip(spaces))
} }
pub fn kill<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool { pub fn kill<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let snap = self.snap_mut(); let snap = self.snap_mut();
@ -89,7 +89,7 @@ impl Input {
let end = start + Self::find_word_boundary(snap.value[start..].chars()); let end = start + Self::find_word_boundary(snap.value[start..].chars());
self.kill_range(start..end) self.kill_range(start..end)
} }
_ => false, _ => {}
} }
} }
} }

View file

@ -1,5 +1,5 @@
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::input::{op::InputOp, snap::InputSnap, Input}; use crate::input::{op::InputOp, snap::InputSnap, Input};
@ -21,22 +21,22 @@ impl From<isize> for Opt {
} }
impl Input { impl Input {
pub fn move_(&mut self, opt: impl Into<Opt>) -> bool { pub fn move_(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let snap = self.snap(); let snap = self.snap();
if opt.in_operating && snap.op == InputOp::None { if opt.in_operating && snap.op == InputOp::None {
return false; return;
} }
let b = self.handle_op( render!(self.handle_op(
if opt.step <= 0 { if opt.step <= 0 {
snap.cursor.saturating_sub(opt.step.unsigned_abs()) snap.cursor.saturating_sub(opt.step.unsigned_abs())
} else { } else {
snap.count().min(snap.cursor + opt.step as usize) snap.count().min(snap.cursor + opt.step as usize)
}, },
false, false,
); ));
let (limit, snap) = (self.limit(), self.snap_mut()); let (limit, snap) = (self.limit(), self.snap_mut());
if snap.offset > snap.cursor { 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); snap.offset = snap.cursor - InputSnap::find_window(&s, 0, limit).end.saturating_sub(delta);
} }
} }
b
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::{input::{op::InputOp, Input}, CLIPBOARD}; use crate::{input::{op::InputOp, Input}, CLIPBOARD};
@ -11,7 +11,7 @@ impl From<&Exec> for Opt {
} }
impl Input { impl Input {
pub fn paste(&mut self, opt: impl Into<Opt>) -> bool { pub fn paste(&mut self, opt: impl Into<Opt>) {
if let Some(start) = self.snap().op.start() { if let Some(start) = self.snap().op.start() {
self.snap_mut().op = InputOp::Delete(false, false, start); self.snap_mut().op = InputOp::Delete(false, false, start);
self.handle_op(self.snap().cursor, true); self.handle_op(self.snap().cursor, true);
@ -19,13 +19,13 @@ impl Input {
let s = futures::executor::block_on(CLIPBOARD.get()); let s = futures::executor::block_on(CLIPBOARD.get());
if s.is_empty() { if s.is_empty() {
return false; return;
} }
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
self.insert(!opt.before); self.insert(!opt.before);
self.type_str(&s.to_string_lossy()); self.type_str(&s.to_string_lossy());
self.escape(()); self.escape(());
true render!();
} }
} }

View file

@ -1,7 +1,9 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::input::Input; use crate::input::Input;
impl Input { impl Input {
pub fn redo(&mut self, _: &Exec) -> bool { self.snaps.redo() } pub fn redo(&mut self, _: &Exec) {
render!(self.snaps.redo());
}
} }

View file

@ -1,7 +1,7 @@
use anyhow::anyhow; use anyhow::anyhow;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use yazi_config::popup::InputCfg; 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; use crate::input::Input;
@ -25,9 +25,9 @@ impl Input {
rx rx
} }
pub fn show(&mut self, opt: impl TryInto<Opt>) -> bool { pub fn show(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else { let Ok(opt) = opt.try_into() else {
return false; return;
}; };
self.close(false); self.close(false);
@ -45,6 +45,6 @@ impl Input {
// Reset snaps // Reset snaps
self.snaps.reset(opt.cfg.value, self.limit()); self.snaps.reset(opt.cfg.value, self.limit());
true render!();
} }
} }

View file

@ -1,5 +1,5 @@
use yazi_config::keymap::Key; use yazi_config::keymap::Key;
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::input::{Input, InputMode}; use crate::input::{Input, InputMode};
@ -10,15 +10,14 @@ impl From<&Exec> for Opt {
} }
impl Input { impl Input {
pub fn type_(&mut self, key: &Key) -> bool { pub fn type_(&mut self, key: &Key) {
if self.mode() != InputMode::Insert { if self.mode() != InputMode::Insert {
return false; return;
} }
if let Some(c) = key.plain() { if let Some(c) = key.plain() {
let mut bits = [0; 4]; let mut bits = [0; 4];
return self.type_str(c.encode_utf8(&mut bits)); render!(self.type_str(c.encode_utf8(&mut bits)));
} }
false
} }
} }

View file

@ -1,15 +1,15 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::input::{Input, InputMode}; use crate::input::{Input, InputMode};
impl Input { impl Input {
pub fn undo(&mut self, _: &Exec) -> bool { pub fn undo(&mut self, _: &Exec) {
if !self.snaps.undo() { if !self.snaps.undo() {
return false; return;
} }
if self.snap().mode == InputMode::Insert { if self.snap().mode == InputMode::Insert {
self.escape(()); self.escape(());
} }
true render!();
} }
} }

View file

@ -1,18 +1,18 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::input::{op::InputOp, Input, InputMode}; use crate::input::{op::InputOp, Input, InputMode};
impl Input { impl Input {
#[inline] #[inline]
pub fn visual(&mut self, _: &Exec) -> bool { pub fn visual(&mut self, _: &Exec) {
let snap = self.snap_mut(); let snap = self.snap_mut();
if snap.mode != InputMode::Normal { if snap.mode != InputMode::Normal {
return false; return;
} else if snap.value.is_empty() { } else if snap.value.is_empty() {
return false; return;
} }
snap.op = InputOp::Select(snap.cursor); snap.op = InputOp::Select(snap.cursor);
true render!();
} }
} }

View file

@ -3,22 +3,23 @@ use yazi_shared::event::Exec;
use crate::input::{op::InputOp, Input}; use crate::input::{op::InputOp, Input};
impl Input { impl Input {
pub fn yank(&mut self, _: &Exec) -> bool { pub fn yank(&mut self, _: &Exec) {
match self.snap().op { match self.snap().op {
InputOp::None => { InputOp::None => {
self.snap_mut().op = InputOp::Yank(self.snap().cursor); self.snap_mut().op = InputOp::Yank(self.snap().cursor);
false
} }
InputOp::Select(start) => { InputOp::Select(start) => {
self.snap_mut().op = InputOp::Yank(start); self.snap_mut().op = InputOp::Yank(start);
return self.handle_op(self.snap().cursor, true).then(|| self.move_(0)).is_some(); // TODO: render
todo!();
// return self.handle_op(self.snap().cursor, true).then(||
// self.move_(0)).is_some();
} }
InputOp::Yank(_) => { InputOp::Yank(_) => {
self.snap_mut().op = InputOp::Yank(0); self.snap_mut().op = InputOp::Yank(0);
self.move_(self.snap().len() as isize); self.move_(self.snap().len() as isize);
false
} }
_ => false, _ => {}
} }
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::select::Select; use crate::select::Select;
@ -13,10 +13,10 @@ impl From<&Exec> for Opt {
} }
impl Select { impl Select {
fn next(&mut self, step: usize) -> bool { fn next(&mut self, step: usize) {
let len = self.items.len(); let len = self.items.len();
if len == 0 { if len == 0 {
return false; return;
} }
let old = self.cursor; let old = self.cursor;
@ -27,10 +27,10 @@ impl Select {
self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old); 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; let old = self.cursor;
self.cursor = self.cursor.saturating_sub(step); self.cursor = self.cursor.saturating_sub(step);
@ -38,10 +38,10 @@ impl Select {
self.offset = self.offset.saturating_sub(old - self.cursor); self.offset = self.offset.saturating_sub(old - self.cursor);
} }
old != self.cursor render!(old != self.cursor);
} }
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool { pub fn arrow(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; 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()) }
} }

View file

@ -1,5 +1,5 @@
use anyhow::anyhow; use anyhow::anyhow;
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::select::Select; use crate::select::Select;
@ -15,7 +15,7 @@ impl From<bool> for Opt {
} }
impl Select { impl Select {
pub fn close(&mut self, opt: impl Into<Opt>) -> bool { pub fn close(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if let Some(cb) = self.callback.take() { if let Some(cb) = self.callback.take() {
_ = cb.send(if opt.submit { Ok(self.cursor) } else { Err(anyhow!("canceled")) }); _ = cb.send(if opt.submit { Ok(self.cursor) } else { Err(anyhow!("canceled")) });
@ -24,6 +24,6 @@ impl Select {
self.cursor = 0; self.cursor = 0;
self.offset = 0; self.offset = 0;
self.visible = false; self.visible = false;
true render!();
} }
} }

View file

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use tokio::sync::oneshot; use tokio::sync::oneshot;
use yazi_config::popup::SelectCfg; 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; use crate::select::Select;
@ -25,9 +25,9 @@ impl Select {
rx.await.unwrap_or_else(|_| Term::goodbye(|| false)) rx.await.unwrap_or_else(|_| Term::goodbye(|| false))
} }
pub fn show(&mut self, opt: impl TryInto<Opt>) -> bool { pub fn show(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else { let Ok(opt) = opt.try_into() else {
return false; return;
}; };
self.close(false); self.close(false);
@ -37,6 +37,6 @@ impl Select {
self.callback = Some(opt.tx); self.callback = Some(opt.tx);
self.visible = true; self.visible = true;
true render!();
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::{manager::Manager, tab::Tab, Step}; use crate::{manager::Manager, tab::Tab, Step};
@ -20,7 +20,7 @@ where
} }
impl Tab { impl Tab {
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool { pub fn arrow(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let ok = if opt.step.is_positive() { let ok = if opt.step.is_positive() {
self.current.next(opt.step) self.current.next(opt.step)
@ -28,7 +28,7 @@ impl Tab {
self.current.prev(opt.step) self.current.prev(opt.step)
}; };
if !ok { if !ok {
return false; return;
} }
// Visual selection // Visual selection
@ -42,6 +42,6 @@ impl Tab {
} }
Manager::_hover(None); Manager::_hover(None);
true render!();
} }
} }

View file

@ -11,17 +11,15 @@ impl From<&Exec> for Opt {
} }
impl Tab { impl Tab {
pub fn back(&mut self, _: impl Into<Opt>) -> bool { pub fn back(&mut self, _: impl Into<Opt>) {
if let Some(url) = self.backstack.shift_backward().cloned() { if let Some(url) = self.backstack.shift_backward().cloned() {
self.cd(url); self.cd(url);
} }
false
} }
pub fn forward(&mut self, _: impl Into<Opt>) -> bool { pub fn forward(&mut self, _: impl Into<Opt>) {
if let Some(url) = self.backstack.shift_forward().cloned() { if let Some(url) = self.backstack.shift_forward().cloned() {
self.cd(url); self.cd(url);
} }
false
} }
} }

View file

@ -3,7 +3,7 @@ use std::{mem, time::Duration};
use tokio::{fs, pin}; use tokio::{fs, pin};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_config::popup::InputCfg; 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}; 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)); emit!(Call(Exec::call("cd", vec![target.to_string()]).vec(), Layer::Manager));
} }
pub fn cd(&mut self, opt: impl Into<Opt>) -> bool { pub fn cd(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if opt.interactive { if opt.interactive {
return self.cd_interactive(); return self.cd_interactive();
} }
if self.current.cwd == opt.target { if self.current.cwd == opt.target {
return false; return;
} }
// Take parent to history // Take parent to history
@ -65,10 +65,10 @@ impl Tab {
} }
Manager::_refresh(); Manager::_refresh();
true render!();
} }
fn cd_interactive(&mut self) -> bool { fn cd_interactive(&mut self) {
tokio::spawn(async move { tokio::spawn(async move {
let rx = Input::_show(InputCfg::cd()); let rx = Input::_show(InputCfg::cd());
@ -96,6 +96,5 @@ impl Tab {
} }
} }
}); });
false
} }
} }

View file

@ -1,6 +1,6 @@
use std::mem; use std::mem;
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::{manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};
@ -13,9 +13,9 @@ impl From<&Exec> for Opt {
} }
impl Tab { impl Tab {
pub fn enter(&mut self, _: impl Into<Opt>) -> bool { pub fn enter(&mut self, _: impl Into<Opt>) {
let Some(hovered) = self.current.hovered().filter(|h| h.is_dir()).map(|h| h.url()) else { let Some(hovered) = self.current.hovered().filter(|h| h.is_dir()).map(|h| h.url()) else {
return false; return;
}; };
// Current // Current
@ -35,6 +35,6 @@ impl Tab {
self.backstack.push(hovered); self.backstack.push(hovered);
Manager::_refresh(); Manager::_refresh();
true render!();
} }
} }

View file

@ -42,7 +42,7 @@ impl Tab {
} }
#[inline] #[inline]
fn escape_select(&mut self) -> bool { self.select_all(Some(false)) } fn escape_select(&mut self) -> bool { self.current.files.select_all(None) }
#[inline] #[inline]
fn escape_filter(&mut self) -> bool { fn escape_filter(&mut self) -> bool {

View file

@ -84,18 +84,16 @@ impl Tab {
render!(); render!();
} }
pub fn find_arrow(&mut self, opt: impl Into<ArrowOpt>) -> bool { pub fn find_arrow(&mut self, opt: impl Into<ArrowOpt>) {
let Some(finder) = &mut self.finder else { let Some(finder) = &mut self.finder else {
return false; return;
}; };
let b = finder.catchup(&self.current.files); render!(finder.catchup(&self.current.files));
let step = if opt.into().prev { if opt.into().prev {
finder.prev(&self.current.files, self.current.cursor, false) finder.prev(&self.current.files, self.current.cursor, false).map(|s| self.arrow(s));
} else { } else {
finder.next(&self.current.files, self.current.cursor, false) finder.next(&self.current.files, self.current.cursor, false).map(|s| self.arrow(s));
}; }
b | step.is_some_and(|s| self.arrow(s))
} }
} }

View file

@ -1,6 +1,6 @@
use std::mem; use std::mem;
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::{manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};
@ -13,7 +13,7 @@ impl From<&Exec> for Opt {
} }
impl Tab { impl Tab {
pub fn leave(&mut self, _: impl Into<Opt>) -> bool { pub fn leave(&mut self, _: impl Into<Opt>) {
let current = self let current = self
.current .current
.hovered() .hovered()
@ -22,7 +22,7 @@ impl Tab {
.or_else(|| self.current.cwd.parent_url()); .or_else(|| self.current.cwd.parent_url());
let Some(current) = current else { let Some(current) = current else {
return false; return;
}; };
// Parent // Parent
@ -44,6 +44,6 @@ impl Tab {
self.backstack.push(current); self.backstack.push(current);
Manager::_refresh(); Manager::_refresh();
true render!();
} }
} }

View file

@ -1,6 +1,6 @@
use anyhow::anyhow; use anyhow::anyhow;
use yazi_plugin::utils::PreviewLock; use yazi_plugin::utils::PreviewLock;
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::tab::Tab; use crate::tab::Tab;
@ -17,20 +17,20 @@ impl TryFrom<&Exec> for Opt {
} }
impl Tab { impl Tab {
pub fn preview(&mut self, opt: impl TryInto<Opt>) -> bool { pub fn preview(&mut self, opt: impl TryInto<Opt>) {
let Some(hovered) = self.current.hovered().map(|h| &h.url) else { 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 { let Ok(opt) = opt.try_into() else {
return false; return;
}; };
if hovered != &opt.lock.url { if hovered != &opt.lock.url {
return false; return;
} }
self.preview.lock = Some(opt.lock); self.preview.lock = Some(opt.lock);
true render!();
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::{emit, event::Exec, fs::{expand_path, File, FilesOp, Url}, Layer}; use yazi_shared::{emit, event::Exec, fs::{expand_path, File, FilesOp, Url}, render, Layer};
use crate::{manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};
@ -26,16 +26,15 @@ impl Tab {
emit!(Call(Exec::call("reveal", vec![target.to_string()]).vec(), Layer::Manager)); emit!(Call(Exec::call("reveal", vec![target.to_string()]).vec(), Layer::Manager));
} }
pub fn reveal(&mut self, opt: impl Into<Opt>) -> bool { pub fn reveal(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let Some(parent) = opt.target.parent_url() else { 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(); FilesOp::Creating(parent, vec![File::from_dummy(opt.target.clone())]).emit();
Manager::_hover(Some(opt.target)); Manager::_hover(Some(opt.target));
b
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::tab::Tab; use crate::tab::Tab;
@ -22,14 +22,13 @@ impl From<Option<bool>> for Opt {
} }
impl Tab { impl Tab {
pub fn select(&mut self, opt: impl Into<Opt>) -> bool { pub fn select(&mut self, opt: impl Into<Opt>) {
if let Some(u) = self.current.hovered().map(|h| h.url()) { 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<Opt>) -> bool { pub fn select_all(&mut self, opt: impl Into<Opt>) {
self.current.files.select_all(opt.into().state) render!(self.current.files.select_all(opt.into().state));
} }
} }

View file

@ -1,6 +1,6 @@
use std::collections::BTreeSet; use std::collections::BTreeSet;
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::tab::{Mode, Tab}; use crate::tab::{Mode, Tab};
@ -13,7 +13,7 @@ impl From<&Exec> for Opt {
} }
impl Tab { impl Tab {
pub fn visual_mode(&mut self, opt: impl Into<Opt>) -> bool { pub fn visual_mode(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let idx = self.current.cursor; let idx = self.current.cursor;
@ -22,6 +22,6 @@ impl Tab {
} else { } else {
self.mode = Mode::Select(idx, BTreeSet::from([idx])); self.mode = Mode::Select(idx, BTreeSet::from([idx]));
}; };
true render!();
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::tasks::Tasks; use crate::tasks::Tasks;
@ -14,23 +14,28 @@ impl From<&Exec> for Opt {
impl Tasks { impl Tasks {
#[allow(clippy::should_implement_trait)] #[allow(clippy::should_implement_trait)]
fn next(&mut self) -> bool { fn next(&mut self) {
let limit = Self::limit().min(self.len()); let limit = Self::limit().min(self.len());
let old = self.cursor; let old = self.cursor;
self.cursor = limit.saturating_sub(1).min(self.cursor + 1); 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; let old = self.cursor;
self.cursor = self.cursor.saturating_sub(1); self.cursor = self.cursor.saturating_sub(1);
old != self.cursor
render!(old != self.cursor);
} }
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool { pub fn arrow(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if opt.step > 0 { self.next() } else { self.prev() } if opt.step > 0 {
self.next();
} else {
self.prev();
}
} }
} }

View file

@ -1,16 +1,16 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::tasks::Tasks; use crate::tasks::Tasks;
impl 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); let id = self.scheduler.running.read().get_id(self.cursor);
if id.map(|id| self.scheduler.cancel(id)) != Some(true) { if id.map(|id| self.scheduler.cancel(id)) != Some(true) {
return false; return;
} }
let len = self.scheduler.running.read().len(); let len = self.scheduler.running.read().len();
self.cursor = self.cursor.min(len.saturating_sub(1)); self.cursor = self.cursor.min(len.saturating_sub(1));
true render!();
} }
} }

View file

@ -8,9 +8,9 @@ use yazi_shared::{event::Exec, term::Term, Defer};
use crate::tasks::Tasks; use crate::tasks::Tasks;
impl 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 { let Some(id) = self.scheduler.running.read().get_id(self.cursor) else {
return false; return;
}; };
let scheduler = self.scheduler.clone(); let scheduler = self.scheduler.clone();
@ -66,6 +66,5 @@ impl Tasks {
stdin.read(&mut quit).await.ok(); stdin.read(&mut quit).await.ok();
} }
}); });
false
} }
} }

View file

@ -22,10 +22,9 @@ impl Tasks {
emit!(Call(Exec::call("open", vec![]).with_data(Opt { targets, opener }).vec(), Layer::Tasks)); emit!(Call(Exec::call("open", vec![]).with_data(Opt { targets, opener }).vec(), Layer::Tasks));
} }
pub fn open(&mut self, opt: impl TryInto<Opt>) -> bool { pub fn open(&mut self, opt: impl TryInto<Opt>) {
if let Ok(opt) = opt.try_into() { if let Ok(opt) = opt.try_into() {
self.file_open_with(&opt.opener, &opt.targets); self.file_open_with(&opt.opener, &opt.targets);
} }
false
} }
} }

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::tasks::Tasks; use crate::tasks::Tasks;
@ -12,8 +12,8 @@ impl From<()> for Opt {
} }
impl Tasks { impl Tasks {
pub fn toggle(&mut self, _: impl Into<Opt>) -> bool { pub fn toggle(&mut self, _: impl Into<Opt>) {
self.visible = !self.visible; self.visible = !self.visible;
true render!();
} }
} }

View file

@ -1,5 +1,5 @@
use anyhow::anyhow; use anyhow::anyhow;
use yazi_shared::{emit, event::Exec, Layer}; use yazi_shared::{emit, event::Exec, render, Layer};
use crate::tasks::{Tasks, TasksProgress}; use crate::tasks::{Tasks, TasksProgress};
@ -20,12 +20,12 @@ impl Tasks {
emit!(Call(Exec::call("update", vec![]).with_data(Opt { progress }).vec(), Layer::Tasks)); emit!(Call(Exec::call("update", vec![]).with_data(Opt { progress }).vec(), Layer::Tasks));
} }
pub fn update(&mut self, opt: impl TryInto<Opt>) -> bool { pub fn update(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else { let Ok(opt) = opt.try_into() else {
return false; return;
}; };
self.progress = opt.progress; self.progress = opt.progress;
true render!();
} }
} }

View file

@ -171,7 +171,7 @@ impl<'a> Executor<'a> {
b"tasks_show" => self.app.cx.tasks.toggle(()), b"tasks_show" => self.app.cx.tasks.toggle(()),
// Help // Help
b"help" => self.app.cx.help.toggle(Layer::Manager), b"help" => self.app.cx.help.toggle(Layer::Manager),
_ => false, _ => {}
} }
} }
@ -198,7 +198,7 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() { match exec.cmd.as_str() {
"help" => self.app.cx.help.toggle(Layer::Tasks), "help" => self.app.cx.help.toggle(Layer::Tasks),
_ => false, _ => {}
} }
} }
@ -217,7 +217,7 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() { match exec.cmd.as_str() {
"help" => self.app.cx.help.toggle(Layer::Select), "help" => self.app.cx.help.toggle(Layer::Select),
_ => false, _ => {}
} }
} }
@ -264,14 +264,12 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() { match exec.cmd.as_str() {
"help" => self.app.cx.help.toggle(Layer::Input), "help" => self.app.cx.help.toggle(Layer::Input),
_ => false, _ => {}
} }
} }
InputMode::Insert => { InputMode::Insert => {
on!(backspace); on!(backspace);
on!(kill); on!(kill);
false
} }
} }
} }