From 4a72dea37eeb5710706bbda0b4e3c31861465c87 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 5 Nov 2023 21:12:43 +0800 Subject: [PATCH] .. --- yazi-core/src/completion/commands/arrow.rs | 12 ++++++---- yazi-core/src/completion/commands/close.rs | 10 ++++---- yazi-core/src/completion/commands/show.rs | 2 +- yazi-core/src/completion/commands/trigger.rs | 2 +- yazi-core/src/input/commands/complete.rs | 2 +- yazi-core/src/manager/commands/create.rs | 2 +- yazi-core/src/manager/commands/link.rs | 2 +- yazi-core/src/manager/commands/open.rs | 2 +- yazi-core/src/manager/commands/paste.rs | 2 +- yazi-core/src/manager/commands/quit.rs | 2 +- yazi-core/src/manager/commands/remove.rs | 2 +- yazi-core/src/manager/commands/rename.rs | 2 +- yazi-core/src/manager/commands/tab_close.rs | 2 +- yazi-core/src/manager/commands/tab_create.rs | 2 +- yazi-core/src/manager/commands/tab_swap.rs | 6 ++--- yazi-core/src/manager/commands/tab_switch.rs | 16 ++++++------- yazi-core/src/manager/commands/yank.rs | 2 +- yazi-core/src/tab/commands/arrow.rs | 16 +++++++++---- yazi-core/src/tab/commands/copy.rs | 2 +- yazi-core/src/tab/commands/find.rs | 4 ++-- yazi-core/src/tab/commands/jump.rs | 2 +- yazi-core/src/tab/commands/search.rs | 2 +- yazi-core/src/tab/commands/select.rs | 25 +++++++++++--------- yazi-core/src/tab/commands/shell.rs | 2 +- yazi-core/src/tab/commands/visual_mode.rs | 2 +- 25 files changed, 70 insertions(+), 55 deletions(-) diff --git a/yazi-core/src/completion/commands/arrow.rs b/yazi-core/src/completion/commands/arrow.rs index 735b5e94..c5296585 100644 --- a/yazi-core/src/completion/commands/arrow.rs +++ b/yazi-core/src/completion/commands/arrow.rs @@ -2,10 +2,14 @@ use yazi_config::keymap::Exec; use crate::completion::Completion; -pub struct Opt(isize); +pub struct Opt { + step: isize, +} impl From<&Exec> for Opt { - fn from(e: &Exec) -> Self { Self(e.args.first().and_then(|s| s.parse().ok()).unwrap_or(0)) } + fn from(e: &Exec) -> Self { + Self { step: e.args.first().and_then(|s| s.parse().ok()).unwrap_or(0) } + } } impl Completion { @@ -38,7 +42,7 @@ impl Completion { } pub fn arrow(&mut self, opt: impl Into) -> bool { - let step = opt.into().0; - if step > 0 { self.next(step as usize) } else { self.prev(step.unsigned_abs()) } + 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/completion/commands/close.rs b/yazi-core/src/completion/commands/close.rs index ea3eaa65..84e0d7fa 100644 --- a/yazi-core/src/completion/commands/close.rs +++ b/yazi-core/src/completion/commands/close.rs @@ -2,16 +2,18 @@ use yazi_config::keymap::{Exec, KeymapLayer}; use crate::{completion::Completion, emit}; -pub struct Opt(bool); +pub struct Opt { + submit: bool, +} impl From<&Exec> for Opt { - fn from(e: &Exec) -> Self { Self(e.named.contains_key("submit")) } + fn from(e: &Exec) -> Self { Self { submit: e.named.contains_key("submit") } } } impl Completion { pub fn close(&mut self, opt: impl Into) -> bool { - let submit = opt.into().0; - if submit { + let opt = opt.into() as Opt; + if opt.submit { emit!(Call( Exec::call("complete", vec![self.selected().into()]).with("ticket", self.ticket).vec(), KeymapLayer::Input diff --git a/yazi-core/src/completion/commands/show.rs b/yazi-core/src/completion/commands/show.rs index 204e5ab9..28059b82 100644 --- a/yazi-core/src/completion/commands/show.rs +++ b/yazi-core/src/completion/commands/show.rs @@ -24,7 +24,7 @@ impl<'a> From<&'a Exec> for Opt<'a> { impl Completion { pub fn show<'a>(&mut self, opt: impl Into>) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; if self.ticket != opt.ticket { return false; } diff --git a/yazi-core/src/completion/commands/trigger.rs b/yazi-core/src/completion/commands/trigger.rs index 5ed07e07..23331097 100644 --- a/yazi-core/src/completion/commands/trigger.rs +++ b/yazi-core/src/completion/commands/trigger.rs @@ -29,7 +29,7 @@ impl Completion { } pub fn trigger<'a>(&mut self, opt: impl Into>) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; if opt.ticket < self.ticket { return false; } diff --git a/yazi-core/src/input/commands/complete.rs b/yazi-core/src/input/commands/complete.rs index 83d4c68c..c6d4dd49 100644 --- a/yazi-core/src/input/commands/complete.rs +++ b/yazi-core/src/input/commands/complete.rs @@ -18,7 +18,7 @@ impl<'a> From<&'a Exec> for Opt<'a> { impl Input { pub fn complete<'a>(&mut self, opt: impl Into>) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; if self.ticket != opt.ticket { return false; } diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index 8dd55266..b46099ea 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -16,7 +16,7 @@ impl From<&Exec> for Opt { impl Manager { pub fn create(&self, opt: impl Into) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; let cwd = self.cwd().to_owned(); tokio::spawn(async move { let mut result = emit!(Input(InputOpt::top("Create:"))); diff --git a/yazi-core/src/manager/commands/link.rs b/yazi-core/src/manager/commands/link.rs index 9a452e04..74be120e 100644 --- a/yazi-core/src/manager/commands/link.rs +++ b/yazi-core/src/manager/commands/link.rs @@ -15,7 +15,7 @@ impl From<&Exec> for Opt { impl Manager { pub fn link(&mut self, opt: impl Into, tasks: &Tasks) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; let (cut, ref src) = self.yanked; !cut && 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 1f5f054b..50fca89f 100644 --- a/yazi-core/src/manager/commands/open.rs +++ b/yazi-core/src/manager/commands/open.rs @@ -46,7 +46,7 @@ impl Manager { return false; } - let opt = opt.into(); + let opt = opt.into() as Opt; tokio::spawn(async move { let todo: Vec<_> = files.iter().filter(|(_, m)| m.is_none()).map(|(u, _)| u).collect(); if let Ok(mut mimes) = external::file(&todo).await { diff --git a/yazi-core/src/manager/commands/paste.rs b/yazi-core/src/manager/commands/paste.rs index 93bb07c1..31877e3a 100644 --- a/yazi-core/src/manager/commands/paste.rs +++ b/yazi-core/src/manager/commands/paste.rs @@ -15,7 +15,7 @@ impl Manager { let dest = self.cwd(); let (cut, ref src) = self.yanked; - let opt = opt.into(); + let opt = opt.into() as Opt; if cut { tasks.file_cut(src, dest, opt.force) } else { tasks.file_copy(src, dest, opt.force) } } } diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index 0141ddaf..41304dbb 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -15,7 +15,7 @@ impl From<&Exec> for Opt { impl Manager { pub fn quit(&self, opt: impl Into, tasks: &Tasks) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; let tasks = tasks.len(); if tasks == 0 { diff --git a/yazi-core/src/manager/commands/remove.rs b/yazi-core/src/manager/commands/remove.rs index 2e4ce08f..7f9c4e6b 100644 --- a/yazi-core/src/manager/commands/remove.rs +++ b/yazi-core/src/manager/commands/remove.rs @@ -18,7 +18,7 @@ impl From<&Exec> for Opt { impl Manager { pub fn remove(&mut self, opt: impl Into, tasks: &Tasks) -> bool { - let opt = opt.into(); + 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) } diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index f2a66d23..8c31da33 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -40,7 +40,7 @@ impl Manager { return false; }; - let opt = opt.into(); + let opt = opt.into() as Opt; tokio::spawn(async move { let mut result = emit!(Input( InputOpt::hovered("Rename:").with_value(hovered.file_name().unwrap().to_string_lossy()) diff --git a/yazi-core/src/manager/commands/tab_close.rs b/yazi-core/src/manager/commands/tab_close.rs index 59b3b170..addd3e7c 100644 --- a/yazi-core/src/manager/commands/tab_close.rs +++ b/yazi-core/src/manager/commands/tab_close.rs @@ -18,7 +18,7 @@ impl From for Opt { impl Tabs { pub fn close(&mut self, opt: impl Into) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; let len = self.items.len(); if len < 2 || opt.idx >= len { diff --git a/yazi-core/src/manager/commands/tab_create.rs b/yazi-core/src/manager/commands/tab_create.rs index d629cb75..e125a6c5 100644 --- a/yazi-core/src/manager/commands/tab_create.rs +++ b/yazi-core/src/manager/commands/tab_create.rs @@ -27,7 +27,7 @@ impl Tabs { return false; } - let opt = opt.into(); + let opt = opt.into() as Opt; let url = if opt.current { self.active().current.cwd.to_owned() } else { opt.url.unwrap() }; let mut tab = Tab::from(url); diff --git a/yazi-core/src/manager/commands/tab_swap.rs b/yazi-core/src/manager/commands/tab_swap.rs index 07f06afb..00a52207 100644 --- a/yazi-core/src/manager/commands/tab_swap.rs +++ b/yazi-core/src/manager/commands/tab_swap.rs @@ -3,18 +3,18 @@ use yazi_config::keymap::Exec; use crate::manager::Tabs; pub struct Opt { - idx: isize, + step: isize, } impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { - Self { idx: e.args.first().and_then(|s| s.parse().ok()).unwrap_or(0) } + Self { step: e.args.first().and_then(|s| s.parse().ok()).unwrap_or(0) } } } impl Tabs { pub fn swap(&mut self, opt: impl Into) -> bool { - let idx = self.absolute(opt.into().idx); + let idx = self.absolute(opt.into().step); if idx == self.idx { return false; } diff --git a/yazi-core/src/manager/commands/tab_switch.rs b/yazi-core/src/manager/commands/tab_switch.rs index e16d168e..27c7bafa 100644 --- a/yazi-core/src/manager/commands/tab_switch.rs +++ b/yazi-core/src/manager/commands/tab_switch.rs @@ -3,26 +3,26 @@ use yazi_config::keymap::Exec; use crate::manager::Tabs; pub struct Opt { - idx: isize, - rel: bool, + step: isize, + relative: bool, } impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { Self { - idx: e.args.first().and_then(|s| s.parse().ok()).unwrap_or(0), - rel: e.named.contains_key("relative"), + step: e.args.first().and_then(|s| s.parse().ok()).unwrap_or(0), + relative: e.named.contains_key("relative"), } } } impl Tabs { pub fn switch(&mut self, opt: impl Into) -> bool { - let opt = opt.into(); - let idx = if opt.rel { - (self.idx as isize + opt.idx).rem_euclid(self.items.len() as isize) as usize + 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 } else { - opt.idx as usize + opt.step as usize }; if idx == self.idx || idx >= self.items.len() { diff --git a/yazi-core/src/manager/commands/yank.rs b/yazi-core/src/manager/commands/yank.rs index 6638c2e2..bd43646a 100644 --- a/yazi-core/src/manager/commands/yank.rs +++ b/yazi-core/src/manager/commands/yank.rs @@ -12,7 +12,7 @@ impl From<&Exec> for Opt { impl Manager { pub fn yank(&mut self, opt: impl Into) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; self.yanked.0 = opt.cut; self.yanked.1 = self.selected().into_iter().map(|f| f.url()).collect(); diff --git a/yazi-core/src/tab/commands/arrow.rs b/yazi-core/src/tab/commands/arrow.rs index b46782d9..dd6a8282 100644 --- a/yazi-core/src/tab/commands/arrow.rs +++ b/yazi-core/src/tab/commands/arrow.rs @@ -2,11 +2,13 @@ use yazi_config::keymap::Exec; use crate::{emit, tab::Tab, Step}; -pub struct Opt(Step); +pub struct Opt { + step: Step, +} impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { - Self(e.args.first().and_then(|s| s.parse().ok()).unwrap_or_default()) + Self { step: e.args.first().and_then(|s| s.parse().ok()).unwrap_or_default() } } } @@ -14,13 +16,17 @@ impl From for Opt where T: Into, { - fn from(t: T) -> Self { Self(t.into()) } + fn from(t: T) -> Self { Self { step: t.into() } } } impl Tab { pub fn arrow(&mut self, opt: impl Into) -> bool { - let step = opt.into().0; - let ok = if step.is_positive() { self.current.next(step) } else { self.current.prev(step) }; + let opt = opt.into() as Opt; + let ok = if opt.step.is_positive() { + self.current.next(opt.step) + } else { + self.current.prev(opt.step) + }; if !ok { return false; } diff --git a/yazi-core/src/tab/commands/copy.rs b/yazi-core/src/tab/commands/copy.rs index 59c66c1b..bc864585 100644 --- a/yazi-core/src/tab/commands/copy.rs +++ b/yazi-core/src/tab/commands/copy.rs @@ -14,7 +14,7 @@ impl<'a> From<&'a Exec> for Opt<'a> { impl Tab { pub fn copy<'a>(&self, opt: impl Into>) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; let mut s = OsString::new(); let mut it = self.selected().into_iter().peekable(); diff --git a/yazi-core/src/tab/commands/find.rs b/yazi-core/src/tab/commands/find.rs index 72f4a58e..6aa54e1f 100644 --- a/yazi-core/src/tab/commands/find.rs +++ b/yazi-core/src/tab/commands/find.rs @@ -37,7 +37,7 @@ impl From<&Exec> for ArrowOpt { impl Tab { pub fn find<'a>(&mut self, opt: impl Into>) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; tokio::spawn(async move { let rx = emit!(Input( InputOpt::top(if opt.prev { "Find previous:" } else { "Find next:" }).with_realtime() @@ -61,7 +61,7 @@ impl Tab { } pub fn find_do<'a>(&mut self, opt: impl Into>) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; let Some(query) = opt.query else { return false; }; diff --git a/yazi-core/src/tab/commands/jump.rs b/yazi-core/src/tab/commands/jump.rs index 5ab19743..901a83ba 100644 --- a/yazi-core/src/tab/commands/jump.rs +++ b/yazi-core/src/tab/commands/jump.rs @@ -28,7 +28,7 @@ impl From<&Exec> for Opt { impl Tab { pub fn jump(&self, opt: impl Into) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; if opt.type_ == OptType::None { return false; } diff --git a/yazi-core/src/tab/commands/search.rs b/yazi-core/src/tab/commands/search.rs index 0fe5c633..93acade8 100644 --- a/yazi-core/src/tab/commands/search.rs +++ b/yazi-core/src/tab/commands/search.rs @@ -32,7 +32,7 @@ impl From<&Exec> for Opt { impl Tab { pub fn search(&mut self, opt: impl Into) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; if opt.type_ == OptType::None { return self.search_stop(); } diff --git a/yazi-core/src/tab/commands/select.rs b/yazi-core/src/tab/commands/select.rs index 4637e090..5d7cac87 100644 --- a/yazi-core/src/tab/commands/select.rs +++ b/yazi-core/src/tab/commands/select.rs @@ -2,31 +2,34 @@ use yazi_config::keymap::Exec; use crate::tab::Tab; -pub struct Opt(Option); - -impl From> for Opt { - fn from(b: Option) -> Self { Self(b) } +pub struct Opt { + state: Option, } impl From<&Exec> for Opt { fn from(e: &Exec) -> Self { - Self(match e.named.get("state").map(|s| s.as_bytes()) { - Some(b"true") => Some(true), - Some(b"false") => Some(false), - _ => None, - }) + Self { + state: match e.named.get("state").map(|s| s.as_bytes()) { + Some(b"true") => Some(true), + Some(b"false") => Some(false), + _ => None, + }, + } } } +impl From> for Opt { + fn from(state: Option) -> Self { Self { state } } +} impl Tab { pub fn select(&mut self, opt: impl Into) -> bool { if let Some(u) = self.current.hovered().map(|h| h.url()) { - return self.current.files.select(&u, opt.into().0); + return 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().0) + 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 14f1573f..2fd1ba37 100644 --- a/yazi-core/src/tab/commands/shell.rs +++ b/yazi-core/src/tab/commands/shell.rs @@ -26,7 +26,7 @@ impl Tab { .map(|f| (f.url.as_os_str().to_owned(), Default::default())) .collect(); - let mut opt = opt.into(); + let mut opt = opt.into() as Opt; tokio::spawn(async move { if !opt.confirm || opt.cmd.is_empty() { let mut result = emit!(Input( diff --git a/yazi-core/src/tab/commands/visual_mode.rs b/yazi-core/src/tab/commands/visual_mode.rs index 34dc3e29..15ac386b 100644 --- a/yazi-core/src/tab/commands/visual_mode.rs +++ b/yazi-core/src/tab/commands/visual_mode.rs @@ -14,7 +14,7 @@ impl From<&Exec> for Opt { impl Tab { pub fn visual_mode(&mut self, opt: impl Into) -> bool { - let opt = opt.into(); + let opt = opt.into() as Opt; let idx = self.current.cursor; if opt.unset {