diff --git a/yazi-config/src/keymap/chord.rs b/yazi-config/src/keymap/chord.rs index 596d14b42..b3d6a0d23 100644 --- a/yazi-config/src/keymap/chord.rs +++ b/yazi-config/src/keymap/chord.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, collections::VecDeque, hash::{Hash, Hasher}, sync::OnceLock}; +use std::{borrow::Cow, hash::{Hash, Hasher}, sync::OnceLock}; use regex::Regex; use serde::Deserialize; @@ -53,7 +53,4 @@ impl Chord { || self.run().to_lowercase().contains(&s) || self.on().to_lowercase().contains(&s) } - - #[inline] - pub fn to_seq(&self) -> VecDeque { self.run.iter().map(|c| c.shallow_clone()).collect() } } diff --git a/yazi-config/src/keymap/cow.rs b/yazi-config/src/keymap/cow.rs index cc671d826..62cdc706b 100644 --- a/yazi-config/src/keymap/cow.rs +++ b/yazi-config/src/keymap/cow.rs @@ -1,6 +1,6 @@ use std::{collections::VecDeque, ops::Deref}; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use super::Chord; @@ -10,14 +10,14 @@ pub enum ChordCow { Borrowed(&'static Chord), } -impl From<&'static Chord> for ChordCow { - fn from(c: &'static Chord) -> Self { Self::Borrowed(c) } -} - impl From for ChordCow { fn from(c: Chord) -> Self { Self::Owned(c) } } +impl From<&'static Chord> for ChordCow { + fn from(c: &'static Chord) -> Self { Self::Borrowed(c) } +} + impl Deref for ChordCow { type Target = Chord; @@ -34,10 +34,10 @@ impl Default for ChordCow { } impl ChordCow { - pub fn into_seq(self) -> VecDeque { + pub fn into_seq(self) -> VecDeque { match self { - Self::Owned(c) => c.run.into(), - Self::Borrowed(c) => c.to_seq(), + Self::Owned(c) => c.run.into_iter().map(|c| c.into()).collect(), + Self::Borrowed(c) => c.run.iter().map(|c| c.into()).collect(), } } } diff --git a/yazi-core/src/completion/commands/arrow.rs b/yazi-core/src/completion/commands/arrow.rs index 11dd74be5..da810ec72 100644 --- a/yazi-core/src/completion/commands/arrow.rs +++ b/yazi-core/src/completion/commands/arrow.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::completion::Completion; @@ -7,8 +7,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl Completion { diff --git a/yazi-core/src/completion/commands/close.rs b/yazi-core/src/completion/commands/close.rs index 94d84a54a..fb3f162d1 100644 --- a/yazi-core/src/completion/commands/close.rs +++ b/yazi-core/src/completion/commands/close.rs @@ -1,6 +1,6 @@ use yazi_macro::render; use yazi_proxy::InputProxy; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::completion::Completion; @@ -8,8 +8,8 @@ struct Opt { submit: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { submit: c.bool("submit") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From for Opt { fn from(submit: bool) -> Self { Self { submit } } diff --git a/yazi-core/src/completion/commands/show.rs b/yazi-core/src/completion/commands/show.rs index 68dd5a26f..707b0cb8f 100644 --- a/yazi-core/src/completion/commands/show.rs +++ b/yazi-core/src/completion/commands/show.rs @@ -1,7 +1,7 @@ -use std::{mem, ops::ControlFlow}; +use std::{borrow::Cow, mem, ops::ControlFlow}; use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{Cmd, CmdCow, Data}; use crate::completion::Completion; @@ -9,13 +9,13 @@ const LIMIT: usize = 30; struct Opt { cache: Vec, - cache_name: String, - word: String, + cache_name: Cow<'static, str>, + word: Cow<'static, str>, ticket: usize, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { cache: c.take_any("cache").unwrap_or_default(), cache_name: c.take_str("cache-name").unwrap_or_default(), @@ -25,6 +25,10 @@ impl From for Opt { } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self::from(CmdCow::from(c)) } +} + impl Completion { #[yazi_codegen::command] pub fn show(&mut self, opt: Opt) { @@ -33,9 +37,9 @@ impl Completion { } if !opt.cache.is_empty() { - self.caches.insert(opt.cache_name.to_owned(), opt.cache); + self.caches.insert(opt.cache_name.as_ref().to_owned(), opt.cache); } - let Some(cache) = self.caches.get(&opt.cache_name) else { + let Some(cache) = self.caches.get(opt.cache_name.as_ref()) else { return; }; diff --git a/yazi-core/src/completion/commands/trigger.rs b/yazi-core/src/completion/commands/trigger.rs index 55646f42a..012bd4506 100644 --- a/yazi-core/src/completion/commands/trigger.rs +++ b/yazi-core/src/completion/commands/trigger.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}}; use tokio::fs; use yazi_macro::{emit, render}; -use yazi_shared::{Layer, event::{Cmd, Data}}; +use yazi_shared::{Layer, event::{Cmd, CmdCow, Data}}; use crate::completion::Completion; @@ -13,12 +13,12 @@ const SEPARATOR: [char; 2] = ['/', '\\']; const SEPARATOR: char = std::path::MAIN_SEPARATOR; struct Opt { - word: String, + word: Cow<'static, str>, ticket: usize, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { word: c.take_first_str().unwrap_or_default(), ticket: c.get("ticket").and_then(Data::as_usize).unwrap_or(0), @@ -40,7 +40,7 @@ impl Completion { if self.caches.contains_key(&parent) { return self.show( - Cmd::new("show").with("cache-name", parent).with("word", child).with("ticket", opt.ticket), + Cmd::default().with("cache-name", parent).with("word", child).with("ticket", opt.ticket), ); } diff --git a/yazi-core/src/confirm/commands/arrow.rs b/yazi-core/src/confirm/commands/arrow.rs index 8ce87a660..bdde389b3 100644 --- a/yazi-core/src/confirm/commands/arrow.rs +++ b/yazi-core/src/confirm/commands/arrow.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::{confirm::Confirm, manager::Manager}; @@ -7,8 +7,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl Confirm { diff --git a/yazi-core/src/confirm/commands/close.rs b/yazi-core/src/confirm/commands/close.rs index 8050484a6..c9b52c805 100644 --- a/yazi-core/src/confirm/commands/close.rs +++ b/yazi-core/src/confirm/commands/close.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::confirm::Confirm; @@ -7,8 +7,8 @@ struct Opt { submit: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { submit: c.bool("submit") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From for Opt { fn from(submit: bool) -> Self { Self { submit } } diff --git a/yazi-core/src/confirm/commands/show.rs b/yazi-core/src/confirm/commands/show.rs index 1cde9b8aa..076b498fb 100644 --- a/yazi-core/src/confirm/commands/show.rs +++ b/yazi-core/src/confirm/commands/show.rs @@ -1,7 +1,7 @@ use tokio::sync::oneshot; use yazi_config::popup::ConfirmCfg; use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::confirm::Confirm; @@ -10,10 +10,10 @@ pub struct Opt { tx: oneshot::Sender, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) } } diff --git a/yazi-core/src/help/commands/arrow.rs b/yazi-core/src/help/commands/arrow.rs index b0cc16615..04b389bcf 100644 --- a/yazi-core/src/help/commands/arrow.rs +++ b/yazi-core/src/help/commands/arrow.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::help::Help; @@ -7,8 +7,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl From for Opt { fn from(step: isize) -> Self { Self { step } } diff --git a/yazi-core/src/help/commands/escape.rs b/yazi-core/src/help/commands/escape.rs index 008177076..801d8f8bf 100644 --- a/yazi-core/src/help/commands/escape.rs +++ b/yazi-core/src/help/commands/escape.rs @@ -1,10 +1,10 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::help::Help; impl Help { - pub fn escape(&mut self, _: Cmd) { + pub fn escape(&mut self, _: CmdCow) { if self.keyword().is_none() { return self.toggle(self.layer); } diff --git a/yazi-core/src/help/commands/filter.rs b/yazi-core/src/help/commands/filter.rs index d20c17502..29fcc5405 100644 --- a/yazi-core/src/help/commands/filter.rs +++ b/yazi-core/src/help/commands/filter.rs @@ -1,11 +1,11 @@ use yazi_config::popup::{Offset, Origin, Position}; use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{help::Help, input::Input}; impl Help { - pub fn filter(&mut self, _: Cmd) { + pub fn filter(&mut self, _: CmdCow) { let mut input = Input::default(); input.position = Position::new(Origin::BottomLeft, Offset::line()); diff --git a/yazi-core/src/input/commands/backspace.rs b/yazi-core/src/input/commands/backspace.rs index 972139c9d..89a69d8f3 100644 --- a/yazi-core/src/input/commands/backspace.rs +++ b/yazi-core/src/input/commands/backspace.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::Input; @@ -7,8 +7,8 @@ struct Opt { under: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { under: c.bool("under") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { under: c.bool("under") } } } impl From for Opt { fn from(under: bool) -> Self { Self { under } } diff --git a/yazi-core/src/input/commands/backward.rs b/yazi-core/src/input/commands/backward.rs index a4fb92197..3a69c88bf 100644 --- a/yazi-core/src/input/commands/backward.rs +++ b/yazi-core/src/input/commands/backward.rs @@ -1,9 +1,9 @@ -use yazi_shared::{CharKind, event::Cmd}; +use yazi_shared::{CharKind, event::CmdCow}; use crate::input::Input; impl Input { - pub fn backward(&mut self, _: Cmd) { + pub fn backward(&mut self, _: CmdCow) { let snap = self.snap(); if snap.cursor == 0 { return self.move_(0); diff --git a/yazi-core/src/input/commands/close.rs b/yazi-core/src/input/commands/close.rs index af5f74170..d8e0c45cc 100644 --- a/yazi-core/src/input/commands/close.rs +++ b/yazi-core/src/input/commands/close.rs @@ -1,6 +1,6 @@ use yazi_macro::render; use yazi_proxy::CompletionProxy; -use yazi_shared::{errors::InputError, event::Cmd}; +use yazi_shared::{errors::InputError, event::CmdCow}; use crate::input::Input; @@ -8,8 +8,8 @@ struct Opt { submit: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { submit: c.bool("submit") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From for Opt { fn from(submit: bool) -> Self { Self { submit } } diff --git a/yazi-core/src/input/commands/complete.rs b/yazi-core/src/input/commands/complete.rs index 9c7fab555..0cf3a9cd6 100644 --- a/yazi-core/src/input/commands/complete.rs +++ b/yazi-core/src/input/commands/complete.rs @@ -1,7 +1,7 @@ -use std::path::MAIN_SEPARATOR_STR; +use std::{borrow::Cow, path::MAIN_SEPARATOR_STR}; use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::input::Input; @@ -12,12 +12,12 @@ const SEPARATOR: [char; 2] = ['/', '\\']; const SEPARATOR: char = std::path::MAIN_SEPARATOR; struct Opt { - word: String, + word: Cow<'static, str>, ticket: usize, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { word: c.take_first_str().unwrap_or_default(), ticket: c.get("ticket").and_then(Data::as_usize).unwrap_or(0), diff --git a/yazi-core/src/input/commands/delete.rs b/yazi-core/src/input/commands/delete.rs index b55cf49f5..6b94c44a9 100644 --- a/yazi-core/src/input/commands/delete.rs +++ b/yazi-core/src/input/commands/delete.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, op::InputOp}; @@ -8,8 +8,8 @@ struct Opt { insert: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { cut: c.bool("cut"), insert: c.bool("insert") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { cut: c.bool("cut"), insert: c.bool("insert") } } } impl Input { diff --git a/yazi-core/src/input/commands/escape.rs b/yazi-core/src/input/commands/escape.rs index 41e6e0b75..6c8cbadbc 100644 --- a/yazi-core/src/input/commands/escape.rs +++ b/yazi-core/src/input/commands/escape.rs @@ -1,13 +1,13 @@ use yazi_macro::render; use yazi_proxy::CompletionProxy; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, InputMode, op::InputOp}; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl From<()> for Opt { fn from(_: ()) -> Self { Self } diff --git a/yazi-core/src/input/commands/forward.rs b/yazi-core/src/input/commands/forward.rs index 5d0a9983f..f27b25206 100644 --- a/yazi-core/src/input/commands/forward.rs +++ b/yazi-core/src/input/commands/forward.rs @@ -1,4 +1,4 @@ -use yazi_shared::{CharKind, event::Cmd}; +use yazi_shared::{CharKind, event::CmdCow}; use crate::input::{Input, op::InputOp}; @@ -6,8 +6,8 @@ struct Opt { end_of_word: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { end_of_word: c.bool("end-of-word") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { end_of_word: c.bool("end-of-word") } } } impl Input { diff --git a/yazi-core/src/input/commands/insert.rs b/yazi-core/src/input/commands/insert.rs index 33a5aa90b..23d954bb4 100644 --- a/yazi-core/src/input/commands/insert.rs +++ b/yazi-core/src/input/commands/insert.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, InputMode, op::InputOp}; @@ -7,8 +7,8 @@ struct Opt { append: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { append: c.bool("append") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { append: c.bool("append") } } } impl From for Opt { fn from(append: bool) -> Self { Self { append } } diff --git a/yazi-core/src/input/commands/kill.rs b/yazi-core/src/input/commands/kill.rs index 63cff35d7..3af61ca50 100644 --- a/yazi-core/src/input/commands/kill.rs +++ b/yazi-core/src/input/commands/kill.rs @@ -1,23 +1,23 @@ -use std::ops::RangeBounds; +use std::{borrow::Cow, ops::RangeBounds}; use yazi_macro::render; -use yazi_shared::{CharKind, event::Cmd}; +use yazi_shared::{CharKind, event::CmdCow}; use crate::input::Input; struct Opt { - kind: String, + kind: Cow<'static, str>, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { Self { kind: c.take_first_str().unwrap_or_default() } } +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { kind: c.take_first_str().unwrap_or_default() } } } impl Input { #[yazi_codegen::command] pub fn kill(&mut self, opt: Opt) { let snap = self.snap_mut(); - match opt.kind.as_str() { + match opt.kind.as_ref() { "all" => self.kill_range(..), "bol" => { let end = snap.idx(snap.cursor).unwrap_or(snap.len()); diff --git a/yazi-core/src/input/commands/move_.rs b/yazi-core/src/input/commands/move_.rs index 6000ed519..663319365 100644 --- a/yazi-core/src/input/commands/move_.rs +++ b/yazi-core/src/input/commands/move_.rs @@ -1,6 +1,6 @@ use unicode_width::UnicodeWidthStr; use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::input::{Input, op::InputOp, snap::InputSnap}; @@ -9,8 +9,8 @@ struct Opt { in_operating: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0), in_operating: c.bool("in-operating"), diff --git a/yazi-core/src/input/commands/paste.rs b/yazi-core/src/input/commands/paste.rs index 1a5023348..4e58a8091 100644 --- a/yazi-core/src/input/commands/paste.rs +++ b/yazi-core/src/input/commands/paste.rs @@ -1,6 +1,6 @@ use yazi_macro::render; use yazi_plugin::CLIPBOARD; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, op::InputOp}; @@ -8,8 +8,8 @@ struct Opt { before: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { before: c.bool("before") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { before: c.bool("before") } } } impl Input { diff --git a/yazi-core/src/input/commands/redo.rs b/yazi-core/src/input/commands/redo.rs index 12d8ed230..bab835bd0 100644 --- a/yazi-core/src/input/commands/redo.rs +++ b/yazi-core/src/input/commands/redo.rs @@ -1,10 +1,10 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::Input; impl Input { - pub fn redo(&mut self, _: Cmd) { + pub fn redo(&mut self, _: CmdCow) { render!(self.snaps.redo()); } } diff --git a/yazi-core/src/input/commands/show.rs b/yazi-core/src/input/commands/show.rs index 270d86b46..b3128fe79 100644 --- a/yazi-core/src/input/commands/show.rs +++ b/yazi-core/src/input/commands/show.rs @@ -1,7 +1,7 @@ use tokio::sync::mpsc; use yazi_config::popup::InputCfg; use yazi_macro::render; -use yazi_shared::{errors::InputError, event::Cmd}; +use yazi_shared::{errors::InputError, event::CmdCow}; use crate::input::Input; @@ -10,10 +10,10 @@ pub struct Opt { tx: mpsc::UnboundedSender>, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) } } diff --git a/yazi-core/src/input/commands/type_.rs b/yazi-core/src/input/commands/type_.rs index 9d21f4c87..724889981 100644 --- a/yazi-core/src/input/commands/type_.rs +++ b/yazi-core/src/input/commands/type_.rs @@ -1,12 +1,12 @@ use yazi_config::keymap::Key; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, InputMode}; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl Input { diff --git a/yazi-core/src/input/commands/undo.rs b/yazi-core/src/input/commands/undo.rs index dba619689..54a66f3a7 100644 --- a/yazi-core/src/input/commands/undo.rs +++ b/yazi-core/src/input/commands/undo.rs @@ -1,10 +1,10 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, InputMode}; impl Input { - pub fn undo(&mut self, _: Cmd) { + pub fn undo(&mut self, _: CmdCow) { if !self.snaps.undo() { return; } diff --git a/yazi-core/src/input/commands/visual.rs b/yazi-core/src/input/commands/visual.rs index aff958cd9..120cff8ab 100644 --- a/yazi-core/src/input/commands/visual.rs +++ b/yazi-core/src/input/commands/visual.rs @@ -1,11 +1,11 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, InputMode, op::InputOp}; impl Input { #[inline] - pub fn visual(&mut self, _: Cmd) { + pub fn visual(&mut self, _: CmdCow) { let snap = self.snap_mut(); if snap.mode != InputMode::Normal { return; diff --git a/yazi-core/src/input/commands/yank.rs b/yazi-core/src/input/commands/yank.rs index 9229ff0e6..7f822b9f6 100644 --- a/yazi-core/src/input/commands/yank.rs +++ b/yazi-core/src/input/commands/yank.rs @@ -1,10 +1,10 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::input::{Input, op::InputOp}; impl Input { - pub fn yank(&mut self, _: Cmd) { + pub fn yank(&mut self, _: CmdCow) { match self.snap().op { InputOp::None => { self.snap_mut().op = InputOp::Yank(self.snap().cursor); diff --git a/yazi-core/src/manager/commands/close.rs b/yazi-core/src/manager/commands/close.rs index 78d4000cf..3662cc370 100644 --- a/yazi-core/src/manager/commands/close.rs +++ b/yazi-core/src/manager/commands/close.rs @@ -1,9 +1,9 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{manager::Manager, tasks::Tasks}; impl Manager { - pub fn close(&mut self, _: Cmd, tasks: &Tasks) { + pub fn close(&mut self, _: CmdCow, tasks: &Tasks) { if self.tabs.len() > 1 { return self.tabs.close(self.tabs.cursor); } diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index 812d2f203..1ef423bde 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -4,7 +4,7 @@ use anyhow::Result; use tokio::fs; use yazi_config::popup::{ConfirmCfg, InputCfg}; use yazi_proxy::{ConfirmProxy, InputProxy, TabProxy, WATCHER}; -use yazi_shared::{event::Cmd, fs::{File, FilesOp, Url, UrnBuf, maybe_exists, ok_or_not_found, realname}}; +use yazi_shared::{event::CmdCow, fs::{File, FilesOp, Url, UrnBuf, maybe_exists, ok_or_not_found, realname}}; use crate::manager::Manager; @@ -13,8 +13,8 @@ struct Opt { force: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { dir: c.bool("dir"), force: c.bool("force") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { dir: c.bool("dir"), force: c.bool("force") } } } impl Manager { diff --git a/yazi-core/src/manager/commands/hardlink.rs b/yazi-core/src/manager/commands/hardlink.rs index 687e20a56..1990d9e92 100644 --- a/yazi-core/src/manager/commands/hardlink.rs +++ b/yazi-core/src/manager/commands/hardlink.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{manager::Manager, tasks::Tasks}; @@ -7,8 +7,8 @@ struct Opt { follow: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } } impl Manager { diff --git a/yazi-core/src/manager/commands/hover.rs b/yazi-core/src/manager/commands/hover.rs index 45caad8ea..ef0f7e578 100644 --- a/yazi-core/src/manager/commands/hover.rs +++ b/yazi-core/src/manager/commands/hover.rs @@ -2,7 +2,7 @@ use std::{collections::HashSet, path::PathBuf}; use yazi_dds::Pubsub; use yazi_macro::render; -use yazi_shared::{Id, event::{Cmd, Data}, fs::{Url, Urn}}; +use yazi_shared::{Id, event::{CmdCow, Data}, fs::{Url, Urn}}; use crate::manager::Manager; @@ -11,9 +11,9 @@ struct Opt { tab: Option, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { - Self { url: c.take_first().and_then(Data::into_url), tab: c.get("tab").and_then(Data::as_id) } +impl From for Opt { + fn from(mut c: CmdCow) -> Self { + Self { url: c.take_first_url(), tab: c.get("tab").and_then(Data::as_id) } } } impl From> for Opt { diff --git a/yazi-core/src/manager/commands/link.rs b/yazi-core/src/manager/commands/link.rs index 0e4714380..ae357f307 100644 --- a/yazi-core/src/manager/commands/link.rs +++ b/yazi-core/src/manager/commands/link.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{manager::Manager, tasks::Tasks}; @@ -7,8 +7,8 @@ struct Opt { force: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { relative: c.bool("relative"), force: c.bool("force") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { relative: c.bool("relative"), force: c.bool("force") } } } impl Manager { diff --git a/yazi-core/src/manager/commands/open.rs b/yazi-core/src/manager/commands/open.rs index 630455b55..d318d394e 100644 --- a/yazi-core/src/manager/commands/open.rs +++ b/yazi-core/src/manager/commands/open.rs @@ -7,7 +7,7 @@ use yazi_fs::Folder; use yazi_macro::emit; use yazi_plugin::isolate; use yazi_proxy::{ManagerProxy, TasksProxy, options::OpenDoOpt}; -use yazi_shared::{MIME_DIR, event::{Cmd, EventQuit}, fs::{File, Url}}; +use yazi_shared::{MIME_DIR, event::{CmdCow, EventQuit}, fs::{File, Url}}; use crate::{manager::Manager, tasks::Tasks}; @@ -17,8 +17,8 @@ struct Opt { hovered: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { interactive: c.bool("interactive"), hovered: c.bool("hovered") } } } diff --git a/yazi-core/src/manager/commands/paste.rs b/yazi-core/src/manager/commands/paste.rs index def667ed8..526b3b94d 100644 --- a/yazi-core/src/manager/commands/paste.rs +++ b/yazi-core/src/manager/commands/paste.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{manager::Manager, tasks::Tasks}; @@ -7,8 +7,8 @@ struct Opt { follow: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { force: c.bool("force"), follow: c.bool("follow") } } } impl Manager { diff --git a/yazi-core/src/manager/commands/peek.rs b/yazi-core/src/manager/commands/peek.rs index b127472b6..c967b0be2 100644 --- a/yazi-core/src/manager/commands/peek.rs +++ b/yazi-core/src/manager/commands/peek.rs @@ -1,5 +1,5 @@ use yazi_proxy::HIDER; -use yazi_shared::{event::{Cmd, Data}, fs::Url}; +use yazi_shared::{event::{CmdCow, Data}, fs::Url}; use crate::manager::Manager; @@ -11,12 +11,12 @@ struct Opt { upper_bound: bool, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { skip: c.first().and_then(Data::as_usize), force: c.bool("force"), - only_if: c.take("only-if").and_then(Data::into_url), + only_if: c.take_url("only-if"), upper_bound: c.bool("upper-bound"), } } diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index 51a861183..82fb6c6dc 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -4,7 +4,7 @@ use tokio::{select, time}; use yazi_config::popup::ConfirmCfg; use yazi_macro::emit; use yazi_proxy::ConfirmProxy; -use yazi_shared::event::{Cmd, EventQuit}; +use yazi_shared::event::{CmdCow, EventQuit}; use crate::{manager::Manager, tasks::Tasks}; @@ -15,8 +15,8 @@ struct Opt { impl From<()> for Opt { fn from(_: ()) -> Self { Self::default() } } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { no_cwd_file: c.bool("no-cwd-file") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { no_cwd_file: c.bool("no-cwd-file") } } } impl Manager { diff --git a/yazi-core/src/manager/commands/refresh.rs b/yazi-core/src/manager/commands/refresh.rs index 99b43c99d..8a0ab86d6 100644 --- a/yazi-core/src/manager/commands/refresh.rs +++ b/yazi-core/src/manager/commands/refresh.rs @@ -2,12 +2,12 @@ use std::{env, path::MAIN_SEPARATOR}; use crossterm::{execute, terminal::SetTitle}; use yazi_config::MANAGER; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{manager::Manager, tasks::Tasks}; impl Manager { - pub fn refresh(&mut self, _: Cmd, tasks: &Tasks) { + pub fn refresh(&mut self, _: CmdCow, tasks: &Tasks) { env::set_current_dir(self.cwd()).ok(); env::set_var("PWD", self.cwd()); diff --git a/yazi-core/src/manager/commands/remove.rs b/yazi-core/src/manager/commands/remove.rs index 95bc70051..fd8906558 100644 --- a/yazi-core/src/manager/commands/remove.rs +++ b/yazi-core/src/manager/commands/remove.rs @@ -1,6 +1,6 @@ use yazi_config::popup::ConfirmCfg; use yazi_proxy::{ConfirmProxy, ManagerProxy}; -use yazi_shared::{event::Cmd, fs::Url}; +use yazi_shared::{event::CmdCow, fs::Url}; use crate::{manager::Manager, tasks::Tasks}; @@ -11,8 +11,8 @@ struct Opt { targets: Vec, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { force: c.bool("force"), permanently: c.bool("permanently"), diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index f9e2ceae6..2669aecc4 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -1,23 +1,23 @@ -use std::collections::{HashMap, HashSet}; +use std::{borrow::Cow, collections::{HashMap, HashSet}}; use anyhow::Result; use tokio::fs; use yazi_config::popup::{ConfirmCfg, InputCfg}; use yazi_dds::Pubsub; use yazi_proxy::{ConfirmProxy, InputProxy, TabProxy, WATCHER}; -use yazi_shared::{event::Cmd, fs::{File, FilesOp, Url, UrnBuf, maybe_exists, ok_or_not_found, paths_to_same_file, realname}}; +use yazi_shared::{event::CmdCow, fs::{File, FilesOp, Url, UrnBuf, maybe_exists, ok_or_not_found, paths_to_same_file, realname}}; use crate::manager::Manager; struct Opt { hovered: bool, force: bool, - empty: String, - cursor: String, + empty: Cow<'static, str>, + cursor: Cow<'static, str>, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { hovered: c.bool("hovered"), force: c.bool("force"), @@ -42,7 +42,7 @@ impl Manager { } let name = Self::empty_url_part(&hovered, &opt.empty); - let cursor = match opt.cursor.as_str() { + let cursor = match opt.cursor.as_ref() { "start" => Some(0), "before_ext" => name .chars() diff --git a/yazi-core/src/manager/commands/seek.rs b/yazi-core/src/manager/commands/seek.rs index f4cf1d654..5bd1f4e51 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::{MIME_DIR, event::{Cmd, Data}}; +use yazi_shared::{MIME_DIR, event::{CmdCow, Data}}; use crate::manager::Manager; @@ -9,8 +9,8 @@ struct Opt { units: i16, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { units: c.first().and_then(Data::as_i16).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { units: c.first().and_then(Data::as_i16).unwrap_or(0) } } } impl Manager { diff --git a/yazi-core/src/manager/commands/spot.rs b/yazi-core/src/manager/commands/spot.rs index 662f7b8f0..4ed53ef11 100644 --- a/yazi-core/src/manager/commands/spot.rs +++ b/yazi-core/src/manager/commands/spot.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use yazi_shared::{MIME_DIR, event::{Cmd, Data}}; +use yazi_shared::{MIME_DIR, event::{CmdCow, Data}}; use crate::manager::Manager; @@ -8,8 +8,8 @@ struct Opt { skip: Option, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { skip: c.get("skip").and_then(Data::as_usize) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { skip: c.get("skip").and_then(Data::as_usize) } } } impl Manager { diff --git a/yazi-core/src/manager/commands/suspend.rs b/yazi-core/src/manager/commands/suspend.rs index bd7ab4118..a59939013 100644 --- a/yazi-core/src/manager/commands/suspend.rs +++ b/yazi-core/src/manager/commands/suspend.rs @@ -1,9 +1,9 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::manager::Manager; impl Manager { - pub fn suspend(&mut self, _: Cmd) { + pub fn suspend(&mut self, _: CmdCow) { #[cfg(unix)] unsafe { libc::raise(libc::SIGTSTP); diff --git a/yazi-core/src/manager/commands/tab_close.rs b/yazi-core/src/manager/commands/tab_close.rs index 3f475ac6c..80a6d6939 100644 --- a/yazi-core/src/manager/commands/tab_close.rs +++ b/yazi-core/src/manager/commands/tab_close.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::manager::Tabs; @@ -7,8 +7,8 @@ struct Opt { idx: usize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { idx: c.first().and_then(Data::as_usize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { idx: c.first().and_then(Data::as_usize).unwrap_or(0) } } } impl From for Opt { diff --git a/yazi-core/src/manager/commands/tab_create.rs b/yazi-core/src/manager/commands/tab_create.rs index ed4169b3b..76acc4d77 100644 --- a/yazi-core/src/manager/commands/tab_create.rs +++ b/yazi-core/src/manager/commands/tab_create.rs @@ -1,7 +1,7 @@ use yazi_boot::BOOT; use yazi_macro::render; use yazi_proxy::AppProxy; -use yazi_shared::{event::{Cmd, Data}, fs::Url}; +use yazi_shared::{event::CmdCow, fs::Url}; use crate::{manager::Tabs, tab::Tab}; @@ -12,16 +12,13 @@ struct Opt { current: bool, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { if c.bool("current") { Self { url: Default::default(), current: true } } else { Self { - url: c - .take_first() - .and_then(Data::into_url) - .unwrap_or_else(|| Url::from(&BOOT.cwds[0])), + url: c.take_first_url().unwrap_or_else(|| Url::from(&BOOT.cwds[0])), current: false, } } diff --git a/yazi-core/src/manager/commands/tab_swap.rs b/yazi-core/src/manager/commands/tab_swap.rs index 144397440..932916a93 100644 --- a/yazi-core/src/manager/commands/tab_swap.rs +++ b/yazi-core/src/manager/commands/tab_swap.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::manager::Tabs; @@ -7,8 +7,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl Tabs { diff --git a/yazi-core/src/manager/commands/tab_switch.rs b/yazi-core/src/manager/commands/tab_switch.rs index 7e6bb0c85..09326fc82 100644 --- a/yazi-core/src/manager/commands/tab_switch.rs +++ b/yazi-core/src/manager/commands/tab_switch.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::manager::Tabs; @@ -8,8 +8,8 @@ struct Opt { relative: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0), relative: c.bool("relative") } } } diff --git a/yazi-core/src/manager/commands/unyank.rs b/yazi-core/src/manager/commands/unyank.rs index 135c54564..4956ae607 100644 --- a/yazi-core/src/manager/commands/unyank.rs +++ b/yazi-core/src/manager/commands/unyank.rs @@ -1,12 +1,12 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::manager::Manager; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl From<()> for Opt { fn from(_: ()) -> Self { Self } diff --git a/yazi-core/src/manager/commands/update_files.rs b/yazi-core/src/manager/commands/update_files.rs index b88abb05e..0560a6e15 100644 --- a/yazi-core/src/manager/commands/update_files.rs +++ b/yazi-core/src/manager/commands/update_files.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use yazi_fs::Folder; use yazi_macro::render; use yazi_proxy::ManagerProxy; -use yazi_shared::{event::Cmd, fs::FilesOp}; +use yazi_shared::{event::CmdCow, fs::FilesOp}; use crate::{manager::{LINKED, Manager}, tab::Tab, tasks::Tasks}; @@ -11,10 +11,10 @@ pub struct Opt { op: FilesOp, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { op: c.take_any("op").ok_or(())? }) } } diff --git a/yazi-core/src/manager/commands/update_mimes.rs b/yazi-core/src/manager/commands/update_mimes.rs index dfa2948d5..64fd2026c 100644 --- a/yazi-core/src/manager/commands/update_mimes.rs +++ b/yazi-core/src/manager/commands/update_mimes.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use tracing::error; use yazi_macro::render; -use yazi_shared::{event::Cmd, fs::Url}; +use yazi_shared::{event::CmdCow, fs::Url}; use crate::{manager::{LINKED, Manager}, tasks::Tasks}; @@ -10,11 +10,11 @@ pub struct Opt { updates: HashMap, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { - Ok(Self { updates: c.take("updates").ok_or(())?.into_dict_string() }) + fn try_from(mut c: CmdCow) -> Result { + Ok(Self { updates: c.try_take("updates").ok_or(())?.into_dict_string() }) } } diff --git a/yazi-core/src/manager/commands/update_paged.rs b/yazi-core/src/manager/commands/update_paged.rs index 0dd8128bd..59a0bc2b8 100644 --- a/yazi-core/src/manager/commands/update_paged.rs +++ b/yazi-core/src/manager/commands/update_paged.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::{Cmd, Data}, fs::Url}; +use yazi_shared::{event::{CmdCow, Data}, fs::Url}; use crate::{manager::Manager, tasks::Tasks}; @@ -8,12 +8,9 @@ pub struct Opt { only_if: Option, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { - Self { - page: c.first().and_then(Data::as_usize), - only_if: c.take("only-if").and_then(Data::into_url), - } +impl From for Opt { + fn from(mut c: CmdCow) -> Self { + Self { page: c.first().and_then(Data::as_usize), only_if: c.take_url("only-if") } } } diff --git a/yazi-core/src/manager/commands/update_tasks.rs b/yazi-core/src/manager/commands/update_tasks.rs index caed5e4d3..785be0694 100644 --- a/yazi-core/src/manager/commands/update_tasks.rs +++ b/yazi-core/src/manager/commands/update_tasks.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Cmd, fs::Url}; +use yazi_shared::{event::CmdCow, fs::Url}; use crate::manager::Manager; @@ -6,10 +6,10 @@ pub struct Opt { urls: Vec, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { urls: c.take_any("urls").ok_or(())? }) } } diff --git a/yazi-core/src/manager/commands/update_yanked.rs b/yazi-core/src/manager/commands/update_yanked.rs index adbbeda37..b26a3bd5d 100644 --- a/yazi-core/src/manager/commands/update_yanked.rs +++ b/yazi-core/src/manager/commands/update_yanked.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use yazi_macro::render; -use yazi_shared::{event::Cmd, fs::Url}; +use yazi_shared::{event::CmdCow, fs::Url}; use crate::manager::{Manager, Yanked}; @@ -11,10 +11,10 @@ pub struct Opt { urls: HashSet, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { if let Some(iter) = c.take_any::("urls") { Ok(Self { urls: iter.urls.into_iter().collect(), cut: iter.cut }) } else { diff --git a/yazi-core/src/manager/commands/yank.rs b/yazi-core/src/manager/commands/yank.rs index 5da6cbc3b..68d947258 100644 --- a/yazi-core/src/manager/commands/yank.rs +++ b/yazi-core/src/manager/commands/yank.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::manager::{Manager, Yanked}; @@ -7,8 +7,8 @@ struct Opt { cut: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { cut: c.bool("cut") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { cut: c.bool("cut") } } } impl Manager { diff --git a/yazi-core/src/notify/commands/tick.rs b/yazi-core/src/notify/commands/tick.rs index 0ab133f58..c7b19ae55 100644 --- a/yazi-core/src/notify/commands/tick.rs +++ b/yazi-core/src/notify/commands/tick.rs @@ -2,7 +2,7 @@ use std::time::Duration; use ratatui::layout::Rect; use yazi_macro::emit; -use yazi_shared::{Layer, event::{Cmd, Data}}; +use yazi_shared::{Layer, event::{Cmd, CmdCow, Data}}; use crate::notify::Notify; @@ -10,10 +10,10 @@ pub struct Opt { interval: Duration, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(c: Cmd) -> Result { + fn try_from(c: CmdCow) -> Result { let interval = c.first().and_then(Data::as_f64).ok_or(())?; if interval < 0.0 { return Err(()); @@ -23,6 +23,12 @@ impl TryFrom for Opt { } } +impl TryFrom for Opt { + type Error = (); + + fn try_from(c: Cmd) -> Result { Self::try_from(CmdCow::from(c)) } +} + impl Notify { pub fn tick(&mut self, opt: impl TryInto, area: Rect) { self.tick_handle.take().map(|h| h.abort()); diff --git a/yazi-core/src/pick/commands/arrow.rs b/yazi-core/src/pick/commands/arrow.rs index e78883e85..191837f87 100644 --- a/yazi-core/src/pick/commands/arrow.rs +++ b/yazi-core/src/pick/commands/arrow.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::pick::Pick; @@ -7,8 +7,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl Pick { diff --git a/yazi-core/src/pick/commands/close.rs b/yazi-core/src/pick/commands/close.rs index cd684345c..b63334238 100644 --- a/yazi-core/src/pick/commands/close.rs +++ b/yazi-core/src/pick/commands/close.rs @@ -1,6 +1,6 @@ use anyhow::anyhow; use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::pick::Pick; @@ -8,8 +8,8 @@ struct Opt { submit: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { submit: c.bool("submit") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { submit: c.bool("submit") } } } impl From for Opt { fn from(submit: bool) -> Self { Self { submit } } diff --git a/yazi-core/src/pick/commands/show.rs b/yazi-core/src/pick/commands/show.rs index dc24fefed..c177acd95 100644 --- a/yazi-core/src/pick/commands/show.rs +++ b/yazi-core/src/pick/commands/show.rs @@ -1,7 +1,7 @@ use tokio::sync::oneshot; use yazi_config::popup::PickCfg; use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::pick::Pick; @@ -10,10 +10,10 @@ pub struct Opt { tx: oneshot::Sender>, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { cfg: c.take_any("cfg").ok_or(())?, tx: c.take_any("tx").ok_or(())? }) } } diff --git a/yazi-core/src/spot/commands/arrow.rs b/yazi-core/src/spot/commands/arrow.rs index f815c12b3..be704adee 100644 --- a/yazi-core/src/spot/commands/arrow.rs +++ b/yazi-core/src/spot/commands/arrow.rs @@ -1,6 +1,6 @@ use yazi_macro::render; use yazi_proxy::ManagerProxy; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::spot::Spot; @@ -8,8 +8,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl Spot { diff --git a/yazi-core/src/spot/commands/close.rs b/yazi-core/src/spot/commands/close.rs index 8a73c299a..31b403b67 100644 --- a/yazi-core/src/spot/commands/close.rs +++ b/yazi-core/src/spot/commands/close.rs @@ -1,12 +1,12 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::spot::Spot; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl From<()> for Opt { fn from(_: ()) -> Self { Self } diff --git a/yazi-core/src/spot/commands/copy.rs b/yazi-core/src/spot/commands/copy.rs index 6d01d8a7b..a1615ca55 100644 --- a/yazi-core/src/spot/commands/copy.rs +++ b/yazi-core/src/spot/commands/copy.rs @@ -1,14 +1,16 @@ +use std::borrow::Cow; + use yazi_plugin::CLIPBOARD; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::spot::Spot; struct Opt { - type_: String, + type_: Cow<'static, str>, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { Self { type_: c.take_first_str().unwrap_or_default() } } +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { type_: c.take_first_str().unwrap_or_default() } } } impl Spot { @@ -18,7 +20,7 @@ impl Spot { let Some(table) = lock.table() else { return }; let mut s = String::new(); - match opt.type_.as_str() { + match opt.type_.as_ref() { "cell" => { let Some(cell) = table.selected_cell() else { return }; s = cell.to_string(); diff --git a/yazi-core/src/spot/commands/swipe.rs b/yazi-core/src/spot/commands/swipe.rs index 420d16791..f956cb38d 100644 --- a/yazi-core/src/spot/commands/swipe.rs +++ b/yazi-core/src/spot/commands/swipe.rs @@ -1,5 +1,5 @@ use yazi_proxy::{ManagerProxy, TabProxy}; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::spot::Spot; @@ -7,8 +7,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl Spot { diff --git a/yazi-core/src/tab/commands/arrow.rs b/yazi-core/src/tab/commands/arrow.rs index c635d4490..10a33ee4f 100644 --- a/yazi-core/src/tab/commands/arrow.rs +++ b/yazi-core/src/tab/commands/arrow.rs @@ -1,7 +1,7 @@ use yazi_fs::Step; use yazi_macro::render; use yazi_proxy::ManagerProxy; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::tab::Tab; @@ -9,10 +9,10 @@ struct Opt { step: Step, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { - let step = match c.take_first() { - Some(Data::Integer(i)) => Step::from(i as isize), +impl From for Opt { + fn from(c: CmdCow) -> Self { + let step = match c.first() { + Some(Data::Integer(i)) => Step::from(*i as isize), Some(Data::String(s)) => s.parse().unwrap_or_default(), _ => Step::default(), }; diff --git a/yazi-core/src/tab/commands/back.rs b/yazi-core/src/tab/commands/back.rs index 3aec0be25..15f3e1466 100644 --- a/yazi-core/src/tab/commands/back.rs +++ b/yazi-core/src/tab/commands/back.rs @@ -1,7 +1,9 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; impl Tab { - pub fn back(&mut self, _: Cmd) { self.backstack.shift_backward().cloned().map(|u| self.cd(u)); } + pub fn back(&mut self, _: CmdCow) { + self.backstack.shift_backward().cloned().map(|u| self.cd(u)); + } } diff --git a/yazi-core/src/tab/commands/cd.rs b/yazi-core/src/tab/commands/cd.rs index 69b59e29f..d734dd42e 100644 --- a/yazi-core/src/tab/commands/cd.rs +++ b/yazi-core/src/tab/commands/cd.rs @@ -6,7 +6,7 @@ use yazi_config::popup::InputCfg; use yazi_dds::Pubsub; use yazi_macro::render; use yazi_proxy::{CompletionProxy, InputProxy, ManagerProxy, TabProxy}; -use yazi_shared::{Debounce, errors::InputError, event::{Cmd, Data}, fs::{Url, expand_path}}; +use yazi_shared::{Debounce, errors::InputError, event::CmdCow, fs::{Url, expand_path}}; use crate::tab::Tab; @@ -15,11 +15,11 @@ struct Opt { interactive: bool, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { interactive: c.bool("interactive"), - ..Self::from(c.take_first().and_then(Data::into_url).unwrap_or_default()) + ..Self::from(c.take_first_url().unwrap_or_default()) } } } diff --git a/yazi-core/src/tab/commands/copy.rs b/yazi-core/src/tab/commands/copy.rs index 806845f79..49168d104 100644 --- a/yazi-core/src/tab/commands/copy.rs +++ b/yazi-core/src/tab/commands/copy.rs @@ -1,17 +1,17 @@ use std::{borrow::Cow, ffi::{OsStr, OsString}, path::Path}; use yazi_plugin::CLIPBOARD; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; struct Opt { - type_: String, + type_: Cow<'static, str>, separator: Separator, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { type_: c.take_first_str().unwrap_or_default(), separator: c.str("separator").unwrap_or_default().into(), @@ -29,7 +29,7 @@ impl Tab { let mut s = OsString::new(); let mut it = self.selected_or_hovered(true).peekable(); while let Some(u) = it.next() { - s.push(match opt.type_.as_str() { + s.push(match opt.type_.as_ref() { "path" => opt.separator.transform(u), "dirname" => opt.separator.transform(u.parent().unwrap_or(Path::new(""))), "filename" => opt.separator.transform(u.name()), diff --git a/yazi-core/src/tab/commands/enter.rs b/yazi-core/src/tab/commands/enter.rs index 57aba094b..751e3a9c6 100644 --- a/yazi-core/src/tab/commands/enter.rs +++ b/yazi-core/src/tab/commands/enter.rs @@ -1,9 +1,9 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; impl Tab { - pub fn enter(&mut self, _: Cmd) { + pub fn enter(&mut self, _: CmdCow) { self.hovered().filter(|h| h.is_dir()).map(|h| h.url.to_regular()).map(|u| self.cd(u)); } } diff --git a/yazi-core/src/tab/commands/escape.rs b/yazi-core/src/tab/commands/escape.rs index ce43851a7..a1ae415ef 100644 --- a/yazi-core/src/tab/commands/escape.rs +++ b/yazi-core/src/tab/commands/escape.rs @@ -1,7 +1,7 @@ use bitflags::bitflags; use yazi_macro::{render, render_and}; use yazi_proxy::{AppProxy, ManagerProxy}; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; @@ -15,8 +15,8 @@ bitflags! { } } -impl From for Opt { - fn from(c: Cmd) -> Self { +impl From for Opt { + fn from(c: CmdCow) -> Self { c.args.iter().fold(Opt::empty(), |acc, (k, v)| { match (k.as_str(), v.as_bool().unwrap_or(false)) { ("all", true) => Self::all(), diff --git a/yazi-core/src/tab/commands/filter.rs b/yazi-core/src/tab/commands/filter.rs index 3cb551b9d..9fa2027b4 100644 --- a/yazi-core/src/tab/commands/filter.rs +++ b/yazi-core/src/tab/commands/filter.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{borrow::Cow, time::Duration}; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; @@ -6,22 +6,22 @@ use yazi_config::popup::InputCfg; use yazi_fs::FilterCase; use yazi_macro::emit; use yazi_proxy::InputProxy; -use yazi_shared::{Debounce, Layer, errors::InputError, event::Cmd}; +use yazi_shared::{Debounce, Layer, errors::InputError, event::{Cmd, CmdCow}}; use crate::tab::Tab; #[derive(Default)] pub(super) struct Opt { - pub query: String, + pub query: Cow<'static, str>, pub case: FilterCase, pub done: bool, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { query: c.take_first_str().unwrap_or_default(), - case: FilterCase::from(&c), + case: FilterCase::from(&*c), done: c.bool("done"), } } diff --git a/yazi-core/src/tab/commands/find.rs b/yazi-core/src/tab/commands/find.rs index d06266e36..2c6d82e8d 100644 --- a/yazi-core/src/tab/commands/find.rs +++ b/yazi-core/src/tab/commands/find.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{borrow::Cow, time::Duration}; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; @@ -6,19 +6,19 @@ use yazi_config::popup::InputCfg; use yazi_fs::FilterCase; use yazi_macro::emit; use yazi_proxy::InputProxy; -use yazi_shared::{Debounce, Layer, errors::InputError, event::Cmd}; +use yazi_shared::{Debounce, Layer, errors::InputError, event::{Cmd, CmdCow}}; use crate::tab::Tab; pub(super) struct Opt { - pub(super) query: Option, + pub(super) query: Option>, pub(super) prev: bool, pub(super) case: FilterCase, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { - Self { query: c.take_first_str(), prev: c.bool("previous"), case: FilterCase::from(&c) } +impl From for Opt { + fn from(mut c: CmdCow) -> Self { + Self { query: c.take_first_str(), prev: c.bool("previous"), case: FilterCase::from(&*c) } } } diff --git a/yazi-core/src/tab/commands/find_arrow.rs b/yazi-core/src/tab/commands/find_arrow.rs index bdbb2739a..cc621ad39 100644 --- a/yazi-core/src/tab/commands/find_arrow.rs +++ b/yazi-core/src/tab/commands/find_arrow.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; @@ -7,8 +7,8 @@ struct Opt { prev: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { prev: c.bool("previous") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { prev: c.bool("previous") } } } impl Tab { diff --git a/yazi-core/src/tab/commands/forward.rs b/yazi-core/src/tab/commands/forward.rs index 87bc5057e..e66789652 100644 --- a/yazi-core/src/tab/commands/forward.rs +++ b/yazi-core/src/tab/commands/forward.rs @@ -1,7 +1,9 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; impl Tab { - pub fn forward(&mut self, _: Cmd) { self.backstack.shift_forward().cloned().map(|u| self.cd(u)); } + pub fn forward(&mut self, _: CmdCow) { + self.backstack.shift_forward().cloned().map(|u| self.cd(u)); + } } diff --git a/yazi-core/src/tab/commands/hidden.rs b/yazi-core/src/tab/commands/hidden.rs index fc1fa651b..ea9630c2b 100644 --- a/yazi-core/src/tab/commands/hidden.rs +++ b/yazi-core/src/tab/commands/hidden.rs @@ -1,10 +1,10 @@ use yazi_proxy::ManagerProxy; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; impl Tab { - pub fn hidden(&mut self, mut c: Cmd) { + pub fn hidden(&mut self, mut c: CmdCow) { self.pref.show_hidden = match c.take_first_str().as_deref() { Some("show") => true, Some("hide") => false, diff --git a/yazi-core/src/tab/commands/leave.rs b/yazi-core/src/tab/commands/leave.rs index ccb9764c3..993578d5b 100644 --- a/yazi-core/src/tab/commands/leave.rs +++ b/yazi-core/src/tab/commands/leave.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; @@ -6,8 +6,8 @@ struct Opt; impl From<()> for Opt { fn from(_: ()) -> Self { Self } } -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl Tab { diff --git a/yazi-core/src/tab/commands/linemode.rs b/yazi-core/src/tab/commands/linemode.rs index 736020fc8..18e6de9db 100644 --- a/yazi-core/src/tab/commands/linemode.rs +++ b/yazi-core/src/tab/commands/linemode.rs @@ -1,16 +1,16 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; impl Tab { - pub fn linemode(&mut self, mut c: Cmd) { + pub fn linemode(&mut self, mut c: CmdCow) { render!(self.pref.patch(|new| { let Some(mode) = c.take_first_str() else { return; }; if !mode.is_empty() && mode.len() <= 20 { - new.linemode = mode; + new.linemode = mode.into_owned(); } })); } diff --git a/yazi-core/src/tab/commands/reveal.rs b/yazi-core/src/tab/commands/reveal.rs index 00edc64ff..8f4f9df8d 100644 --- a/yazi-core/src/tab/commands/reveal.rs +++ b/yazi-core/src/tab/commands/reveal.rs @@ -1,5 +1,5 @@ use yazi_proxy::ManagerProxy; -use yazi_shared::{event::{Cmd, Data}, fs::{File, FilesOp, Url, expand_path}}; +use yazi_shared::{event::CmdCow, fs::{File, FilesOp, Url, expand_path}}; use crate::tab::Tab; @@ -7,9 +7,9 @@ struct Opt { target: Url, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { - let mut target = c.take_first().and_then(Data::into_url).unwrap_or_default(); +impl From for Opt { + fn from(mut c: CmdCow) -> Self { + let mut target = c.take_first_url().unwrap_or_default(); if target.is_regular() { target = Url::from(expand_path(&target)); } diff --git a/yazi-core/src/tab/commands/search.rs b/yazi-core/src/tab/commands/search.rs index 068cff576..6073147c4 100644 --- a/yazi-core/src/tab/commands/search.rs +++ b/yazi-core/src/tab/commands/search.rs @@ -1,4 +1,4 @@ -use std::{mem, time::Duration}; +use std::{borrow::Cow, mem, time::Duration}; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; @@ -29,7 +29,7 @@ impl Tab { InputProxy::show(InputCfg::search(&opt.via.to_string()).with_value(opt.subject)); if let Some(Ok(subject)) = input.recv().await { - opt.subject = subject; + opt.subject = Cow::Owned(subject); TabProxy::search_do(opt); } }); @@ -52,14 +52,14 @@ impl Tab { external::rg(external::RgOpt { cwd: cwd.clone(), hidden, - subject: opt.subject, + subject: opt.subject.into_owned(), args: opt.args, }) } else { external::fd(external::FdOpt { cwd: cwd.clone(), hidden, - subject: opt.subject, + subject: opt.subject.into_owned(), args: opt.args, }) }?; diff --git a/yazi-core/src/tab/commands/select.rs b/yazi-core/src/tab/commands/select.rs index 3e237d41b..0415fd8d1 100644 --- a/yazi-core/src/tab/commands/select.rs +++ b/yazi-core/src/tab/commands/select.rs @@ -1,13 +1,13 @@ use std::time::Duration; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl From<()> for Opt { diff --git a/yazi-core/src/tab/commands/select_all.rs b/yazi-core/src/tab/commands/select_all.rs index 55ce6cb71..8fa211944 100644 --- a/yazi-core/src/tab/commands/select_all.rs +++ b/yazi-core/src/tab/commands/select_all.rs @@ -1,11 +1,11 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl Tab { diff --git a/yazi-core/src/tab/commands/shell.rs b/yazi-core/src/tab/commands/shell.rs index 370cf8792..5852da850 100644 --- a/yazi-core/src/tab/commands/shell.rs +++ b/yazi-core/src/tab/commands/shell.rs @@ -3,12 +3,12 @@ use std::{borrow::Cow, fmt::Display}; use anyhow::bail; use yazi_config::{open::Opener, popup::InputCfg}; use yazi_proxy::{AppProxy, InputProxy, TasksProxy}; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::tab::Tab; pub struct Opt { - run: String, + run: Cow<'static, str>, block: bool, orphan: bool, confirm: bool, @@ -16,10 +16,10 @@ pub struct Opt { cursor: Option, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = anyhow::Error; - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { let me = Self { run: c.take_first_str().unwrap_or_default(), block: c.bool("block"), @@ -71,7 +71,7 @@ Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` wi let mut result = InputProxy::show(InputCfg::shell(opt.block).with_value(opt.run).with_cursor(opt.cursor)); match result.recv().await { - Some(Ok(e)) => opt.run = e, + Some(Ok(e)) => opt.run = Cow::Owned(e), _ => return, } } @@ -79,7 +79,7 @@ Please replace e.g. `shell` with `shell --interactive`, `shell "my-template"` wi TasksProxy::open_with( selected, Cow::Owned(Opener { - run: opt.run, + run: opt.run.into_owned(), block: opt.block, orphan: opt.orphan, desc: Default::default(), diff --git a/yazi-core/src/tab/commands/sort.rs b/yazi-core/src/tab/commands/sort.rs index 25acec971..d4c98ab3f 100644 --- a/yazi-core/src/tab/commands/sort.rs +++ b/yazi-core/src/tab/commands/sort.rs @@ -2,12 +2,12 @@ use std::str::FromStr; use yazi_config::manager::SortBy; use yazi_proxy::ManagerProxy; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{tab::Tab, tasks::Tasks}; impl Tab { - pub fn sort(&mut self, mut c: Cmd, tasks: &Tasks) { + pub fn sort(&mut self, mut c: CmdCow, tasks: &Tasks) { let pref = &mut self.pref; if let Some(by) = c.take_first_str() { pref.sort_by = SortBy::from_str(&by).unwrap_or_default(); diff --git a/yazi-core/src/tab/commands/toggle.rs b/yazi-core/src/tab/commands/toggle.rs index 99764a366..7c10c42df 100644 --- a/yazi-core/src/tab/commands/toggle.rs +++ b/yazi-core/src/tab/commands/toggle.rs @@ -1,6 +1,6 @@ use yazi_macro::render_and; use yazi_proxy::AppProxy; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; @@ -8,8 +8,8 @@ struct Opt { state: Option, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { state: match c.take_first_str().as_deref() { Some("on") => Some(true), diff --git a/yazi-core/src/tab/commands/toggle_all.rs b/yazi-core/src/tab/commands/toggle_all.rs index ebab9e97d..e56057160 100644 --- a/yazi-core/src/tab/commands/toggle_all.rs +++ b/yazi-core/src/tab/commands/toggle_all.rs @@ -1,6 +1,6 @@ use yazi_macro::render; use yazi_proxy::AppProxy; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; @@ -8,8 +8,8 @@ struct Opt { state: Option, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { state: match c.take_first_str().as_deref() { Some("on") => Some(true), diff --git a/yazi-core/src/tab/commands/update_peeked.rs b/yazi-core/src/tab/commands/update_peeked.rs index ebe58f826..96e9520ce 100644 --- a/yazi-core/src/tab/commands/update_peeked.rs +++ b/yazi-core/src/tab/commands/update_peeked.rs @@ -1,6 +1,6 @@ use yazi_macro::render; use yazi_plugin::utils::PreviewLock; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; @@ -8,10 +8,10 @@ pub struct Opt { lock: PreviewLock, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { lock: c.take_any("lock").ok_or(())? }) } } diff --git a/yazi-core/src/tab/commands/update_spotted.rs b/yazi-core/src/tab/commands/update_spotted.rs index 05eea4468..9427cde9e 100644 --- a/yazi-core/src/tab/commands/update_spotted.rs +++ b/yazi-core/src/tab/commands/update_spotted.rs @@ -1,6 +1,6 @@ use yazi_macro::render; use yazi_plugin::utils::SpotLock; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::Tab; @@ -8,10 +8,10 @@ pub struct Opt { lock: SpotLock, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { lock: c.take_any("lock").ok_or(())? }) } } diff --git a/yazi-core/src/tab/commands/visual_mode.rs b/yazi-core/src/tab/commands/visual_mode.rs index fcf6369ad..5e6cbc606 100644 --- a/yazi-core/src/tab/commands/visual_mode.rs +++ b/yazi-core/src/tab/commands/visual_mode.rs @@ -1,7 +1,7 @@ use std::collections::BTreeSet; use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tab::{Mode, Tab}; @@ -9,8 +9,8 @@ struct Opt { unset: bool, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { unset: c.bool("unset") } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { unset: c.bool("unset") } } } impl Tab { diff --git a/yazi-core/src/tasks/commands/arrow.rs b/yazi-core/src/tasks/commands/arrow.rs index ba65808f2..d1b8c5279 100644 --- a/yazi-core/src/tasks/commands/arrow.rs +++ b/yazi-core/src/tasks/commands/arrow.rs @@ -1,5 +1,5 @@ use yazi_macro::render; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::tasks::Tasks; @@ -7,8 +7,8 @@ struct Opt { step: isize, } -impl From for Opt { - fn from(c: Cmd) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } +impl From for Opt { + fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } } } impl From for Opt { diff --git a/yazi-core/src/tasks/commands/cancel.rs b/yazi-core/src/tasks/commands/cancel.rs index 2b0b3e125..a8cd9be37 100644 --- a/yazi-core/src/tasks/commands/cancel.rs +++ b/yazi-core/src/tasks/commands/cancel.rs @@ -1,10 +1,10 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tasks::Tasks; impl Tasks { - pub fn cancel(&mut self, _: Cmd) { + pub fn cancel(&mut self, _: CmdCow) { let id = self.ongoing().lock().get_id(self.cursor); if id.map(|id| self.scheduler.cancel(id)) != Some(true) { return; diff --git a/yazi-core/src/tasks/commands/inspect.rs b/yazi-core/src/tasks/commands/inspect.rs index 003b45e1c..147c4381d 100644 --- a/yazi-core/src/tasks/commands/inspect.rs +++ b/yazi-core/src/tasks/commands/inspect.rs @@ -4,12 +4,12 @@ use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use scopeguard::defer; use tokio::{io::{AsyncReadExt, stdin}, select, sync::mpsc, time}; use yazi_proxy::{AppProxy, HIDER}; -use yazi_shared::{event::Cmd, terminal_clear}; +use yazi_shared::{event::CmdCow, terminal_clear}; use crate::tasks::Tasks; impl Tasks { - pub fn inspect(&self, _: Cmd) { + pub fn inspect(&self, _: CmdCow) { let ongoing = self.ongoing().clone(); let Some(id) = ongoing.lock().get_id(self.cursor) else { return; diff --git a/yazi-core/src/tasks/commands/toggle.rs b/yazi-core/src/tasks/commands/toggle.rs index 3d726352c..3b9af7a9b 100644 --- a/yazi-core/src/tasks/commands/toggle.rs +++ b/yazi-core/src/tasks/commands/toggle.rs @@ -1,12 +1,12 @@ use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::tasks::Tasks; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl From<()> for Opt { fn from(_: ()) -> Self { Self } diff --git a/yazi-core/src/which/commands/callback.rs b/yazi-core/src/which/commands/callback.rs index 07ae3cfe9..313fb6cc0 100644 --- a/yazi-core/src/which/commands/callback.rs +++ b/yazi-core/src/which/commands/callback.rs @@ -1,6 +1,6 @@ use tokio::sync::mpsc; use tracing::error; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; use crate::which::Which; @@ -9,10 +9,10 @@ pub struct Opt { idx: usize, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { tx: c.take_any("tx").ok_or(())?, idx: c.first().and_then(Data::as_usize).ok_or(())?, diff --git a/yazi-core/src/which/commands/show.rs b/yazi-core/src/which/commands/show.rs index 91bba6b72..d2860b660 100644 --- a/yazi-core/src/which/commands/show.rs +++ b/yazi-core/src/which/commands/show.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use yazi_config::{KEYMAP, keymap::{Chord, Key}}; use yazi_macro::render; -use yazi_shared::{Layer, event::Cmd}; +use yazi_shared::{Layer, event::CmdCow}; use crate::which::{Which, WhichSorter}; @@ -12,10 +12,10 @@ pub struct Opt { silent: bool, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = anyhow::Error; - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { cands: c.take_any("candidates").unwrap_or_default(), layer: Layer::from_str(&c.take_str("layer").unwrap_or_default())?, diff --git a/yazi-fm/src/app/app.rs b/yazi-fm/src/app/app.rs index 31ff6a15c..b91d4b669 100644 --- a/yazi-fm/src/app/app.rs +++ b/yazi-fm/src/app/app.rs @@ -5,7 +5,7 @@ use crossterm::event::KeyEvent; use yazi_config::keymap::Key; use yazi_core::input::InputMode; use yazi_macro::emit; -use yazi_shared::{Layer, event::{Cmd, Event, NEED_RENDER}}; +use yazi_shared::{Layer, event::{CmdCow, Event, NEED_RENDER}}; use crate::{Ctx, Executor, Router, Signals, Term, lives::Lives}; @@ -66,10 +66,12 @@ impl App { } #[inline] - fn dispatch_call(&mut self, cmd: Cmd, layer: Layer) { Executor::new(self).execute(cmd, layer); } + fn dispatch_call(&mut self, cmd: CmdCow, layer: Layer) { + Executor::new(self).execute(cmd, layer); + } #[inline] - fn dispatch_seq(&mut self, mut cmds: VecDeque, layer: Layer) { + fn dispatch_seq(&mut self, mut cmds: VecDeque, layer: Layer) { if let Some(cmd) = cmds.pop_front() { Executor::new(self).execute(cmd, layer); } diff --git a/yazi-fm/src/app/commands/accept_payload.rs b/yazi-fm/src/app/commands/accept_payload.rs index df3dcaa83..78dd77798 100644 --- a/yazi-fm/src/app/commands/accept_payload.rs +++ b/yazi-fm/src/app/commands/accept_payload.rs @@ -2,12 +2,12 @@ use mlua::IntoLua; use tracing::error; use yazi_dds::{LOCAL, Payload, REMOTE}; use yazi_plugin::LUA; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{app::App, lives::Lives}; impl App { - pub(crate) fn accept_payload(&mut self, mut cmd: Cmd) { + pub(crate) fn accept_payload(&mut self, mut cmd: CmdCow) { let Some(payload) = cmd.take_any::("payload") else { return; }; diff --git a/yazi-fm/src/app/commands/plugin.rs b/yazi-fm/src/app/commands/plugin.rs index c924b6f2d..2df1ebe22 100644 --- a/yazi-fm/src/app/commands/plugin.rs +++ b/yazi-fm/src/app/commands/plugin.rs @@ -17,13 +17,13 @@ impl App { }; let mut hits = false; - if let Some(chunk) = LOADER.read().get(&opt.id) { + if let Some(chunk) = LOADER.read().get(opt.id.as_ref()) { hits = true; opt.mode = opt.mode.auto_then(chunk.sync_entry); } if opt.mode == PluginMode::Async { - return self.cx.tasks.plugin_micro(opt.id, opt.args); + return self.cx.tasks.plugin_micro(opt.id.into_owned(), opt.args); } else if opt.mode == PluginMode::Sync && hits { return self.plugin_do(opt); } @@ -42,12 +42,12 @@ impl App { }; let loader = LOADER.read(); - let Some(chunk) = loader.get(&opt.id) else { + let Some(chunk) = loader.get(opt.id.as_ref()) else { return warn!("plugin `{}` not found", opt.id); }; if opt.mode.auto_then(chunk.sync_entry) != PluginMode::Sync { - return self.cx.tasks.plugin_micro(opt.id, opt.args); + return self.cx.tasks.plugin_micro(opt.id.into_owned(), opt.args); } match LUA.named_registry_value::("rt") { diff --git a/yazi-fm/src/app/commands/reflow.rs b/yazi-fm/src/app/commands/reflow.rs index fda07fcd2..5d944bdb3 100644 --- a/yazi-fm/src/app/commands/reflow.rs +++ b/yazi-fm/src/app/commands/reflow.rs @@ -3,14 +3,14 @@ use ratatui::layout::Position; use tracing::error; use yazi_config::LAYOUT; use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{Root, app::App, lives::Lives}; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl From<()> for Opt { diff --git a/yazi-fm/src/app/commands/resize.rs b/yazi-fm/src/app/commands/resize.rs index ce2ca020d..e55930d8f 100644 --- a/yazi-fm/src/app/commands/resize.rs +++ b/yazi-fm/src/app/commands/resize.rs @@ -1,11 +1,11 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::app::App; struct Opt; -impl From for Opt { - fn from(_: Cmd) -> Self { Self } +impl From for Opt { + fn from(_: CmdCow) -> Self { Self } } impl From<()> for Opt { diff --git a/yazi-fm/src/app/commands/resume.rs b/yazi-fm/src/app/commands/resume.rs index 71c94e18b..f6c37e55d 100644 --- a/yazi-fm/src/app/commands/resume.rs +++ b/yazi-fm/src/app/commands/resume.rs @@ -1,9 +1,9 @@ -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{Term, app::App}; impl App { - pub(crate) fn resume(&mut self, _: Cmd) { + pub(crate) fn resume(&mut self, _: CmdCow) { self.cx.active_mut().preview.reset_image(); self.term = Some(Term::start().unwrap()); diff --git a/yazi-fm/src/app/commands/stop.rs b/yazi-fm/src/app/commands/stop.rs index fed1c1df4..ff07a25fd 100644 --- a/yazi-fm/src/app/commands/stop.rs +++ b/yazi-fm/src/app/commands/stop.rs @@ -1,5 +1,5 @@ use tokio::sync::oneshot; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::app::App; @@ -7,8 +7,8 @@ struct Opt { tx: Option>, } -impl From for Opt { - fn from(mut c: Cmd) -> Self { Self { tx: c.take_any("tx") } } +impl From for Opt { + fn from(mut c: CmdCow) -> Self { Self { tx: c.take_any("tx") } } } impl App { diff --git a/yazi-fm/src/app/commands/update_notify.rs b/yazi-fm/src/app/commands/update_notify.rs index 08a5cc51c..376b66804 100644 --- a/yazi-fm/src/app/commands/update_notify.rs +++ b/yazi-fm/src/app/commands/update_notify.rs @@ -1,12 +1,12 @@ use crossterm::terminal::WindowSize; use ratatui::layout::Rect; use yazi_adapter::Dimension; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::{app::App, notify}; impl App { - pub(crate) fn update_notify(&mut self, cmd: Cmd) { + pub(crate) fn update_notify(&mut self, cmd: CmdCow) { let WindowSize { rows, columns, .. } = Dimension::available(); let area = notify::Notify::available(Rect { x: 0, y: 0, width: columns, height: rows }); diff --git a/yazi-fm/src/app/commands/update_progress.rs b/yazi-fm/src/app/commands/update_progress.rs index 15d9633c8..2a7f88371 100644 --- a/yazi-fm/src/app/commands/update_progress.rs +++ b/yazi-fm/src/app/commands/update_progress.rs @@ -1,6 +1,6 @@ use yazi_core::tasks::TasksProgress; use yazi_macro::render; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; use crate::app::App; @@ -8,10 +8,10 @@ pub struct Opt { progress: TasksProgress, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { Ok(Self { progress: c.take_any("progress").ok_or(())? }) } } diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index 2c3b4bc53..efe7619e5 100644 --- a/yazi-fm/src/executor.rs +++ b/yazi-fm/src/executor.rs @@ -1,5 +1,5 @@ use yazi_core::input::InputMode; -use yazi_shared::{Layer, event::Cmd}; +use yazi_shared::{Layer, event::CmdCow}; use crate::app::App; @@ -12,7 +12,7 @@ impl<'a> Executor<'a> { pub(super) fn new(app: &'a mut App) -> Self { Self { app } } #[inline] - pub(super) fn execute(&mut self, cmd: Cmd, layer: Layer) { + pub(super) fn execute(&mut self, cmd: CmdCow, layer: Layer) { match layer { Layer::App => self.app(cmd), Layer::Manager => self.manager(cmd), @@ -27,7 +27,7 @@ impl<'a> Executor<'a> { } } - fn app(&mut self, cmd: Cmd) { + fn app(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { @@ -47,7 +47,7 @@ impl<'a> Executor<'a> { on!(resume); } - fn manager(&mut self, cmd: Cmd) { + fn manager(&mut self, cmd: CmdCow) { macro_rules! on { (MANAGER, $name:ident $(,$args:expr)*) => { if cmd.name == stringify!($name) { @@ -153,7 +153,7 @@ impl<'a> Executor<'a> { } } - fn tasks(&mut self, cmd: Cmd) { + fn tasks(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { @@ -183,7 +183,7 @@ impl<'a> Executor<'a> { } } - fn spot(&mut self, cmd: Cmd) { + fn spot(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { @@ -206,7 +206,7 @@ impl<'a> Executor<'a> { } } - fn pick(&mut self, cmd: Cmd) { + fn pick(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { @@ -228,7 +228,7 @@ impl<'a> Executor<'a> { } } - fn input(&mut self, cmd: Cmd) { + fn input(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { @@ -284,7 +284,7 @@ impl<'a> Executor<'a> { } } - fn confirm(&mut self, cmd: Cmd) { + fn confirm(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident $(,$args:expr)*) => { if cmd.name == stringify!($name) { @@ -298,7 +298,7 @@ impl<'a> Executor<'a> { on!(close); } - fn help(&mut self, cmd: Cmd) { + fn help(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { @@ -319,7 +319,7 @@ impl<'a> Executor<'a> { } } - fn completion(&mut self, cmd: Cmd) { + fn completion(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { @@ -343,7 +343,7 @@ impl<'a> Executor<'a> { } } - fn which(&mut self, cmd: Cmd) { + fn which(&mut self, cmd: CmdCow) { macro_rules! on { ($name:ident) => { if cmd.name == stringify!($name) { diff --git a/yazi-fm/src/input/input.rs b/yazi-fm/src/input/input.rs index eb17a3b15..d247d97ca 100644 --- a/yazi-fm/src/input/input.rs +++ b/yazi-fm/src/input/input.rs @@ -21,7 +21,7 @@ impl<'a> Input<'a> { bail!("Highlighting is disabled"); } - let (theme, syntaxes) = Highlighter::init(); + let (theme, syntaxes) = futures::executor::block_on(Highlighter::init()); if let Some(syntax) = syntaxes.find_syntax_by_name("Bourne Again Shell (bash)") { let mut h = HighlightLines::new(syntax, theme); let regions = h.highlight_line(self.cx.input.value(), syntaxes)?; diff --git a/yazi-fm/src/router.rs b/yazi-fm/src/router.rs index 0a71cce43..28f94fc56 100644 --- a/yazi-fm/src/router.rs +++ b/yazi-fm/src/router.rs @@ -1,4 +1,4 @@ -use yazi_config::{KEYMAP, keymap::{Chord, Key}}; +use yazi_config::{KEYMAP, keymap::{Chord, ChordCow, Key}}; use yazi_macro::emit; use yazi_shared::Layer; @@ -47,7 +47,7 @@ impl<'a> Router<'a> { #[inline] fn matches(&mut self, layer: Layer, key: Key) -> bool { - for ctrl @ Chord { on, .. } in KEYMAP.get(layer) { + for chord @ Chord { on, .. } in KEYMAP.get(layer) { if on.is_empty() || on[0] != key { continue; } @@ -55,7 +55,7 @@ impl<'a> Router<'a> { if on.len() > 1 { self.app.cx.which.show_with(key, layer); } else { - emit!(Seq(ctrl.to_seq(), layer)); + emit!(Seq(ChordCow::from(chord).into_seq(), layer)); } return true; } diff --git a/yazi-macro/src/event.rs b/yazi-macro/src/event.rs index 012746624..31fd73b8d 100644 --- a/yazi-macro/src/event.rs +++ b/yazi-macro/src/event.rs @@ -4,7 +4,7 @@ macro_rules! emit { yazi_shared::event::Event::Quit($opt).emit(); }; (Call($cmd:expr, $layer:expr)) => { - yazi_shared::event::Event::Call($cmd, $layer).emit(); + yazi_shared::event::Event::Call(yazi_shared::event::CmdCow::from($cmd), $layer).emit(); }; (Seq($cmds:expr, $layer:expr)) => { yazi_shared::event::Event::Seq($cmds, $layer).emit(); diff --git a/yazi-plugin/preset/plugins/font.lua b/yazi-plugin/preset/plugins/font.lua index bf09650cb..567d72a2a 100644 --- a/yazi-plugin/preset/plugins/font.lua +++ b/yazi-plugin/preset/plugins/font.lua @@ -21,7 +21,7 @@ function M:preload() return 1 end - local child, err = Command("magick"):args({ + local status, err = Command("magick"):args({ "-size", "800x560", "-gravity", @@ -37,15 +37,14 @@ function M:preload() "+0+0", TEXT, "JPG:" .. tostring(cache), - }):spawn() + }):status() - if not child then + if status then + return status.success and 1 or 2 + else ya.err("Failed to start `magick`, error: " .. err) return 0 end - - local status = child:wait() - return status and status.success and 1 or 2 end return M diff --git a/yazi-plugin/preset/plugins/magick.lua b/yazi-plugin/preset/plugins/magick.lua index f260ebc6c..f74387dfc 100644 --- a/yazi-plugin/preset/plugins/magick.lua +++ b/yazi-plugin/preset/plugins/magick.lua @@ -19,7 +19,7 @@ function M:preload() return 1 end - local child, err = Command("magick"):args({ + local status, err = Command("magick"):args({ "-density", "200", tostring(self.file.url), @@ -30,15 +30,14 @@ function M:preload() tostring(PREVIEW.image_quality), "-auto-orient", "JPG:" .. tostring(cache), - }):spawn() + }):status() - if not child then + if status then + return status.success and 1 or 2 + else ya.err("Failed to start `magick`, error: " .. err) return 0 end - - local status = child:wait() - return status and status.success and 1 or 2 end function M:spot(job) require("file"):spot(job) end diff --git a/yazi-plugin/preset/plugins/video.lua b/yazi-plugin/preset/plugins/video.lua index 22f728099..c93a3f87b 100644 --- a/yazi-plugin/preset/plugins/video.lua +++ b/yazi-plugin/preset/plugins/video.lua @@ -49,7 +49,7 @@ function M:preload() local ss = math.floor(meta.format.duration * percent / 100) local qv = 31 - math.floor(PREVIEW.image_quality * 0.3) -- stylua: ignore - local child, err = Command("ffmpeg"):args({ + local status, err = Command("ffmpeg"):args({ "-v", "quiet", "-hwaccel", "auto", "-skip_frame", "nokey", "-ss", ss, "-an", "-sn", "-dn", @@ -59,15 +59,14 @@ function M:preload() "-vf", string.format("scale=%d:-2:flags=fast_bilinear", PREVIEW.max_width), "-f", "image2", "-y", tostring(cache), - }):spawn() + }):status() - if not child then + if status then + return status.success and 1 or 2 + else ya.err("Failed to start `ffmpeg`, error: " .. err) return 0 end - - local status = child:wait() - return status and status.success and 1 or 2 end function M:spot(job) diff --git a/yazi-plugin/src/external/highlighter.rs b/yazi-plugin/src/external/highlighter.rs index 75d379373..ab5b79f26 100644 --- a/yazi-plugin/src/external/highlighter.rs +++ b/yazi-plugin/src/external/highlighter.rs @@ -1,14 +1,14 @@ -use std::{borrow::Cow, io::Cursor, mem, path::{Path, PathBuf}, sync::OnceLock}; +use std::{borrow::Cow, io::Cursor, mem, path::{Path, PathBuf}}; use anyhow::{Result, anyhow}; use ratatui::{layout::Size, text::{Line, Span, Text}}; use syntect::{LoadingError, dumps, easy::HighlightLines, highlighting::{self, Theme, ThemeSet}, parsing::{SyntaxReference, SyntaxSet}}; -use tokio::{fs::File, io::{AsyncBufReadExt, BufReader}}; +use tokio::{fs::File, io::{AsyncBufReadExt, BufReader}, sync::OnceCell}; use yazi_config::{PREVIEW, THEME, preview::PreviewWrap}; use yazi_shared::{Ids, errors::PeekError, replace_to_printable}; static INCR: Ids = Ids::new(); -static SYNTECT: OnceLock<(Theme, SyntaxSet)> = OnceLock::new(); +static SYNTECT: OnceCell<(Theme, SyntaxSet)> = OnceCell::const_new(); pub struct Highlighter { path: PathBuf, @@ -18,19 +18,22 @@ impl Highlighter { #[inline] pub fn new(path: &Path) -> Self { Self { path: path.to_owned() } } - pub fn init() -> (&'static Theme, &'static SyntaxSet) { - let r = SYNTECT.get_or_init(|| { - let theme = std::fs::File::open(&THEME.manager.syntect_theme) - .map_err(LoadingError::Io) - .and_then(|f| ThemeSet::load_from_reader(&mut std::io::BufReader::new(f))) - .or_else(|_| ThemeSet::load_from_reader(&mut Cursor::new(yazi_prebuild::ansi_theme()))); + pub async fn init() -> (&'static Theme, &'static SyntaxSet) { + let f = || { + tokio::task::spawn_blocking(|| { + let theme = std::fs::File::open(&THEME.manager.syntect_theme) + .map_err(LoadingError::Io) + .and_then(|f| ThemeSet::load_from_reader(&mut std::io::BufReader::new(f))) + .or_else(|_| ThemeSet::load_from_reader(&mut Cursor::new(yazi_prebuild::ansi_theme()))); - let syntaxes = dumps::from_uncompressed_data(yazi_prebuild::syntaxes()); + let syntaxes = dumps::from_uncompressed_data(yazi_prebuild::syntaxes()); - (theme.unwrap(), syntaxes.unwrap()) - }); + (theme.unwrap(), syntaxes.unwrap()) + }) + }; - (&r.0, &r.1) + let (theme, syntaxes) = SYNTECT.get_or_try_init(f).await.unwrap(); + (theme, syntaxes) } #[inline] @@ -100,7 +103,7 @@ impl Highlighter { syntax: &'static SyntaxReference, ) -> Result, PeekError> { let ticket = INCR.current(); - let (theme, syntaxes) = Self::init(); + let (theme, syntaxes) = Self::init().await; tokio::task::spawn_blocking(move || { let mut h = HighlightLines::new(syntax, theme); @@ -128,7 +131,7 @@ impl Highlighter { } async fn find_syntax(path: &Path) -> Result<&'static SyntaxReference> { - let (_, syntaxes) = Self::init(); + let (_, syntaxes) = Self::init().await; let name = path.file_name().map(|n| n.to_string_lossy()).unwrap_or_default(); if let Some(s) = syntaxes.find_syntax_by_extension(&name) { return Ok(s); diff --git a/yazi-proxy/src/options/notify.rs b/yazi-proxy/src/options/notify.rs index 3eaba76e9..f8901c7e3 100644 --- a/yazi-proxy/src/options/notify.rs +++ b/yazi-proxy/src/options/notify.rs @@ -3,7 +3,7 @@ use std::{str::FromStr, time::Duration}; use anyhow::bail; use mlua::{ExternalError, ExternalResult}; use yazi_config::THEME; -use yazi_shared::{event::Cmd, theme::Style}; +use yazi_shared::{event::CmdCow, theme::Style}; pub struct NotifyOpt { pub title: String, @@ -12,10 +12,10 @@ pub struct NotifyOpt { pub timeout: Duration, } -impl TryFrom for NotifyOpt { +impl TryFrom for NotifyOpt { type Error = (); - fn try_from(mut c: Cmd) -> Result { c.take_any("option").ok_or(()) } + fn try_from(mut c: CmdCow) -> Result { c.take_any("option").ok_or(()) } } impl TryFrom for NotifyOpt { diff --git a/yazi-proxy/src/options/open.rs b/yazi-proxy/src/options/open.rs index 3e8101b6a..48a7c60a4 100644 --- a/yazi-proxy/src/options/open.rs +++ b/yazi-proxy/src/options/open.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use yazi_config::open::Opener; -use yazi_shared::{event::Cmd, fs::Url}; +use yazi_shared::{event::CmdCow, fs::Url}; // --- Open #[derive(Default)] @@ -11,8 +11,8 @@ pub struct OpenDoOpt { pub interactive: bool, } -impl From for OpenDoOpt { - fn from(mut c: Cmd) -> Self { c.take_any("option").unwrap_or_default() } +impl From for OpenDoOpt { + fn from(mut c: CmdCow) -> Self { c.take_any("option").unwrap_or_default() } } // --- Open with @@ -21,8 +21,8 @@ pub struct OpenWithOpt { pub opener: Cow<'static, Opener>, } -impl TryFrom for OpenWithOpt { +impl TryFrom for OpenWithOpt { type Error = (); - fn try_from(mut c: Cmd) -> Result { c.take_any("option").ok_or(()) } + fn try_from(mut c: CmdCow) -> Result { c.take_any("option").ok_or(()) } } diff --git a/yazi-proxy/src/options/plugin.rs b/yazi-proxy/src/options/plugin.rs index 77a19f2b0..02b737688 100644 --- a/yazi-proxy/src/options/plugin.rs +++ b/yazi-proxy/src/options/plugin.rs @@ -1,21 +1,23 @@ +use std::borrow::Cow; + use anyhow::bail; use mlua::{Lua, Table}; -use yazi_shared::event::{Cmd, Data}; +use yazi_shared::event::{CmdCow, Data}; -pub type PluginCallback = Box mlua::Result<()> + Send>; +pub type PluginCallback = Box mlua::Result<()> + Send + Sync>; #[derive(Default)] pub struct PluginOpt { - pub id: String, + pub id: Cow<'static, str>, pub mode: PluginMode, pub args: Vec, pub cb: Option, } -impl TryFrom for PluginOpt { +impl TryFrom for PluginOpt { type Error = anyhow::Error; - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { if let Some(opt) = c.take_any("opt") { return Ok(opt); } @@ -50,7 +52,7 @@ Please add `--- @sync entry` metadata at the head of your `{id}` plugin instead. impl PluginOpt { pub fn new_callback(id: &str, cb: PluginCallback) -> Self { - Self { id: id.to_owned(), mode: PluginMode::Sync, cb: Some(cb), ..Default::default() } + Self { id: id.to_owned().into(), mode: PluginMode::Sync, cb: Some(cb), ..Default::default() } } } diff --git a/yazi-proxy/src/options/process.rs b/yazi-proxy/src/options/process.rs index 28b3b8ece..23b6b7c31 100644 --- a/yazi-proxy/src/options/process.rs +++ b/yazi-proxy/src/options/process.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, ffi::OsString}; use tokio::sync::oneshot; use yazi_config::open::Opener; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; // --- Exec pub struct ProcessExecOpt { @@ -11,8 +11,8 @@ pub struct ProcessExecOpt { pub done: oneshot::Sender<()>, } -impl TryFrom for ProcessExecOpt { +impl TryFrom for ProcessExecOpt { type Error = (); - fn try_from(mut c: Cmd) -> Result { c.take_any("option").ok_or(()) } + fn try_from(mut c: CmdCow) -> Result { c.take_any("option").ok_or(()) } } diff --git a/yazi-proxy/src/options/search.rs b/yazi-proxy/src/options/search.rs index b985e773d..f6d8575f3 100644 --- a/yazi-proxy/src/options/search.rs +++ b/yazi-proxy/src/options/search.rs @@ -1,23 +1,29 @@ -use std::fmt::Display; +use std::{borrow::Cow, fmt::Display}; -use yazi_shared::event::Cmd; +use yazi_shared::event::CmdCow; pub struct SearchOpt { pub via: SearchOptVia, - pub subject: String, + pub subject: Cow<'static, str>, pub args: Vec, - pub args_raw: String, + pub args_raw: Cow<'static, str>, } -impl TryFrom for SearchOpt { +impl TryFrom for SearchOpt { type Error = (); - fn try_from(mut c: Cmd) -> Result { + fn try_from(mut c: CmdCow) -> Result { + // TODO: remove this + let (via, subject) = if let Some(s) = c.take_str("via") { + (s.as_ref().into(), c.take_first_str().unwrap_or_default()) + } else { + (c.take_first_str().unwrap_or_default().as_ref().into(), "".into()) + }; + Ok(Self { - // TODO: remove `c.take_first_str()` in the future - via: c.take_str("via").or_else(|| c.take_first_str()).unwrap_or_default().into(), - subject: c.take_first_str().unwrap_or_default(), - args: shell_words::split(c.str("args").unwrap_or_default()).map_err(|_| ())?, + via, + subject, + args: shell_words::split(c.str("args").unwrap_or_default()).map_err(|_| ())?, args_raw: c.take_str("args").unwrap_or_default(), }) } @@ -32,9 +38,9 @@ pub enum SearchOptVia { Fd, } -impl From for SearchOptVia { - fn from(value: String) -> Self { - match value.as_str() { +impl From<&str> for SearchOptVia { + fn from(value: &str) -> Self { + match value { "rg" => Self::Rg, "fd" => Self::Fd, _ => Self::None, diff --git a/yazi-scheduler/src/plugin/op.rs b/yazi-scheduler/src/plugin/op.rs index bac6d530d..183fa658e 100644 --- a/yazi-scheduler/src/plugin/op.rs +++ b/yazi-scheduler/src/plugin/op.rs @@ -16,6 +16,7 @@ impl PluginOp { #[derive(Debug)] pub struct PluginOpEntry { pub id: usize, + // TODO: remove these fields and use `CmdCow` instead pub name: String, pub args: Vec, } diff --git a/yazi-shared/src/event/cmd.rs b/yazi-shared/src/event/cmd.rs index 307da56ad..6f5cfcd01 100644 --- a/yazi-shared/src/event/cmd.rs +++ b/yazi-shared/src/event/cmd.rs @@ -4,6 +4,7 @@ use anyhow::bail; use serde::{Deserialize, de}; use super::Data; +use crate::fs::Url; #[derive(Debug, Default)] pub struct Cmd { @@ -49,7 +50,7 @@ impl Cmd { } #[inline] - pub fn with_any(mut self, name: impl ToString, data: impl Any + Send) -> Self { + pub fn with_any(mut self, name: impl ToString, data: impl Any + Send + Sync) -> Self { self.args.insert(name.to_string(), Data::Any(Box::new(data))); self } @@ -70,6 +71,9 @@ impl Cmd { #[inline] pub fn first(&self) -> Option<&Data> { self.get("0") } + #[inline] + pub fn first_str(&self) -> Option<&str> { self.str("0") } + // --- Take #[inline] pub fn take(&mut self, name: &str) -> Option { self.args.remove(name) } @@ -87,22 +91,13 @@ impl Cmd { if let Some(Data::String(s)) = self.take_first() { Some(s) } else { None } } + #[inline] + pub fn take_first_url(&mut self) -> Option { self.take_first()?.into_url() } + #[inline] pub fn take_any(&mut self, name: &str) -> Option { self.args.remove(name).and_then(|d| d.into_any()) } - - // --- Clone - pub fn shallow_clone(&self) -> Self { - Self { - name: self.name.clone(), - args: self - .args - .iter() - .filter_map(|(k, v)| v.shallow_clone().map(|v| (k.clone(), v))) - .collect(), - } - } } impl Display for Cmd { diff --git a/yazi-shared/src/event/cow.rs b/yazi-shared/src/event/cow.rs new file mode 100644 index 000000000..ac5dd97aa --- /dev/null +++ b/yazi-shared/src/event/cow.rs @@ -0,0 +1,78 @@ +use std::{borrow::Cow, ops::Deref}; + +use super::{Cmd, Data}; +use crate::fs::Url; + +#[derive(Debug)] +pub enum CmdCow { + Owned(Cmd), + Borrowed(&'static Cmd), +} + +impl From for CmdCow { + fn from(c: Cmd) -> Self { Self::Owned(c) } +} + +impl From<&'static Cmd> for CmdCow { + fn from(c: &'static Cmd) -> Self { Self::Borrowed(c) } +} + +impl Deref for CmdCow { + type Target = Cmd; + + fn deref(&self) -> &Self::Target { + match self { + Self::Owned(c) => c, + Self::Borrowed(c) => c, + } + } +} + +impl CmdCow { + #[inline] + pub fn try_take(&mut self, name: &str) -> Option { + match self { + Self::Owned(c) => c.take(name), + Self::Borrowed(_) => None, + } + } + + #[inline] + pub fn take_str(&mut self, name: &str) -> Option> { + match self { + Self::Owned(c) => c.take_str(name).map(Cow::Owned), + Self::Borrowed(c) => c.str(name).map(Cow::Borrowed), + } + } + + #[inline] + pub fn take_url(&mut self, name: &str) -> Option { + match self { + Self::Owned(c) => c.take(name).and_then(Data::into_url), + Self::Borrowed(c) => c.get(name).and_then(Data::to_url), + } + } + + #[inline] + pub fn take_first_str(&mut self) -> Option> { + match self { + Self::Owned(c) => c.take_first_str().map(Cow::Owned), + Self::Borrowed(c) => c.first_str().map(Cow::Borrowed), + } + } + + pub fn take_first_url(&mut self) -> Option { + match self { + Self::Owned(c) => c.take_first_url(), + Self::Borrowed(c) => c.first().and_then(Data::to_url), + } + } + + #[inline] + pub fn take_any(&mut self, name: &str) -> Option { + match self { + Self::Owned(c) => c.take_any(name), + Self::Borrowed(_) => None, + } + } +} diff --git a/yazi-shared/src/event/data.rs b/yazi-shared/src/event/data.rs index e5675a983..40f7bebb3 100644 --- a/yazi-shared/src/event/data.rs +++ b/yazi-shared/src/event/data.rs @@ -18,7 +18,7 @@ pub enum Data { #[serde(skip_deserializing)] Url(Url), #[serde(skip)] - Any(Box), + Any(Box), } impl Data { @@ -40,14 +40,6 @@ impl Data { } } - #[inline] - pub fn as_any(&self) -> Option<&T> { - match self { - Self::Any(b) => b.downcast_ref::(), - _ => None, - } - } - #[inline] pub fn into_any(self) -> Option { match self { @@ -80,10 +72,10 @@ impl Data { } #[inline] - pub fn shallow_clone(&self) -> Option { + pub fn to_url(&self) -> Option { match self { - Self::Boolean(b) => Some(Self::Boolean(*b)), - Self::String(s) => Some(Self::String(s.clone())), + Self::String(s) => Some(Url::from(s)), + Self::Url(u) => Some(u.clone()), _ => None, } } diff --git a/yazi-shared/src/event/event.rs b/yazi-shared/src/event/event.rs index 8298913d6..cd8d03b9b 100644 --- a/yazi-shared/src/event/event.rs +++ b/yazi-shared/src/event/event.rs @@ -3,7 +3,7 @@ use std::{collections::VecDeque, ffi::OsString}; use crossterm::event::{KeyEvent, MouseEvent}; use tokio::sync::mpsc; -use super::Cmd; +use super::CmdCow; use crate::{Layer, RoCell}; static TX: RoCell> = RoCell::new(); @@ -11,8 +11,8 @@ static RX: RoCell> = RoCell::new(); #[derive(Debug)] pub enum Event { - Call(Cmd, Layer), - Seq(VecDeque, Layer), + Call(CmdCow, Layer), + Seq(VecDeque, Layer), Render, Key(KeyEvent), Mouse(MouseEvent), diff --git a/yazi-shared/src/event/mod.rs b/yazi-shared/src/event/mod.rs index 86f5ad3c6..1399e1450 100644 --- a/yazi-shared/src/event/mod.rs +++ b/yazi-shared/src/event/mod.rs @@ -1,5 +1,5 @@ #![allow(clippy::module_inception)] -yazi_macro::mod_flat!(cmd data event); +yazi_macro::mod_flat!(cmd cow data event); pub static NEED_RENDER: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); diff --git a/yazi-shared/src/fs/op.rs b/yazi-shared/src/fs/op.rs index 2f0a76052..84d03cce6 100644 --- a/yazi-shared/src/fs/op.rs +++ b/yazi-shared/src/fs/op.rs @@ -38,7 +38,8 @@ impl FilesOp { #[inline] pub fn emit(self) { - crate::event::Event::Call(Cmd::new("update_files").with_any("op", self), Layer::Manager).emit(); + crate::event::Event::Call(Cmd::new("update_files").with_any("op", self).into(), Layer::Manager) + .emit(); } pub fn prepare(cwd: &Url) -> Id {