.. [no ci]

This commit is contained in:
sxyazi 2024-01-02 01:33:06 +08:00
parent a54af2e66f
commit faebd78219
No known key found for this signature in database
18 changed files with 73 additions and 74 deletions

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::completion::Completion; use crate::completion::Completion;
@ -13,10 +13,10 @@ impl From<&Exec> for Opt {
} }
impl Completion { impl Completion {
fn next(&mut self, step: usize) -> bool { fn next(&mut self, step: usize) {
let len = self.cands.len(); let len = self.cands.len();
if len == 0 { if len == 0 {
return false; return;
} }
let old = self.cursor; let old = self.cursor;
@ -27,10 +27,10 @@ impl Completion {
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,11 +38,15 @@ impl Completion {
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,4 +1,4 @@
use yazi_shared::{emit, event::Exec, Layer}; use yazi_shared::{emit, event::Exec, render, Layer};
use crate::{completion::Completion, input::Input}; use crate::{completion::Completion, input::Input};
@ -16,7 +16,7 @@ impl Completion {
emit!(Call(Exec::call("close", vec![]).vec(), Layer::Completion)); emit!(Call(Exec::call("close", vec![]).vec(), Layer::Completion));
} }
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 opt.submit { if opt.submit {
Input::_complete(self.selected(), self.ticket); Input::_complete(self.selected(), self.ticket);
@ -24,6 +24,6 @@ impl Completion {
self.caches.clear(); self.caches.clear();
self.visible = false; self.visible = false;
true render!();
} }
} }

View file

@ -1,15 +1,15 @@
use yazi_config::popup::{Offset, Origin, Position}; use yazi_config::popup::{Offset, Origin, Position};
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::{help::Help, input::Input}; use crate::{help::Help, input::Input};
impl Help { impl Help {
pub fn filter(&mut self, _: &Exec) -> bool { pub fn filter(&mut self, _: &Exec) {
let mut input = Input::default(); let mut input = Input::default();
input.position = Position::new(Origin::BottomLeft, Offset::line()); input.position = Position::new(Origin::BottomLeft, Offset::line());
self.in_filter = Some(input); self.in_filter = Some(input);
self.filter_apply(); self.filter_apply();
true render!();
} }
} }

View file

@ -15,7 +15,7 @@ impl From<&Exec> for Opt {
} }
impl Manager { impl Manager {
pub fn create(&self, opt: impl Into<Opt>) -> bool { pub fn create(&self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let cwd = self.cwd().to_owned(); let cwd = self.cwd().to_owned();
tokio::spawn(async move { tokio::spawn(async move {
@ -47,6 +47,5 @@ impl Manager {
} }
Ok::<(), anyhow::Error>(()) Ok::<(), anyhow::Error>(())
}); });
false
} }
} }

View file

@ -14,9 +14,13 @@ impl From<&Exec> for Opt {
} }
impl Manager { impl Manager {
pub fn link(&mut self, opt: impl Into<Opt>, tasks: &Tasks) -> bool { pub fn link(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
let opt = opt.into() as Opt;
let (cut, ref src) = self.yanked; 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);
} }
} }

View file

@ -4,7 +4,7 @@ use tokio::fs;
use tracing::error; use tracing::error;
use yazi_config::{popup::SelectCfg, ARGS, OPEN}; use yazi_config::{popup::SelectCfg, ARGS, OPEN};
use yazi_plugin::isolate; use yazi_plugin::isolate;
use yazi_shared::{emit, event::Exec, fs::{File, Url}, Layer, MIME_DIR}; use yazi_shared::{emit, event::Exec, fs::{File, Url}, render, Layer, MIME_DIR};
use crate::{manager::Manager, select::Select, tasks::Tasks}; use crate::{manager::Manager, select::Select, tasks::Tasks};
@ -20,12 +20,12 @@ impl From<&Exec> for Opt {
} }
impl Manager { impl Manager {
pub fn open(&mut self, opt: impl Into<Opt>, tasks: &Tasks) -> bool { pub fn open(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
let selected = self.selected(); let selected = self.selected();
if selected.is_empty() { if selected.is_empty() {
return false; return;
} else if Self::quit_with_selected(&selected) { } else if Self::quit_with_selected(&selected) {
return false; return;
} }
let (mut done, mut todo) = (Vec::with_capacity(selected.len()), vec![]); let (mut done, mut todo) = (Vec::with_capacity(selected.len()), vec![]);
@ -53,7 +53,6 @@ impl Manager {
Self::_open_do(opt.interactive, done); Self::_open_do(opt.interactive, done);
}); });
false
} }
#[inline] #[inline]
@ -64,10 +63,10 @@ impl Manager {
)); ));
} }
pub fn open_do(&mut self, opt: impl Into<Opt>, tasks: &Tasks) -> bool { pub fn open_do(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let Some(targets) = opt.targets else { let Some(targets) = opt.targets else {
return false; return;
}; };
let targets: Vec<_> = targets let targets: Vec<_> = targets
@ -76,15 +75,15 @@ impl Manager {
.collect(); .collect();
if targets.is_empty() { if targets.is_empty() {
return false; return;
} else if !opt.interactive { } else if !opt.interactive {
tasks.file_open(&targets); tasks.file_open(&targets);
return false; return;
} }
let openers: Vec<_> = OPEN.common_openers(&targets).into_iter().cloned().collect(); let openers: Vec<_> = OPEN.common_openers(&targets).into_iter().cloned().collect();
if openers.is_empty() { if openers.is_empty() {
return false; return;
} }
let urls = targets.into_iter().map(|(u, _)| u).collect(); let urls = targets.into_iter().map(|(u, _)| u).collect();
@ -94,7 +93,6 @@ impl Manager {
Tasks::_open(urls, openers[choice].clone()); Tasks::_open(urls, openers[choice].clone());
} }
}); });
false
} }
fn quit_with_selected(selected: &[&File]) -> bool { fn quit_with_selected(selected: &[&File]) -> bool {

View file

@ -14,15 +14,15 @@ impl From<&Exec> for Opt {
} }
impl Manager { impl Manager {
pub fn paste(&mut self, opt: impl Into<Opt>, tasks: &Tasks) -> bool { pub fn paste(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
let dest = self.cwd(); let dest = self.cwd();
let (cut, ref src) = self.yanked; let (cut, ref src) = self.yanked;
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if cut { if cut {
tasks.file_cut(src, dest, opt.force) tasks.file_cut(src, dest, opt.force);
} else { } else {
tasks.file_copy(src, dest, opt.force, opt.follow) tasks.file_copy(src, dest, opt.force);
} }
} }
} }

View file

@ -17,9 +17,9 @@ impl From<&Exec> for Opt {
} }
impl Manager { impl Manager {
pub fn remove(&mut self, opt: impl Into<Opt>, tasks: &Tasks) -> bool { pub fn remove(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let targets = self.selected().into_iter().map(|f| f.url()).collect(); 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);
} }
} }

View file

@ -29,13 +29,13 @@ impl Manager {
Ok(Self::_hover(Some(new))) Ok(Self::_hover(Some(new)))
} }
pub fn rename(&self, opt: impl Into<Opt>) -> bool { pub fn rename(&self, opt: impl Into<Opt>) {
if self.active().in_selecting() { if self.active().in_selecting() {
return self.bulk_rename(); return self.bulk_rename();
} }
let Some(hovered) = self.hovered().map(|h| h.url()) else { let Some(hovered) = self.hovered().map(|h| h.url()) else {
return false; return;
}; };
let opt = opt.into() as Opt; 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 old: Vec<_> = self.selected().into_iter().map(|f| &f.url).collect();
let root = max_common_root(&old); 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(); let new: Vec<_> = fs::read_to_string(&tmp).await?.lines().map(PathBuf::from).collect();
Self::bulk_rename_do(root, old, new).await Self::bulk_rename_do(root, old, new).await
}); });
false
} }
async fn bulk_rename_do(root: PathBuf, old: Vec<PathBuf>, new: Vec<PathBuf>) -> Result<()> { async fn bulk_rename_do(root: PathBuf, old: Vec<PathBuf>, new: Vec<PathBuf>) -> Result<()> {

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::manager::Manager; use crate::manager::Manager;
@ -11,11 +11,11 @@ impl From<&Exec> for Opt {
} }
impl Manager { impl Manager {
pub fn yank(&mut self, opt: impl Into<Opt>) -> bool { pub fn yank(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
self.yanked.0 = opt.cut; self.yanked.0 = opt.cut;
self.yanked.1 = self.selected().into_iter().map(|f| f.url()).collect(); self.yanked.1 = self.selected().into_iter().map(|f| f.url()).collect();
true render!();
} }
} }

View file

@ -13,7 +13,7 @@ impl<'a> From<&'a Exec> for Opt<'a> {
} }
impl Tab { impl Tab {
pub fn copy<'a>(&self, opt: impl Into<Opt<'a>>) -> bool { pub fn copy<'a>(&self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let mut s = OsString::new(); let mut s = OsString::new();
@ -24,7 +24,7 @@ impl Tab {
"dirname" => f.url.parent().map_or(OsStr::new(""), |p| p.as_os_str()), "dirname" => f.url.parent().map_or(OsStr::new(""), |p| p.as_os_str()),
"filename" => f.name().unwrap_or(OsStr::new("")), "filename" => f.name().unwrap_or(OsStr::new("")),
"name_without_ext" => f.stem().unwrap_or(OsStr::new("")), "name_without_ext" => f.stem().unwrap_or(OsStr::new("")),
_ => return false, _ => return,
}); });
if it.peek().is_some() { if it.peek().is_some() {
s.push("\n"); s.push("\n");
@ -32,6 +32,5 @@ impl Tab {
} }
futures::executor::block_on(CLIPBOARD.set(s)); futures::executor::block_on(CLIPBOARD.set(s));
false
} }
} }

View file

@ -50,7 +50,11 @@ impl Tab {
} }
#[inline] #[inline]
fn escape_search(&mut self) -> bool { self.search_stop() } fn escape_search(&mut self) -> bool {
self.search_stop();
// TODO: render
false
}
pub fn escape(&mut self, opt: impl Into<Opt>) { pub fn escape(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;

View file

@ -1,9 +1,9 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::{manager::Manager, tab::Tab}; use crate::{manager::Manager, tab::Tab};
impl 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()) { self.conf.show_hidden = match e.args.first().map(|s| s.as_bytes()) {
Some(b"show") => true, Some(b"show") => true,
Some(b"hide") => false, Some(b"hide") => false,
@ -11,8 +11,7 @@ impl Tab {
}; };
if self.apply_files_attrs(false) { if self.apply_files_attrs(false) {
Manager::_hover(None); Manager::_hover(None);
return true; render!();
} }
false
} }
} }

View file

@ -1,16 +1,16 @@
use yazi_shared::event::Exec; use yazi_shared::{event::Exec, render};
use crate::tab::Tab; use crate::tab::Tab;
impl Tab { impl Tab {
pub fn linemode(&mut self, e: &Exec) -> bool { pub fn linemode(&mut self, e: &Exec) {
self.conf.patch(|c| { render!(self.conf.patch(|c| {
let Some(mode) = e.args.first() else { let Some(mode) = e.args.first() else {
return; return;
}; };
if !mode.is_empty() && mode.len() <= 20 { if !mode.is_empty() && mode.len() <= 20 {
c.linemode = mode.to_owned(); c.linemode = mode.to_owned();
} }
}) }));
} }
} }

View file

@ -5,7 +5,7 @@ use tokio::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_plugin::external; 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}; use crate::{input::Input, manager::Manager, tab::Tab};
@ -33,7 +33,7 @@ impl From<&Exec> for Opt {
} }
impl Tab { impl Tab {
pub fn search(&mut self, opt: impl Into<Opt>) -> bool { pub fn search(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
if opt.type_ == OptType::None { if opt.type_ == OptType::None {
return self.search_stop(); return self.search_stop();
@ -70,10 +70,11 @@ impl Tab {
} }
Ok(()) 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() { if let Some(handle) = self.search.take() {
handle.abort(); handle.abort();
} }
@ -82,6 +83,5 @@ impl Tab {
drop(mem::replace(&mut self.current, rep)); drop(mem::replace(&mut self.current, rep));
Manager::_refresh(); Manager::_refresh();
} }
false
} }
} }

View file

@ -20,7 +20,7 @@ impl<'a> From<&'a Exec> for Opt {
} }
impl Tab { impl Tab {
pub fn shell(&self, opt: impl Into<Opt>) -> bool { pub fn shell(&self, opt: impl Into<Opt>) {
let mut opt = opt.into() as Opt; let mut opt = opt.into() as Opt;
let selected: Vec<_> = self.selected().into_iter().map(|f| f.url()).collect(); let selected: Vec<_> = self.selected().into_iter().map(|f| f.url()).collect();
@ -42,6 +42,5 @@ impl Tab {
spread: true, spread: true,
}); });
}); });
false
} }
} }

View file

@ -77,7 +77,7 @@ impl Tasks {
false false
} }
pub fn file_cut(&self, src: &HashSet<Url>, dest: &Url, force: bool) -> bool { pub fn file_cut(&self, src: &HashSet<Url>, dest: &Url, force: bool) {
for u in src { for u in src {
let to = dest.join(u.file_name().unwrap()); let to = dest.join(u.file_name().unwrap());
if force && u == &to { if force && u == &to {
@ -86,10 +86,9 @@ impl Tasks {
self.scheduler.file_cut(u.clone(), to, force); self.scheduler.file_cut(u.clone(), to, force);
} }
} }
false
} }
pub fn file_copy(&self, src: &HashSet<Url>, dest: &Url, force: bool, follow: bool) -> bool { pub fn file_copy(&self, src: &HashSet<Url>, dest: &Url, force: bool) {
for u in src { for u in src {
let to = dest.join(u.file_name().unwrap()); let to = dest.join(u.file_name().unwrap());
if force && u == &to { if force && u == &to {
@ -98,10 +97,9 @@ impl Tasks {
self.scheduler.file_copy(u.clone(), to, force, follow); self.scheduler.file_copy(u.clone(), to, force, follow);
} }
} }
false
} }
pub fn file_link(&self, src: &HashSet<Url>, dest: &Url, relative: bool, force: bool) -> bool { pub fn file_link(&self, src: &HashSet<Url>, dest: &Url, relative: bool, force: bool) {
for u in src { for u in src {
let to = dest.join(u.file_name().unwrap()); let to = dest.join(u.file_name().unwrap());
if force && *u == to { if force && *u == to {
@ -110,10 +108,9 @@ impl Tasks {
self.scheduler.file_link(u.clone(), to, relative, force); self.scheduler.file_link(u.clone(), to, relative, force);
} }
} }
false
} }
pub fn file_remove(&self, targets: Vec<Url>, force: bool, permanently: bool) -> bool { pub fn file_remove(&self, targets: Vec<Url>, force: bool, permanently: bool) {
if force { if force {
for u in targets { for u in targets {
if permanently { if permanently {
@ -122,7 +119,7 @@ impl Tasks {
self.scheduler.file_trash(u); self.scheduler.file_trash(u);
} }
} }
return false; return;
} }
let scheduler = self.scheduler.clone(); let scheduler = self.scheduler.clone();
@ -146,7 +143,6 @@ impl Tasks {
} }
} }
}); });
false
} }
pub fn plugin_micro(&self, name: &str) { self.scheduler.plugin_micro(name.to_owned()); } pub fn plugin_micro(&self, name: &str) { self.scheduler.plugin_micro(name.to_owned()); }

View file

@ -289,7 +289,7 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() { match exec.cmd.as_str() {
"close" => self.app.cx.help.toggle(Layer::Help), "close" => self.app.cx.help.toggle(Layer::Help),
_ => false, _ => {}
} }
} }
@ -309,7 +309,7 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() { match exec.cmd.as_str() {
"help" => self.app.cx.help.toggle(Layer::Completion), "help" => self.app.cx.help.toggle(Layer::Completion),
_ => false, _ => {}
} }
} }
} }