diff --git a/cspell.json b/cspell.json index 847adae7b..c089cb893 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos"],"flagWords":[],"version":"0.2"} \ No newline at end of file +{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds"],"language":"en","version":"0.2"} \ No newline at end of file diff --git a/yazi-config/src/keymap/control.rs b/yazi-config/src/keymap/control.rs index aa178c637..74548fe71 100644 --- a/yazi-config/src/keymap/control.rs +++ b/yazi-config/src/keymap/control.rs @@ -1,7 +1,7 @@ -use std::{borrow::Cow, collections::VecDeque}; +use std::{borrow::Cow, collections::VecDeque, ops::Deref}; use serde::Deserialize; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use super::Key; @@ -9,12 +9,13 @@ use super::Key; pub struct Control { pub on: Vec, #[serde(deserialize_with = "super::exec_deserialize")] - pub exec: Vec, + pub exec: Vec, pub desc: Option, } impl Control { - pub fn to_seq(&self) -> VecDeque { + #[inline] + pub fn to_seq(&self) -> VecDeque { self.exec.iter().map(|e| e.clone_without_data()).collect() } } @@ -41,3 +42,27 @@ impl Control { || self.on().to_lowercase().contains(&s) } } + +pub enum ControlCow { + Owned(Control), + Borrowed(&'static Control), +} + +impl From<&'static Control> for ControlCow { + fn from(c: &'static Control) -> Self { Self::Borrowed(c) } +} + +impl From for ControlCow { + fn from(c: Control) -> Self { Self::Owned(c) } +} + +impl Deref for ControlCow { + type Target = Control; + + fn deref(&self) -> &Self::Target { + match self { + Self::Owned(c) => c, + Self::Borrowed(c) => c, + } + } +} diff --git a/yazi-config/src/keymap/exec.rs b/yazi-config/src/keymap/exec.rs index 5f4a0e58b..6b54e5654 100644 --- a/yazi-config/src/keymap/exec.rs +++ b/yazi-config/src/keymap/exec.rs @@ -2,36 +2,36 @@ use std::fmt; use anyhow::{bail, Result}; use serde::{de::{self, Visitor}, Deserializer}; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; -pub(super) fn exec_deserialize<'de, D>(deserializer: D) -> Result, D::Error> +pub(super) fn exec_deserialize<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { struct ExecVisitor; - fn parse(s: &str) -> Result { + fn parse(s: &str) -> Result { let s = shell_words::split(s)?; if s.is_empty() { bail!("`exec` cannot be empty"); } - let mut exec = Exec { cmd: s[0].clone(), ..Default::default() }; + let mut cmd = Cmd { name: s[0].clone(), ..Default::default() }; for arg in s.into_iter().skip(1) { if arg.starts_with("--") { let mut arg = arg.splitn(2, '='); let key = arg.next().unwrap().trim_start_matches('-'); let val = arg.next().unwrap_or("").to_string(); - exec.named.insert(key.to_string(), val); + cmd.named.insert(key.to_string(), val); } else { - exec.args.push(arg); + cmd.args.push(arg); } } - Ok(exec) + Ok(cmd) } impl<'de> Visitor<'de> for ExecVisitor { - type Value = Vec; + type Value = Vec; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("a `exec` string or array of strings within [keymap]") @@ -41,14 +41,14 @@ where where A: de::SeqAccess<'de>, { - let mut execs = vec![]; + let mut cmds = vec![]; while let Some(value) = &seq.next_element::()? { - execs.push(parse(value).map_err(de::Error::custom)?); + cmds.push(parse(value).map_err(de::Error::custom)?); } - if execs.is_empty() { + if cmds.is_empty() { return Err(de::Error::custom("`exec` within [keymap] cannot be empty")); } - Ok(execs) + Ok(cmds) } fn visit_str(self, value: &str) -> Result diff --git a/yazi-config/src/plugin/exec.rs b/yazi-config/src/plugin/exec.rs index 8e7f81bb4..2e3fd68ba 100644 --- a/yazi-config/src/plugin/exec.rs +++ b/yazi-config/src/plugin/exec.rs @@ -2,16 +2,16 @@ use std::fmt; use anyhow::Result; use serde::{de::{self, Visitor}, Deserializer}; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; -pub(super) fn exec_deserialize<'de, D>(deserializer: D) -> Result +pub(super) fn exec_deserialize<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, { struct ExecVisitor; impl<'de> Visitor<'de> for ExecVisitor { - type Value = Exec; + type Value = Cmd; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("a `exec` string or array of strings") @@ -31,7 +31,7 @@ where if value.is_empty() { return Err(de::Error::custom("`exec` within [plugin] cannot be empty")); } - Ok(Exec { cmd: value.to_owned(), ..Default::default() }) + Ok(Cmd { name: value.to_owned(), ..Default::default() }) } } diff --git a/yazi-config/src/plugin/plugin.rs b/yazi-config/src/plugin/plugin.rs index 85c9d2c4d..dc5228f07 100644 --- a/yazi-config/src/plugin/plugin.rs +++ b/yazi-config/src/plugin/plugin.rs @@ -1,7 +1,7 @@ use std::path::Path; use serde::Deserialize; -use yazi_shared::{event::Exec, Condition, MIME_DIR}; +use yazi_shared::{event::Cmd, Condition, MIME_DIR}; use crate::{pattern::Pattern, plugin::MAX_PRELOADERS, Preset, Priority, MERGED_YAZI}; @@ -18,8 +18,9 @@ pub struct PluginRule { pub cond: Option, pub name: Option, pub mime: Option, + #[serde(rename = "exec")] #[serde(deserialize_with = "super::exec_deserialize")] - pub exec: Exec, + pub cmd: Cmd, #[serde(default)] pub sync: bool, #[serde(default)] diff --git a/yazi-config/src/plugin/props.rs b/yazi-config/src/plugin/props.rs index 80a8196cb..410bb73f4 100644 --- a/yazi-config/src/plugin/props.rs +++ b/yazi-config/src/plugin/props.rs @@ -4,13 +4,13 @@ use crate::Priority; #[derive(Debug, Clone)] pub struct PluginProps { pub id: u8, - pub cmd: String, + pub name: String, pub multi: bool, pub prio: Priority, } impl From<&PluginRule> for PluginProps { fn from(rule: &PluginRule) -> Self { - Self { id: rule.id, cmd: rule.exec.cmd.to_owned(), multi: rule.multi, prio: rule.prio } + Self { id: rule.id, name: rule.cmd.name.to_owned(), multi: rule.multi, prio: rule.prio } } } diff --git a/yazi-core/src/completion/commands/arrow.rs b/yazi-core/src/completion/commands/arrow.rs index c8bc0ba14..5598be2d6 100644 --- a/yazi-core/src/completion/commands/arrow.rs +++ b/yazi-core/src/completion/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::completion::Completion; @@ -6,9 +6,9 @@ pub struct Opt { step: isize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } } } diff --git a/yazi-core/src/completion/commands/close.rs b/yazi-core/src/completion/commands/close.rs index c0c6f812f..91fe09340 100644 --- a/yazi-core/src/completion/commands/close.rs +++ b/yazi-core/src/completion/commands/close.rs @@ -1,4 +1,4 @@ -use yazi_shared::{emit, event::Exec, render, Layer}; +use yazi_shared::{emit, event::Cmd, render, Layer}; use crate::{completion::Completion, input::Input}; @@ -6,14 +6,14 @@ pub struct Opt { submit: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { submit: e.named.contains_key("submit") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { submit: c.named.contains_key("submit") } } } impl Completion { #[inline] pub fn _close() { - emit!(Call(Exec::call("close", vec![]), Layer::Completion)); + emit!(Call(Cmd::new("close"), Layer::Completion)); } pub fn close(&mut self, opt: impl Into) { diff --git a/yazi-core/src/completion/commands/show.rs b/yazi-core/src/completion/commands/show.rs index 963ed471b..b5b61c1fe 100644 --- a/yazi-core/src/completion/commands/show.rs +++ b/yazi-core/src/completion/commands/show.rs @@ -1,6 +1,6 @@ use std::{mem, ops::ControlFlow}; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::completion::Completion; @@ -13,13 +13,13 @@ pub struct Opt { ticket: usize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - cache: mem::take(&mut e.args), - cache_name: e.take_name("cache-name").unwrap_or_default(), - word: e.take_name("word").unwrap_or_default(), - ticket: e.take_name("ticket").and_then(|v| v.parse().ok()).unwrap_or(0), + cache: mem::take(&mut c.args), + cache_name: c.take_name("cache-name").unwrap_or_default(), + word: c.take_name("word").unwrap_or_default(), + ticket: c.take_name("ticket").and_then(|v| v.parse().ok()).unwrap_or(0), } } } diff --git a/yazi-core/src/completion/commands/trigger.rs b/yazi-core/src/completion/commands/trigger.rs index 44869ab76..f8389190a 100644 --- a/yazi-core/src/completion/commands/trigger.rs +++ b/yazi-core/src/completion/commands/trigger.rs @@ -1,7 +1,7 @@ use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}}; use tokio::fs; -use yazi_shared::{emit, event::Exec, render, Layer}; +use yazi_shared::{emit, event::Cmd, render, Layer}; use crate::completion::Completion; @@ -10,11 +10,11 @@ pub struct Opt { ticket: usize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - word: e.take_first().unwrap_or_default(), - ticket: e.take_name("ticket").and_then(|s| s.parse().ok()).unwrap_or(0), + word: c.take_first().unwrap_or_default(), + ticket: c.take_name("ticket").and_then(|s| s.parse().ok()).unwrap_or(0), } } } @@ -23,7 +23,7 @@ impl Completion { #[inline] pub fn _trigger(word: &str, ticket: usize) { emit!(Call( - Exec::call("trigger", vec![word.to_owned()]).with("ticket", ticket), + Cmd::args("trigger", vec![word.to_owned()]).with("ticket", ticket), Layer::Completion )); } @@ -39,10 +39,7 @@ impl Completion { if self.caches.contains_key(&parent) { return self.show( - Exec::call("show", vec![]) - .with("cache-name", parent) - .with("word", child) - .with("ticket", opt.ticket), + Cmd::new("show").with("cache-name", parent).with("word", child).with("ticket", opt.ticket), ); } @@ -64,7 +61,7 @@ impl Completion { if !cache.is_empty() { emit!(Call( - Exec::call("show", cache) + Cmd::args("show", cache) .with("cache-name", parent) .with("word", child) .with("ticket", ticket), diff --git a/yazi-core/src/folder/filter.rs b/yazi-core/src/folder/filter.rs index 10d3823c3..61d909e57 100644 --- a/yazi-core/src/folder/filter.rs +++ b/yazi-core/src/folder/filter.rs @@ -2,7 +2,7 @@ use std::{ffi::OsStr, ops::Range}; use anyhow::Result; use regex::bytes::{Regex, RegexBuilder}; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; pub struct Filter { raw: String, @@ -43,9 +43,9 @@ pub enum FilterCase { Insensitive, } -impl From<&Exec> for FilterCase { - fn from(e: &Exec) -> Self { - match (e.named.contains_key("smart"), e.named.contains_key("insensitive")) { +impl From<&Cmd> for FilterCase { + fn from(c: &Cmd) -> Self { + match (c.named.contains_key("smart"), c.named.contains_key("insensitive")) { (true, _) => Self::Smart, (_, false) => Self::Sensitive, (_, true) => Self::Insensitive, diff --git a/yazi-core/src/help/commands/arrow.rs b/yazi-core/src/help/commands/arrow.rs index 59b981375..8cef1f115 100644 --- a/yazi-core/src/help/commands/arrow.rs +++ b/yazi-core/src/help/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::help::Help; @@ -6,9 +6,9 @@ pub struct Opt { step: isize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } } } impl From for Opt { diff --git a/yazi-core/src/help/commands/escape.rs b/yazi-core/src/help/commands/escape.rs index 35d4a7e62..2d6c58a36 100644 --- a/yazi-core/src/help/commands/escape.rs +++ b/yazi-core/src/help/commands/escape.rs @@ -1,9 +1,9 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::help::Help; impl Help { - pub fn escape(&mut self, _: Exec) { + pub fn escape(&mut self, _: Cmd) { if self.in_filter.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 992486a34..f09b9ab03 100644 --- a/yazi-core/src/help/commands/filter.rs +++ b/yazi-core/src/help/commands/filter.rs @@ -1,10 +1,10 @@ use yazi_config::popup::{Offset, Origin, Position}; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::{help::Help, input::Input}; impl Help { - pub fn filter(&mut self, _: Exec) { + pub fn filter(&mut self, _: Cmd) { 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 d73eb1d07..c5fb688c5 100644 --- a/yazi-core/src/input/commands/backspace.rs +++ b/yazi-core/src/input/commands/backspace.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::Input; @@ -6,8 +6,8 @@ pub struct Opt { under: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { under: e.named.contains_key("under") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { under: c.named.contains_key("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 37d44640f..d25f23d6b 100644 --- a/yazi-core/src/input/commands/backward.rs +++ b/yazi-core/src/input/commands/backward.rs @@ -1,9 +1,9 @@ -use yazi_shared::{event::Exec, CharKind}; +use yazi_shared::{event::Cmd, CharKind}; use crate::input::Input; impl Input { - pub fn backward(&mut self, _: Exec) { + pub fn backward(&mut self, _: Cmd) { 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 7ddd9b71e..a882b4112 100644 --- a/yazi-core/src/input/commands/close.rs +++ b/yazi-core/src/input/commands/close.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render, InputError}; +use yazi_shared::{event::Cmd, render, InputError}; use crate::{completion::Completion, input::Input}; @@ -6,8 +6,8 @@ pub struct Opt { submit: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { submit: e.named.contains_key("submit") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { submit: c.named.contains_key("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 d3097ae08..e0dcc3a3a 100644 --- a/yazi-core/src/input/commands/complete.rs +++ b/yazi-core/src/input/commands/complete.rs @@ -1,6 +1,6 @@ use std::path::MAIN_SEPARATOR; -use yazi_shared::{emit, event::Exec, render, Layer}; +use yazi_shared::{emit, event::Cmd, render, Layer}; use crate::input::Input; @@ -9,11 +9,11 @@ pub struct Opt { ticket: usize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - word: e.take_first().unwrap_or_default(), - ticket: e.take_name("ticket").and_then(|s| s.parse().ok()).unwrap_or(0), + word: c.take_first().unwrap_or_default(), + ticket: c.take_name("ticket").and_then(|s| s.parse().ok()).unwrap_or(0), } } } @@ -21,7 +21,7 @@ impl From for Opt { impl Input { #[inline] pub fn _complete(word: &str, ticket: usize) { - emit!(Call(Exec::call("complete", vec![word.to_owned()]).with("ticket", ticket), Layer::Input)); + emit!(Call(Cmd::args("complete", vec![word.to_owned()]).with("ticket", ticket), Layer::Input)); } pub fn complete(&mut self, opt: impl Into) { diff --git a/yazi-core/src/input/commands/delete.rs b/yazi-core/src/input/commands/delete.rs index e99d670fb..415df466f 100644 --- a/yazi-core/src/input/commands/delete.rs +++ b/yazi-core/src/input/commands/delete.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::{op::InputOp, Input}; @@ -7,9 +7,9 @@ pub struct Opt { insert: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { - Self { cut: e.named.contains_key("cut"), insert: e.named.contains_key("insert") } +impl From for Opt { + fn from(c: Cmd) -> Self { + Self { cut: c.named.contains_key("cut"), insert: c.named.contains_key("insert") } } } diff --git a/yazi-core/src/input/commands/escape.rs b/yazi-core/src/input/commands/escape.rs index bd29c553d..b27008370 100644 --- a/yazi-core/src/input/commands/escape.rs +++ b/yazi-core/src/input/commands/escape.rs @@ -1,11 +1,11 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}}; pub struct Opt; -impl From for Opt { - fn from(_: Exec) -> Self { Self } +impl From for Opt { + fn from(_: Cmd) -> 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 a374e6cf6..339c2177a 100644 --- a/yazi-core/src/input/commands/forward.rs +++ b/yazi-core/src/input/commands/forward.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, CharKind}; +use yazi_shared::{event::Cmd, CharKind}; use crate::input::{op::InputOp, Input}; @@ -6,8 +6,8 @@ pub struct Opt { end_of_word: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { end_of_word: e.named.contains_key("end-of-word") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { end_of_word: c.named.contains_key("end-of-word") } } } impl Input { diff --git a/yazi-core/src/input/commands/insert.rs b/yazi-core/src/input/commands/insert.rs index 23523be5c..c5289b653 100644 --- a/yazi-core/src/input/commands/insert.rs +++ b/yazi-core/src/input/commands/insert.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::{op::InputOp, Input, InputMode}; @@ -6,8 +6,8 @@ pub struct Opt { append: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { append: e.named.contains_key("append") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { append: c.named.contains_key("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 b86bee85b..3d0ae7805 100644 --- a/yazi-core/src/input/commands/kill.rs +++ b/yazi-core/src/input/commands/kill.rs @@ -1,6 +1,6 @@ use std::ops::RangeBounds; -use yazi_shared::{event::Exec, render, CharKind}; +use yazi_shared::{event::Cmd, render, CharKind}; use crate::input::Input; @@ -8,8 +8,8 @@ pub struct Opt { kind: String, } -impl From for Opt { - fn from(mut e: Exec) -> Self { Self { kind: e.take_first().unwrap_or_default() } } +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { kind: c.take_first().unwrap_or_default() } } } impl Input { diff --git a/yazi-core/src/input/commands/move_.rs b/yazi-core/src/input/commands/move_.rs index c3d208215..0e032b351 100644 --- a/yazi-core/src/input/commands/move_.rs +++ b/yazi-core/src/input/commands/move_.rs @@ -1,5 +1,5 @@ use unicode_width::UnicodeWidthStr; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::{op::InputOp, snap::InputSnap, Input}; @@ -8,11 +8,11 @@ pub struct Opt { in_operating: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0), - in_operating: e.named.contains_key("in-operating"), + step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0), + in_operating: c.named.contains_key("in-operating"), } } } diff --git a/yazi-core/src/input/commands/paste.rs b/yazi-core/src/input/commands/paste.rs index 8ee5be5e1..c89621164 100644 --- a/yazi-core/src/input/commands/paste.rs +++ b/yazi-core/src/input/commands/paste.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::{input::{op::InputOp, Input}, CLIPBOARD}; @@ -6,8 +6,8 @@ pub struct Opt { before: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { before: e.named.contains_key("before") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { before: c.named.contains_key("before") } } } impl Input { diff --git a/yazi-core/src/input/commands/redo.rs b/yazi-core/src/input/commands/redo.rs index 329635a9b..0b610614b 100644 --- a/yazi-core/src/input/commands/redo.rs +++ b/yazi-core/src/input/commands/redo.rs @@ -1,9 +1,9 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::Input; impl Input { - pub fn redo(&mut self, _: Exec) { + pub fn redo(&mut self, _: Cmd) { render!(self.snaps.redo()); } } diff --git a/yazi-core/src/input/commands/show.rs b/yazi-core/src/input/commands/show.rs index 260bc646c..f6b4b30ff 100644 --- a/yazi-core/src/input/commands/show.rs +++ b/yazi-core/src/input/commands/show.rs @@ -1,6 +1,6 @@ use tokio::sync::mpsc; use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::Exec, render, InputError, Layer}; +use yazi_shared::{emit, event::Cmd, render, InputError, Layer}; use crate::input::Input; @@ -9,16 +9,16 @@ pub struct Opt { tx: mpsc::UnboundedSender>, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut e: Exec) -> Result { e.take_data().ok_or(()) } + fn try_from(mut c: Cmd) -> Result { c.take_data().ok_or(()) } } impl Input { pub fn _show(cfg: InputCfg) -> mpsc::UnboundedReceiver> { let (tx, rx) = mpsc::unbounded_channel(); - emit!(Call(Exec::call("show", vec![]).with_data(Opt { cfg, tx }), Layer::Input)); + emit!(Call(Cmd::new("show").with_data(Opt { cfg, tx }), Layer::Input)); rx } diff --git a/yazi-core/src/input/commands/type_.rs b/yazi-core/src/input/commands/type_.rs index 1da405dcc..5915ab9a6 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::Exec; +use yazi_shared::event::Cmd; use crate::input::{Input, InputMode}; pub struct Opt; -impl From for Opt { - fn from(_: Exec) -> Self { Self } +impl From for Opt { + fn from(_: Cmd) -> Self { Self } } impl Input { diff --git a/yazi-core/src/input/commands/undo.rs b/yazi-core/src/input/commands/undo.rs index c111e6ac7..ac2a7fbde 100644 --- a/yazi-core/src/input/commands/undo.rs +++ b/yazi-core/src/input/commands/undo.rs @@ -1,9 +1,9 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::{Input, InputMode}; impl Input { - pub fn undo(&mut self, _: Exec) { + pub fn undo(&mut self, _: Cmd) { if !self.snaps.undo() { return; } diff --git a/yazi-core/src/input/commands/visual.rs b/yazi-core/src/input/commands/visual.rs index 98a4ca5d5..b53d33746 100644 --- a/yazi-core/src/input/commands/visual.rs +++ b/yazi-core/src/input/commands/visual.rs @@ -1,10 +1,10 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::{op::InputOp, Input, InputMode}; impl Input { #[inline] - pub fn visual(&mut self, _: Exec) { + pub fn visual(&mut self, _: Cmd) { 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 4bc387295..2babc8f33 100644 --- a/yazi-core/src/input/commands/yank.rs +++ b/yazi-core/src/input/commands/yank.rs @@ -1,9 +1,9 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::input::{op::InputOp, Input}; impl Input { - pub fn yank(&mut self, _: Exec) { + pub fn yank(&mut self, _: Cmd) { 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 aa199942c..535b00639 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::Exec; +use yazi_shared::event::Cmd; use crate::{manager::Manager, tasks::Tasks}; impl Manager { - pub fn close(&mut self, _: Exec, tasks: &Tasks) { + pub fn close(&mut self, _: Cmd, tasks: &Tasks) { if self.tabs.len() > 1 { return self.tabs.close(self.tabs.idx); } diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index de7e4687b..22490ba5a 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -2,7 +2,7 @@ use std::path::{PathBuf, MAIN_SEPARATOR}; use tokio::fs; use yazi_config::popup::InputCfg; -use yazi_shared::{event::Exec, fs::{File, FilesOp, Url}}; +use yazi_shared::{event::Cmd, fs::{File, FilesOp, Url}}; use crate::{input::Input, manager::Manager}; @@ -10,8 +10,8 @@ pub struct Opt { force: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { force: e.named.contains_key("force") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { force: c.named.contains_key("force") } } } impl Manager { diff --git a/yazi-core/src/manager/commands/hover.rs b/yazi-core/src/manager/commands/hover.rs index 5cd6180e1..b1b2d0052 100644 --- a/yazi-core/src/manager/commands/hover.rs +++ b/yazi-core/src/manager/commands/hover.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; -use yazi_shared::{emit, event::Exec, fs::Url, render, Layer}; +use yazi_shared::{emit, event::Cmd, fs::Url, render, Layer}; use crate::manager::Manager; @@ -8,8 +8,8 @@ pub struct Opt { url: Option, } -impl From for Opt { - fn from(mut e: Exec) -> Self { Self { url: e.take_first().map(Url::from) } } +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { url: c.take_first().map(Url::from) } } } impl From> for Opt { fn from(url: Option) -> Self { Self { url } } @@ -19,7 +19,7 @@ impl Manager { #[inline] pub fn _hover(url: Option) { emit!(Call( - Exec::call("hover", url.map_or_else(Vec::new, |u| vec![u.to_string()])), + Cmd::args("hover", url.map_or_else(Vec::new, |u| vec![u.to_string()])), Layer::Manager )); } diff --git a/yazi-core/src/manager/commands/link.rs b/yazi-core/src/manager/commands/link.rs index 747dde1c8..e6c72ce98 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::Exec; +use yazi_shared::event::Cmd; use crate::{manager::Manager, tasks::Tasks}; @@ -7,9 +7,9 @@ pub struct Opt { force: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { - Self { relative: e.named.contains_key("relative"), force: e.named.contains_key("force") } +impl From for Opt { + fn from(c: Cmd) -> Self { + Self { relative: c.named.contains_key("relative"), force: c.named.contains_key("force") } } } diff --git a/yazi-core/src/manager/commands/open.rs b/yazi-core/src/manager/commands/open.rs index ff4670290..2bbd211e8 100644 --- a/yazi-core/src/manager/commands/open.rs +++ b/yazi-core/src/manager/commands/open.rs @@ -3,7 +3,7 @@ use std::ffi::OsString; use tracing::error; use yazi_config::{popup::SelectCfg, ARGS, OPEN}; use yazi_plugin::isolate; -use yazi_shared::{emit, event::{EventQuit, Exec}, fs::{File, Url}, Layer, MIME_DIR}; +use yazi_shared::{emit, event::{Cmd, EventQuit}, fs::{File, Url}, Layer, MIME_DIR}; use crate::{manager::Manager, select::Select, tasks::Tasks}; @@ -12,11 +12,11 @@ pub struct Opt { interactive: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - targets: e.take_data().unwrap_or_default(), - interactive: e.named.contains_key("interactive"), + targets: c.take_data().unwrap_or_default(), + interactive: c.named.contains_key("interactive"), } } } @@ -60,7 +60,7 @@ impl Manager { #[inline] pub fn _open_do(interactive: bool, targets: Vec<(Url, Option)>) { emit!(Call( - Exec::call("open_do", vec![]).with_bool("interactive", interactive).with_data(targets), + Cmd::new("open_do").with_bool("interactive", interactive).with_data(targets), Layer::Manager )); } diff --git a/yazi-core/src/manager/commands/paste.rs b/yazi-core/src/manager/commands/paste.rs index 40fb37435..256ffe587 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::Exec; +use yazi_shared::event::Cmd; use crate::{manager::Manager, tasks::Tasks}; @@ -7,9 +7,9 @@ pub struct Opt { follow: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { - Self { force: e.named.contains_key("force"), follow: e.named.contains_key("follow") } +impl From for Opt { + fn from(c: Cmd) -> Self { + Self { force: c.named.contains_key("force"), follow: c.named.contains_key("follow") } } } diff --git a/yazi-core/src/manager/commands/peek.rs b/yazi-core/src/manager/commands/peek.rs index 73bca19c3..908a0bcf0 100644 --- a/yazi-core/src/manager/commands/peek.rs +++ b/yazi-core/src/manager/commands/peek.rs @@ -1,4 +1,4 @@ -use yazi_shared::{emit, event::Exec, fs::Url, render, Layer}; +use yazi_shared::{emit, event::Cmd, fs::Url, render, Layer}; use crate::manager::Manager; @@ -10,13 +10,13 @@ pub struct Opt { upper_bound: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - skip: e.take_first().and_then(|s| s.parse().ok()), - force: e.named.contains_key("force"), - only_if: e.take_name("only-if").map(Url::from), - upper_bound: e.named.contains_key("upper-bound"), + skip: c.take_first().and_then(|s| s.parse().ok()), + force: c.named.contains_key("force"), + only_if: c.take_name("only-if").map(Url::from), + upper_bound: c.named.contains_key("upper-bound"), } } } @@ -27,7 +27,7 @@ impl From for Opt { impl Manager { #[inline] pub fn _peek(force: bool) { - emit!(Call(Exec::call("peek", vec![]).with_bool("force", force), Layer::Manager)); + emit!(Call(Cmd::new("peek").with_bool("force", force), Layer::Manager)); } pub fn peek(&mut self, opt: impl Into) { diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index c6e4c16cc..30119aa5e 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -1,5 +1,5 @@ use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::{EventQuit, Exec}}; +use yazi_shared::{emit, event::{Cmd, EventQuit}}; use crate::{input::Input, manager::Manager, tasks::Tasks}; @@ -10,8 +10,8 @@ pub struct Opt { impl From<()> for Opt { fn from(_: ()) -> Self { Self::default() } } -impl From for Opt { - fn from(e: Exec) -> Self { Self { no_cwd_file: e.named.contains_key("no-cwd-file") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { no_cwd_file: c.named.contains_key("no-cwd-file") } } } impl Manager { diff --git a/yazi-core/src/manager/commands/refresh.rs b/yazi-core/src/manager/commands/refresh.rs index 3f45893cd..5af0999e9 100644 --- a/yazi-core/src/manager/commands/refresh.rs +++ b/yazi-core/src/manager/commands/refresh.rs @@ -1,16 +1,16 @@ use std::env; -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Cmd, Layer}; use crate::{manager::Manager, tasks::Tasks}; impl Manager { #[inline] pub fn _refresh() { - emit!(Call(Exec::call("refresh", vec![]), Layer::Manager)); + emit!(Call(Cmd::new("refresh"), Layer::Manager)); } - pub fn refresh(&mut self, _: Exec, tasks: &Tasks) { + pub fn refresh(&mut self, _: Cmd, 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 c6904bdb9..bc411c549 100644 --- a/yazi-core/src/manager/commands/remove.rs +++ b/yazi-core/src/manager/commands/remove.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::{manager::Manager, tasks::Tasks}; @@ -7,11 +7,11 @@ pub struct Opt { permanently: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { +impl From for Opt { + fn from(c: Cmd) -> Self { Self { - force: e.named.contains_key("force"), - permanently: e.named.contains_key("permanently"), + force: c.named.contains_key("force"), + permanently: c.named.contains_key("permanently"), } } } diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index fd27295a5..b62df60e1 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -5,7 +5,7 @@ use tokio::{fs::{self, OpenOptions}, io::{stdin, AsyncReadExt, AsyncWriteExt}}; use yazi_config::{popup::InputCfg, OPEN, PREVIEW}; use yazi_plugin::external::{self, ShellOpt}; use yazi_scheduler::{Scheduler, BLOCKER}; -use yazi_shared::{event::Exec, fs::{max_common_root, File, FilesOp, Url}, term::Term, Defer}; +use yazi_shared::{event::Cmd, fs::{max_common_root, File, FilesOp, Url}, term::Term, Defer}; use crate::{input::Input, manager::Manager}; @@ -15,12 +15,12 @@ pub struct Opt { cursor: String, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - force: e.named.contains_key("force"), - empty: e.take_name("empty").unwrap_or_default(), - cursor: e.take_name("cursor").unwrap_or_default(), + force: c.named.contains_key("force"), + empty: c.take_name("empty").unwrap_or_default(), + cursor: c.take_name("cursor").unwrap_or_default(), } } } diff --git a/yazi-core/src/manager/commands/seek.rs b/yazi-core/src/manager/commands/seek.rs index 3395fefd9..ef7f6e3aa 100644 --- a/yazi-core/src/manager/commands/seek.rs +++ b/yazi-core/src/manager/commands/seek.rs @@ -1,6 +1,6 @@ use yazi_config::PLUGIN; use yazi_plugin::isolate; -use yazi_shared::{event::Exec, render, MIME_DIR}; +use yazi_shared::{event::Cmd, render, MIME_DIR}; use crate::manager::Manager; @@ -9,9 +9,9 @@ pub struct Opt { units: i16, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { units: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { units: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } } } @@ -34,6 +34,6 @@ impl Manager { }; let opt = opt.into() as Opt; - isolate::seek_sync(&previewer.exec, hovered.clone(), opt.units); + isolate::seek_sync(&previewer.cmd, hovered.clone(), opt.units); } } diff --git a/yazi-core/src/manager/commands/suspend.rs b/yazi-core/src/manager/commands/suspend.rs index 62481eb2d..429d11e8f 100644 --- a/yazi-core/src/manager/commands/suspend.rs +++ b/yazi-core/src/manager/commands/suspend.rs @@ -1,10 +1,10 @@ use yazi_scheduler::Scheduler; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::manager::Manager; impl Manager { - pub fn suspend(&mut self, _: Exec) { + pub fn suspend(&mut self, _: Cmd) { #[cfg(unix)] tokio::spawn(async move { Scheduler::app_stop().await; diff --git a/yazi-core/src/manager/commands/tab_close.rs b/yazi-core/src/manager/commands/tab_close.rs index f74abce16..7ae538fb3 100644 --- a/yazi-core/src/manager/commands/tab_close.rs +++ b/yazi-core/src/manager/commands/tab_close.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::manager::Tabs; @@ -6,9 +6,9 @@ pub struct Opt { idx: usize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { idx: e.take_first().and_then(|i| i.parse().ok()).unwrap_or(0) } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { idx: c.take_first().and_then(|i| i.parse().ok()).unwrap_or(0) } } } diff --git a/yazi-core/src/manager/commands/tab_create.rs b/yazi-core/src/manager/commands/tab_create.rs index 43dfb5beb..5085573d0 100644 --- a/yazi-core/src/manager/commands/tab_create.rs +++ b/yazi-core/src/manager/commands/tab_create.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, fs::Url, render}; +use yazi_shared::{event::Cmd, fs::Url, render}; use crate::{manager::Tabs, tab::Tab}; @@ -9,12 +9,12 @@ pub struct Opt { current: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - let mut opt = Self { url: None, current: e.named.contains_key("current") }; +impl From for Opt { + fn from(mut c: Cmd) -> Self { + let mut opt = Self { url: None, current: c.named.contains_key("current") }; if !opt.current { - opt.url = Some(e.take_first().map_or_else(|| Url::from("."), Url::from)); + opt.url = Some(c.take_first().map_or_else(|| Url::from("."), Url::from)); } opt } diff --git a/yazi-core/src/manager/commands/tab_swap.rs b/yazi-core/src/manager/commands/tab_swap.rs index 5a148d0d6..2a167aa25 100644 --- a/yazi-core/src/manager/commands/tab_swap.rs +++ b/yazi-core/src/manager/commands/tab_swap.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::manager::Tabs; @@ -6,9 +6,9 @@ pub struct Opt { step: isize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } } } diff --git a/yazi-core/src/manager/commands/tab_switch.rs b/yazi-core/src/manager/commands/tab_switch.rs index 83f644a38..215a32cd2 100644 --- a/yazi-core/src/manager/commands/tab_switch.rs +++ b/yazi-core/src/manager/commands/tab_switch.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::manager::Tabs; @@ -7,11 +7,11 @@ pub struct Opt { relative: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0), - relative: e.named.contains_key("relative"), + step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0), + relative: c.named.contains_key("relative"), } } } diff --git a/yazi-core/src/manager/commands/update_files.rs b/yazi-core/src/manager/commands/update_files.rs index 29be95b5e..120505c88 100644 --- a/yazi-core/src/manager/commands/update_files.rs +++ b/yazi-core/src/manager/commands/update_files.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use yazi_shared::{event::Exec, fs::FilesOp, render}; +use yazi_shared::{event::Cmd, fs::FilesOp, render}; use crate::{folder::Folder, manager::Manager, tab::Tab, tasks::Tasks}; @@ -8,12 +8,10 @@ pub struct Opt { op: FilesOp, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut e: Exec) -> Result { - Ok(Self { op: e.take_data().ok_or(())? }) - } + fn try_from(mut c: Cmd) -> Result { Ok(Self { op: c.take_data().ok_or(())? }) } } impl Manager { diff --git a/yazi-core/src/manager/commands/update_mimetype.rs b/yazi-core/src/manager/commands/update_mimetype.rs index 81ef9e9b3..4ad038e7a 100644 --- a/yazi-core/src/manager/commands/update_mimetype.rs +++ b/yazi-core/src/manager/commands/update_mimetype.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use yazi_plugin::ValueSendable; -use yazi_shared::{event::Exec, fs::Url, render}; +use yazi_shared::{event::Cmd, fs::Url, render}; use crate::{manager::Manager, tasks::Tasks}; @@ -9,11 +9,11 @@ pub struct Opt { data: ValueSendable, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut e: Exec) -> Result { - Ok(Self { data: e.take_data().ok_or(())? }) + fn try_from(mut c: Cmd) -> Result { + Ok(Self { data: c.take_data().ok_or(())? }) } } diff --git a/yazi-core/src/manager/commands/update_paged.rs b/yazi-core/src/manager/commands/update_paged.rs index 38c0fd6b6..c3c16498b 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::{emit, event::Exec, fs::Url, Layer}; +use yazi_shared::{emit, event::Cmd, fs::Url, Layer}; use crate::{manager::Manager, tasks::Tasks}; @@ -8,11 +8,11 @@ pub struct Opt { only_if: Option, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - page: e.take_first().and_then(|s| s.parse().ok()), - only_if: e.take_name("only-if").map(Url::from), + page: c.take_first().and_then(|s| s.parse().ok()), + only_if: c.take_name("only-if").map(Url::from), } } } @@ -24,13 +24,13 @@ impl From<()> for Opt { impl Manager { #[inline] pub fn _update_paged() { - emit!(Call(Exec::call("update_paged", vec![]), Layer::Manager)); + emit!(Call(Cmd::new("update_paged"), Layer::Manager)); } #[inline] pub fn _update_paged_by(page: usize, only_if: &Url) { emit!(Call( - Exec::call("update_paged", vec![page.to_string()]).with("only-if", only_if.to_string()), + Cmd::args("update_paged", vec![page.to_string()]).with("only-if", only_if.to_string()), Layer::Manager )); } diff --git a/yazi-core/src/manager/commands/yank.rs b/yazi-core/src/manager/commands/yank.rs index eae09b72c..7f1209a58 100644 --- a/yazi-core/src/manager/commands/yank.rs +++ b/yazi-core/src/manager/commands/yank.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::manager::Manager; @@ -6,8 +6,8 @@ pub struct Opt { cut: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { cut: e.named.contains_key("cut") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { cut: c.named.contains_key("cut") } } } impl Manager { diff --git a/yazi-core/src/select/commands/arrow.rs b/yazi-core/src/select/commands/arrow.rs index 067b417cc..1373e4f29 100644 --- a/yazi-core/src/select/commands/arrow.rs +++ b/yazi-core/src/select/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::select::Select; @@ -6,9 +6,9 @@ pub struct Opt { step: isize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } } } diff --git a/yazi-core/src/select/commands/close.rs b/yazi-core/src/select/commands/close.rs index 0a5acbf07..b4c60c8ae 100644 --- a/yazi-core/src/select/commands/close.rs +++ b/yazi-core/src/select/commands/close.rs @@ -1,5 +1,5 @@ use anyhow::anyhow; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::select::Select; @@ -7,8 +7,8 @@ pub struct Opt { submit: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { submit: e.named.contains_key("submit") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { submit: c.named.contains_key("submit") } } } impl From for Opt { fn from(submit: bool) -> Self { Self { submit } } diff --git a/yazi-core/src/select/commands/show.rs b/yazi-core/src/select/commands/show.rs index 181ffd61c..85c79878c 100644 --- a/yazi-core/src/select/commands/show.rs +++ b/yazi-core/src/select/commands/show.rs @@ -1,7 +1,7 @@ use anyhow::Result; use tokio::sync::oneshot; use yazi_config::popup::SelectCfg; -use yazi_shared::{emit, event::Exec, render, term::Term, Layer}; +use yazi_shared::{emit, event::Cmd, render, term::Term, Layer}; use crate::select::Select; @@ -10,16 +10,16 @@ pub struct Opt { tx: oneshot::Sender>, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut e: Exec) -> Result { e.take_data().ok_or(()) } + fn try_from(mut c: Cmd) -> Result { c.take_data().ok_or(()) } } impl Select { pub async fn _show(cfg: SelectCfg) -> Result { let (tx, rx) = oneshot::channel(); - emit!(Call(Exec::call("show", vec![]).with_data(Opt { cfg, tx }), Layer::Select)); + emit!(Call(Cmd::new("show").with_data(Opt { cfg, tx }), Layer::Select)); rx.await.unwrap_or_else(|_| Term::goodbye(|| false)) } diff --git a/yazi-core/src/tab/commands/arrow.rs b/yazi-core/src/tab/commands/arrow.rs index 5d2ccf3c7..be846ea53 100644 --- a/yazi-core/src/tab/commands/arrow.rs +++ b/yazi-core/src/tab/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::{manager::Manager, tab::Tab, Step}; @@ -6,9 +6,9 @@ pub struct Opt { step: Step, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or_default() } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or_default() } } } diff --git a/yazi-core/src/tab/commands/backstack.rs b/yazi-core/src/tab/commands/backstack.rs index 4e8b7f961..8456233d3 100644 --- a/yazi-core/src/tab/commands/backstack.rs +++ b/yazi-core/src/tab/commands/backstack.rs @@ -1,4 +1,4 @@ -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::tab::Tab; @@ -6,8 +6,8 @@ pub struct Opt; impl From<()> for Opt { fn from(_: ()) -> Self { Self } } -impl From for Opt { - fn from(_: Exec) -> Self { Self } +impl From for Opt { + fn from(_: Cmd) -> Self { Self } } impl Tab { diff --git a/yazi-core/src/tab/commands/cd.rs b/yazi-core/src/tab/commands/cd.rs index 5ea4c1987..f563def72 100644 --- a/yazi-core/src/tab/commands/cd.rs +++ b/yazi-core/src/tab/commands/cd.rs @@ -3,7 +3,7 @@ use std::{mem, time::Duration}; use tokio::{fs, pin}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::Exec, fs::{expand_path, Url}, render, Debounce, InputError, Layer}; +use yazi_shared::{emit, event::Cmd, fs::{expand_path, Url}, render, Debounce, InputError, Layer}; use crate::{completion::Completion, input::Input, manager::Manager, tab::Tab}; @@ -12,14 +12,14 @@ pub struct Opt { interactive: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - let mut target = Url::from(e.take_first().unwrap_or_default()); +impl From for Opt { + fn from(mut c: Cmd) -> Self { + let mut target = Url::from(c.take_first().unwrap_or_default()); if target.is_regular() { target.set_path(expand_path(&target)) } - Self { target, interactive: e.named.contains_key("interactive") } + Self { target, interactive: c.named.contains_key("interactive") } } } impl From for Opt { @@ -29,7 +29,7 @@ impl From for Opt { impl Tab { #[inline] pub fn _cd(target: &Url) { - emit!(Call(Exec::call("cd", vec![target.to_string()]), Layer::Manager)); + emit!(Call(Cmd::args("cd", vec![target.to_string()]), Layer::Manager)); } pub fn cd(&mut self, opt: impl Into) { diff --git a/yazi-core/src/tab/commands/copy.rs b/yazi-core/src/tab/commands/copy.rs index b9ede0cac..a629d9e76 100644 --- a/yazi-core/src/tab/commands/copy.rs +++ b/yazi-core/src/tab/commands/copy.rs @@ -1,6 +1,6 @@ use std::ffi::{OsStr, OsString}; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::{tab::Tab, CLIPBOARD}; @@ -8,8 +8,8 @@ pub struct Opt { type_: String, } -impl From for Opt { - fn from(mut e: Exec) -> Self { Self { type_: e.take_first().unwrap_or_default() } } +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { type_: c.take_first().unwrap_or_default() } } } impl Tab { diff --git a/yazi-core/src/tab/commands/enter.rs b/yazi-core/src/tab/commands/enter.rs index 6c3391dd4..b01f4579e 100644 --- a/yazi-core/src/tab/commands/enter.rs +++ b/yazi-core/src/tab/commands/enter.rs @@ -1,6 +1,6 @@ use std::mem; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::{manager::Manager, tab::Tab}; @@ -8,8 +8,8 @@ pub struct Opt; impl From<()> for Opt { fn from(_: ()) -> Self { Self } } -impl From for Opt { - fn from(_: Exec) -> Self { Self } +impl From for Opt { + fn from(_: Cmd) -> Self { Self } } impl Tab { diff --git a/yazi-core/src/tab/commands/escape.rs b/yazi-core/src/tab/commands/escape.rs index ce72a1ccd..152b778eb 100644 --- a/yazi-core/src/tab/commands/escape.rs +++ b/yazi-core/src/tab/commands/escape.rs @@ -1,5 +1,5 @@ use bitflags::bitflags; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tab::{Mode, Tab}; @@ -13,9 +13,9 @@ bitflags! { } } -impl From for Opt { - fn from(e: Exec) -> Self { - e.named.iter().fold(Opt::empty(), |acc, (k, _)| match k.as_str() { +impl From for Opt { + fn from(c: Cmd) -> Self { + c.named.iter().fold(Opt::empty(), |acc, (k, _)| match k.as_str() { "all" => Self::all(), "find" => acc | Self::FIND, "visual" => acc | Self::VISUAL, diff --git a/yazi-core/src/tab/commands/filter.rs b/yazi-core/src/tab/commands/filter.rs index 544ac6f95..c2e21faf9 100644 --- a/yazi-core/src/tab/commands/filter.rs +++ b/yazi-core/src/tab/commands/filter.rs @@ -3,7 +3,7 @@ use std::time::Duration; use tokio::pin; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::Exec, render, Debounce, InputError, Layer}; +use yazi_shared::{emit, event::Cmd, render, Debounce, InputError, Layer}; use crate::{folder::{Filter, FilterCase}, input::Input, manager::Manager, tab::Tab}; @@ -14,12 +14,12 @@ pub struct Opt { pub done: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - query: e.take_first().unwrap_or_default(), - case: FilterCase::from(&e), - done: e.named.contains_key("done"), + query: c.take_first().unwrap_or_default(), + case: FilterCase::from(&c), + done: c.named.contains_key("done"), } } } @@ -40,7 +40,7 @@ impl Tab { }; emit!(Call( - Exec::call("filter_do", vec![s]) + Cmd::args("filter_do", vec![s]) .with_bool("smart", opt.case == FilterCase::Smart) .with_bool("insensitive", opt.case == FilterCase::Insensitive) .with_bool("done", done), diff --git a/yazi-core/src/tab/commands/find.rs b/yazi-core/src/tab/commands/find.rs index 9dea52f99..7da0fc279 100644 --- a/yazi-core/src/tab/commands/find.rs +++ b/yazi-core/src/tab/commands/find.rs @@ -3,7 +3,7 @@ use std::time::Duration; use tokio::pin; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use yazi_config::popup::InputCfg; -use yazi_shared::{emit, event::Exec, render, Debounce, InputError, Layer}; +use yazi_shared::{emit, event::Cmd, render, Debounce, InputError, Layer}; use crate::{folder::FilterCase, input::Input, tab::{Finder, Tab}}; @@ -13,12 +13,12 @@ pub struct Opt { case: FilterCase, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - query: e.take_first(), - prev: e.named.contains_key("previous"), - case: FilterCase::from(&e), + query: c.take_first(), + prev: c.named.contains_key("previous"), + case: FilterCase::from(&c), } } } @@ -27,8 +27,8 @@ pub struct ArrowOpt { prev: bool, } -impl From for ArrowOpt { - fn from(e: Exec) -> Self { Self { prev: e.named.contains_key("previous") } } +impl From for ArrowOpt { + fn from(c: Cmd) -> Self { Self { prev: c.named.contains_key("previous") } } } impl Tab { @@ -42,7 +42,7 @@ impl Tab { while let Some(Ok(s)) | Some(Err(InputError::Typed(s))) = rx.next().await { emit!(Call( - Exec::call("find_do", vec![s]) + Cmd::args("find_do", vec![s]) .with_bool("previous", opt.prev) .with_bool("smart", opt.case == FilterCase::Smart) .with_bool("insensitive", opt.case == FilterCase::Insensitive), diff --git a/yazi-core/src/tab/commands/hidden.rs b/yazi-core/src/tab/commands/hidden.rs index 84a3e93fe..93c2e3b4d 100644 --- a/yazi-core/src/tab/commands/hidden.rs +++ b/yazi-core/src/tab/commands/hidden.rs @@ -1,10 +1,10 @@ -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::{manager::Manager, tab::Tab}; impl Tab { - pub fn hidden(&mut self, e: Exec) { - self.conf.show_hidden = match e.args.first().map(|s| s.as_str()) { + pub fn hidden(&mut self, c: Cmd) { + self.conf.show_hidden = match c.args.first().map(|s| s.as_str()) { Some("show") => true, Some("hide") => false, _ => !self.conf.show_hidden, diff --git a/yazi-core/src/tab/commands/jump.rs b/yazi-core/src/tab/commands/jump.rs index e88ad072d..c282205d5 100644 --- a/yazi-core/src/tab/commands/jump.rs +++ b/yazi-core/src/tab/commands/jump.rs @@ -1,6 +1,6 @@ use yazi_plugin::external::{self, FzfOpt, ZoxideOpt}; use yazi_scheduler::{Scheduler, BLOCKER}; -use yazi_shared::{event::Exec, fs::ends_with_slash, Defer}; +use yazi_shared::{event::Cmd, fs::ends_with_slash, Defer}; use crate::tab::Tab; @@ -15,10 +15,10 @@ pub enum OptType { Zoxide, } -impl From for Opt { - fn from(e: Exec) -> Self { +impl From for Opt { + fn from(c: Cmd) -> Self { Self { - type_: match e.args.first().map(|s| s.as_str()) { + type_: match c.args.first().map(|s| s.as_str()) { Some("fzf") => OptType::Fzf, Some("zoxide") => OptType::Zoxide, _ => OptType::None, diff --git a/yazi-core/src/tab/commands/leave.rs b/yazi-core/src/tab/commands/leave.rs index e7c5519cb..c98d4236c 100644 --- a/yazi-core/src/tab/commands/leave.rs +++ b/yazi-core/src/tab/commands/leave.rs @@ -1,6 +1,6 @@ use std::mem; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::{manager::Manager, tab::Tab}; @@ -8,8 +8,8 @@ pub struct Opt; impl From<()> for Opt { fn from(_: ()) -> Self { Self } } -impl From for Opt { - fn from(_: Exec) -> Self { Self } +impl From for Opt { + fn from(_: Cmd) -> Self { Self } } impl Tab { diff --git a/yazi-core/src/tab/commands/linemode.rs b/yazi-core/src/tab/commands/linemode.rs index b3fb53848..b4852200f 100644 --- a/yazi-core/src/tab/commands/linemode.rs +++ b/yazi-core/src/tab/commands/linemode.rs @@ -1,15 +1,15 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tab::Tab; impl Tab { - pub fn linemode(&mut self, mut e: Exec) { - render!(self.conf.patch(|c| { - let Some(mode) = e.take_first() else { + pub fn linemode(&mut self, mut c: Cmd) { + render!(self.conf.patch(|new| { + let Some(mode) = c.take_first() else { return; }; if !mode.is_empty() && mode.len() <= 20 { - c.linemode = mode; + new.linemode = mode; } })); } diff --git a/yazi-core/src/tab/commands/preview.rs b/yazi-core/src/tab/commands/preview.rs index a67e2d97f..8c1b68a22 100644 --- a/yazi-core/src/tab/commands/preview.rs +++ b/yazi-core/src/tab/commands/preview.rs @@ -1,5 +1,5 @@ use yazi_plugin::utils::PreviewLock; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tab::Tab; @@ -7,11 +7,11 @@ pub struct Opt { lock: PreviewLock, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut e: Exec) -> Result { - Ok(Self { lock: e.take_data().ok_or(())? }) + fn try_from(mut c: Cmd) -> Result { + Ok(Self { lock: c.take_data().ok_or(())? }) } } diff --git a/yazi-core/src/tab/commands/reveal.rs b/yazi-core/src/tab/commands/reveal.rs index bb80fed35..da932aa06 100644 --- a/yazi-core/src/tab/commands/reveal.rs +++ b/yazi-core/src/tab/commands/reveal.rs @@ -1,4 +1,4 @@ -use yazi_shared::{emit, event::Exec, fs::{expand_path, File, FilesOp, Url}, Layer}; +use yazi_shared::{emit, event::Cmd, fs::{expand_path, File, FilesOp, Url}, Layer}; use crate::{manager::Manager, tab::Tab}; @@ -6,9 +6,9 @@ pub struct Opt { target: Url, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - let mut target = Url::from(e.take_first().unwrap_or_default()); +impl From for Opt { + fn from(mut c: Cmd) -> Self { + let mut target = Url::from(c.take_first().unwrap_or_default()); if target.is_regular() { target.set_path(expand_path(&target)) } @@ -23,7 +23,7 @@ impl From for Opt { impl Tab { #[inline] pub fn _reveal(target: &Url) { - emit!(Call(Exec::call("reveal", vec![target.to_string()]), Layer::Manager)); + emit!(Call(Cmd::args("reveal", vec![target.to_string()]), Layer::Manager)); } pub fn reveal(&mut self, opt: impl Into) { diff --git a/yazi-core/src/tab/commands/search.rs b/yazi-core/src/tab/commands/search.rs index ad5d2166b..ae8c4640a 100644 --- a/yazi-core/src/tab/commands/search.rs +++ b/yazi-core/src/tab/commands/search.rs @@ -5,7 +5,7 @@ use tokio::pin; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use yazi_config::popup::InputCfg; use yazi_plugin::external; -use yazi_shared::{event::Exec, fs::FilesOp, render}; +use yazi_shared::{event::Cmd, fs::FilesOp, render}; use crate::{input::Input, manager::Manager, tab::Tab}; @@ -41,8 +41,8 @@ pub struct Opt { pub type_: OptType, } -impl From for Opt { - fn from(mut e: Exec) -> Self { Self { type_: e.take_first().unwrap_or_default().into() } } +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { type_: c.take_first().unwrap_or_default().into() } } } impl Tab { diff --git a/yazi-core/src/tab/commands/select.rs b/yazi-core/src/tab/commands/select.rs index d25c46368..6e28dd1a5 100644 --- a/yazi-core/src/tab/commands/select.rs +++ b/yazi-core/src/tab/commands/select.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tab::Tab; @@ -6,10 +6,10 @@ pub struct Opt { state: Option, } -impl From for Opt { - fn from(e: Exec) -> Self { +impl From for Opt { + fn from(c: Cmd) -> Self { Self { - state: match e.named.get("state").map(|s| s.as_str()) { + state: match c.named.get("state").map(|s| s.as_str()) { Some("true") => Some(true), Some("false") => Some(false), _ => None, diff --git a/yazi-core/src/tab/commands/shell.rs b/yazi-core/src/tab/commands/shell.rs index 8f42a3674..d5d6b6eed 100644 --- a/yazi-core/src/tab/commands/shell.rs +++ b/yazi-core/src/tab/commands/shell.rs @@ -1,20 +1,20 @@ use yazi_config::{open::Opener, popup::InputCfg}; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::{input::Input, tab::Tab, tasks::Tasks}; pub struct Opt { - cmd: String, + exec: String, block: bool, confirm: bool, } -impl From for Opt { - fn from(mut e: Exec) -> Self { +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { - cmd: e.take_first().unwrap_or_default(), - block: e.named.contains_key("block"), - confirm: e.named.contains_key("confirm"), + exec: c.take_first().unwrap_or_default(), + block: c.named.contains_key("block"), + confirm: c.named.contains_key("confirm"), } } } @@ -25,16 +25,16 @@ impl Tab { let selected: Vec<_> = self.selected().into_iter().map(|f| f.url()).collect(); tokio::spawn(async move { - if !opt.confirm || opt.cmd.is_empty() { - let mut result = Input::_show(InputCfg::shell(opt.block).with_value(opt.cmd)); + if !opt.confirm || opt.exec.is_empty() { + let mut result = Input::_show(InputCfg::shell(opt.block).with_value(opt.exec)); match result.recv().await { - Some(Ok(e)) => opt.cmd = e, + Some(Ok(e)) => opt.exec = e, _ => return, } } Tasks::_open(selected, Opener { - exec: opt.cmd, + exec: opt.exec, block: opt.block, orphan: false, desc: Default::default(), diff --git a/yazi-core/src/tab/commands/sort.rs b/yazi-core/src/tab/commands/sort.rs index 70586e0bb..bdf82d423 100644 --- a/yazi-core/src/tab/commands/sort.rs +++ b/yazi-core/src/tab/commands/sort.rs @@ -1,18 +1,18 @@ use std::str::FromStr; use yazi_config::manager::SortBy; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::{manager::Manager, tab::Tab, tasks::Tasks}; impl Tab { - pub fn sort(&mut self, e: Exec, tasks: &Tasks) { - if let Some(by) = e.args.first() { + pub fn sort(&mut self, c: Cmd, tasks: &Tasks) { + if let Some(by) = c.args.first() { self.conf.sort_by = SortBy::from_str(by).unwrap_or_default(); } - self.conf.sort_sensitive = e.named.contains_key("sensitive"); - self.conf.sort_reverse = e.named.contains_key("reverse"); - self.conf.sort_dir_first = e.named.contains_key("dir-first"); + self.conf.sort_sensitive = c.named.contains_key("sensitive"); + self.conf.sort_reverse = c.named.contains_key("reverse"); + self.conf.sort_dir_first = c.named.contains_key("dir-first"); self.apply_files_attrs(); Manager::_update_paged(); diff --git a/yazi-core/src/tab/commands/visual_mode.rs b/yazi-core/src/tab/commands/visual_mode.rs index 8fb8ea70e..8e19ace52 100644 --- a/yazi-core/src/tab/commands/visual_mode.rs +++ b/yazi-core/src/tab/commands/visual_mode.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tab::{Mode, Tab}; @@ -8,8 +8,8 @@ pub struct Opt { unset: bool, } -impl From for Opt { - fn from(e: Exec) -> Self { Self { unset: e.named.contains_key("unset") } } +impl From for Opt { + fn from(c: Cmd) -> Self { Self { unset: c.named.contains_key("unset") } } } impl Tab { diff --git a/yazi-core/src/tab/preview.rs b/yazi-core/src/tab/preview.rs index 4db88e1b4..60fa3ddfe 100644 --- a/yazi-core/src/tab/preview.rs +++ b/yazi-core/src/tab/preview.rs @@ -32,9 +32,9 @@ impl Preview { self.abort(); if previewer.sync { - isolate::peek_sync(&previewer.exec, file, self.skip); + isolate::peek_sync(&previewer.cmd, file, self.skip); } else { - self.previewer_ct = Some(isolate::peek(&previewer.exec, file, self.skip)); + self.previewer_ct = Some(isolate::peek(&previewer.cmd, file, self.skip)); } } diff --git a/yazi-core/src/tasks/commands/arrow.rs b/yazi-core/src/tasks/commands/arrow.rs index aaf9bbe13..763c7e433 100644 --- a/yazi-core/src/tasks/commands/arrow.rs +++ b/yazi-core/src/tasks/commands/arrow.rs @@ -1,4 +1,4 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tasks::Tasks; @@ -6,9 +6,9 @@ pub struct Opt { step: isize, } -impl From for Opt { - fn from(mut e: Exec) -> Self { - Self { step: e.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } +impl From for Opt { + fn from(mut c: Cmd) -> Self { + Self { step: c.take_first().and_then(|s| s.parse().ok()).unwrap_or(0) } } } diff --git a/yazi-core/src/tasks/commands/cancel.rs b/yazi-core/src/tasks/commands/cancel.rs index 31d126eb4..a7e6b4faa 100644 --- a/yazi-core/src/tasks/commands/cancel.rs +++ b/yazi-core/src/tasks/commands/cancel.rs @@ -1,9 +1,9 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tasks::Tasks; impl Tasks { - pub fn cancel(&mut self, _: Exec) { + pub fn cancel(&mut self, _: Cmd) { let id = self.scheduler.running.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 f19cd47b1..739faabd4 100644 --- a/yazi-core/src/tasks/commands/inspect.rs +++ b/yazi-core/src/tasks/commands/inspect.rs @@ -3,12 +3,12 @@ use std::io::{stdout, Write}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use tokio::{io::{stdin, AsyncReadExt}, select, sync::mpsc, time}; use yazi_scheduler::{Scheduler, BLOCKER}; -use yazi_shared::{event::Exec, term::Term, Defer}; +use yazi_shared::{event::Cmd, term::Term, Defer}; use crate::tasks::Tasks; impl Tasks { - pub fn inspect(&self, _: Exec) { + pub fn inspect(&self, _: Cmd) { let Some(id) = self.scheduler.running.lock().get_id(self.cursor) else { return; }; diff --git a/yazi-core/src/tasks/commands/open.rs b/yazi-core/src/tasks/commands/open.rs index 6ec3f63b5..ad7c6b49b 100644 --- a/yazi-core/src/tasks/commands/open.rs +++ b/yazi-core/src/tasks/commands/open.rs @@ -1,5 +1,5 @@ use yazi_config::open::Opener; -use yazi_shared::{emit, event::Exec, fs::Url, Layer}; +use yazi_shared::{emit, event::Cmd, fs::Url, Layer}; use crate::tasks::Tasks; @@ -8,15 +8,15 @@ pub struct Opt { opener: Opener, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut e: Exec) -> Result { e.take_data().ok_or(()) } + fn try_from(mut c: Cmd) -> Result { c.take_data().ok_or(()) } } impl Tasks { pub fn _open(targets: Vec, opener: Opener) { - emit!(Call(Exec::call("open", vec![]).with_data(Opt { targets, opener }), Layer::Tasks)); + emit!(Call(Cmd::new("open").with_data(Opt { targets, opener }), Layer::Tasks)); } pub fn open(&mut self, opt: impl TryInto) { diff --git a/yazi-core/src/tasks/commands/toggle.rs b/yazi-core/src/tasks/commands/toggle.rs index 391ee0729..88a89fcc4 100644 --- a/yazi-core/src/tasks/commands/toggle.rs +++ b/yazi-core/src/tasks/commands/toggle.rs @@ -1,11 +1,11 @@ -use yazi_shared::{event::Exec, render}; +use yazi_shared::{event::Cmd, render}; use crate::tasks::Tasks; pub struct Opt; -impl From for Opt { - fn from(_: Exec) -> Self { Self } +impl From for Opt { + fn from(_: Cmd) -> Self { Self } } impl From<()> for Opt { fn from(_: ()) -> Self { Self } diff --git a/yazi-core/src/tasks/tasks.rs b/yazi-core/src/tasks/tasks.rs index d8dfc91fe..4d71677b4 100644 --- a/yazi-core/src/tasks/tasks.rs +++ b/yazi-core/src/tasks/tasks.rs @@ -5,7 +5,7 @@ use tracing::debug; use yazi_config::{manager::SortBy, open::Opener, plugin::{PluginRule, MAX_PRELOADERS}, popup::InputCfg, OPEN, PLUGIN}; use yazi_plugin::ValueSendable; use yazi_scheduler::{Scheduler, TaskSummary}; -use yazi_shared::{emit, event::Exec, fs::{File, Url}, term::Term, Layer, MIME_DIR}; +use yazi_shared::{emit, event::Cmd, fs::{File, Url}, term::Term, Layer, MIME_DIR}; use super::{TasksProgress, TASKS_PADDING, TASKS_PERCENT}; use crate::{folder::Files, input::Input}; @@ -36,7 +36,7 @@ impl Tasks { let new = TasksProgress::from(&*running.lock()); if last != new { last = new; - emit!(Call(Exec::call("update_progress", vec![]).with_data(new), Layer::App)); + emit!(Call(Cmd::new("update_progress").with_data(new), Layer::App)); } } }); diff --git a/yazi-core/src/which/which.rs b/yazi-core/src/which/which.rs index 5b3ade0f4..017e35814 100644 --- a/yazi-core/src/which/which.rs +++ b/yazi-core/src/which/which.rs @@ -1,12 +1,10 @@ -use std::mem; - -use yazi_config::{keymap::{Control, Key}, KEYMAP}; +use yazi_config::{keymap::{Control, ControlCow, Key}, KEYMAP}; use yazi_shared::{emit, render, Layer}; pub struct Which { layer: Layer, pub times: usize, - pub cands: Vec<&'static Control>, + pub cands: Vec, pub visible: bool, } @@ -21,16 +19,28 @@ impl Which { pub fn show(&mut self, key: &Key, layer: Layer) { self.layer = layer; self.times = 1; - self.cands = KEYMAP.get(layer).iter().filter(|s| s.on.len() > 1 && &s.on[0] == key).collect(); + self.cands = KEYMAP + .get(layer) + .iter() + .filter(|c| c.on.len() > 1 && &c.on[0] == key) + .map(|c| c.into()) + .collect(); + + self.visible = true; + render!(); + } + + pub fn show_with(&mut self, cands: Vec, layer: Layer) { + self.layer = layer; + self.times = 0; + self.cands = cands.into_iter().map(|c| c.into()).collect(); + self.visible = true; render!(); } pub fn type_(&mut self, key: Key) -> bool { - self.cands = mem::take(&mut self.cands) - .into_iter() - .filter(|s| s.on.len() > self.times && s.on[self.times] == key) - .collect(); + self.cands.retain(|c| c.on.len() > self.times && c.on[self.times] == key); if self.cands.is_empty() { self.visible = false; diff --git a/yazi-fm/src/app/app.rs b/yazi-fm/src/app/app.rs index 1c46cf88e..867242d60 100644 --- a/yazi-fm/src/app/app.rs +++ b/yazi-fm/src/app/app.rs @@ -4,7 +4,7 @@ use anyhow::Result; use crossterm::event::KeyEvent; use yazi_config::keymap::Key; use yazi_core::input::InputMode; -use yazi_shared::{emit, event::{Event, Exec, NEED_RENDER}, term::Term, Layer}; +use yazi_shared::{emit, event::{Cmd, Event, NEED_RENDER}, term::Term, Layer}; use crate::{lives::Lives, Ctx, Executor, Logs, Panic, Router, Signals}; @@ -66,12 +66,10 @@ impl App { } #[inline] - fn dispatch_call(&mut self, exec: Exec, layer: Layer) { - Executor::new(self).execute(exec, layer); - } + fn dispatch_call(&mut self, cmd: Cmd, layer: Layer) { Executor::new(self).execute(cmd, layer); } #[inline] - fn dispatch_seq(&mut self, mut execs: VecDeque, layer: Layer) { + fn dispatch_seq(&mut self, mut execs: VecDeque, layer: Layer) { if let Some(exec) = execs.pop_front() { Executor::new(self).execute(exec, layer); } diff --git a/yazi-fm/src/app/commands/plugin.rs b/yazi-fm/src/app/commands/plugin.rs index 3e5aa5149..872e6c134 100644 --- a/yazi-fm/src/app/commands/plugin.rs +++ b/yazi-fm/src/app/commands/plugin.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use mlua::{ExternalError, ExternalResult, IntoLua, Table, TableExt, Variadic}; use tracing::warn; use yazi_plugin::{LOADED, LUA}; -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Cmd, Layer}; use crate::{app::App, lives::Lives}; @@ -24,7 +24,7 @@ impl App { tokio::spawn(async move { if LOADED.ensure(&opt.name).await.is_ok() { - emit!(Call(Exec::call("plugin_do", vec![opt.name]).with_data(opt.data), Layer::App)); + emit!(Call(Cmd::args("plugin_do", vec![opt.name]).with_data(opt.data), Layer::App)); } }); } diff --git a/yazi-fm/src/app/commands/resize.rs b/yazi-fm/src/app/commands/resize.rs index 11ec2ad8b..ffcae5b86 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::Exec; +use yazi_shared::event::Cmd; use crate::app::App; pub struct Opt; -impl From for Opt { - fn from(_: Exec) -> Self { Self } +impl From for Opt { + fn from(_: Cmd) -> 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 1fab8ccb2..fe6ebf681 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::Exec, term::Term}; +use yazi_shared::{event::Cmd, term::Term}; use crate::app::App; impl App { - pub(crate) fn resume(&mut self, _: Exec) { + pub(crate) fn resume(&mut self, _: Cmd) { self.cx.manager.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 ef4dc3b83..cfc0e1255 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::Exec; +use yazi_shared::event::Cmd; use crate::app::App; @@ -7,8 +7,8 @@ pub struct Opt { tx: Option>, } -impl From for Opt { - fn from(mut e: Exec) -> Self { Self { tx: e.take_data() } } +impl From for Opt { + fn from(mut c: Cmd) -> Self { Self { tx: c.take_data() } } } impl App { diff --git a/yazi-fm/src/app/commands/update_progress.rs b/yazi-fm/src/app/commands/update_progress.rs index 45535c54f..d6a57fe48 100644 --- a/yazi-fm/src/app/commands/update_progress.rs +++ b/yazi-fm/src/app/commands/update_progress.rs @@ -1,6 +1,6 @@ use ratatui::backend::Backend; use yazi_core::tasks::TasksProgress; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::{app::App, components::Progress, lives::Lives}; @@ -8,11 +8,11 @@ pub struct Opt { progress: TasksProgress, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = (); - fn try_from(mut e: Exec) -> Result { - Ok(Self { progress: e.take_data().ok_or(())? }) + fn try_from(mut c: Cmd) -> Result { + Ok(Self { progress: c.take_data().ok_or(())? }) } } diff --git a/yazi-fm/src/executor.rs b/yazi-fm/src/executor.rs index d988b0afa..532258a0e 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::{event::Exec, Layer}; +use yazi_shared::{event::Cmd, Layer}; use crate::app::App; @@ -12,24 +12,24 @@ impl<'a> Executor<'a> { pub(super) fn new(app: &'a mut App) -> Self { Self { app } } #[inline] - pub(super) fn execute(&mut self, exec: Exec, layer: Layer) { + pub(super) fn execute(&mut self, cmd: Cmd, layer: Layer) { match layer { - Layer::App => self.app(exec), - Layer::Manager => self.manager(exec), - Layer::Tasks => self.tasks(exec), - Layer::Select => self.select(exec), - Layer::Input => self.input(exec), - Layer::Help => self.help(exec), - Layer::Completion => self.completion(exec), + Layer::App => self.app(cmd), + Layer::Manager => self.manager(cmd), + Layer::Tasks => self.tasks(cmd), + Layer::Select => self.select(cmd), + Layer::Input => self.input(cmd), + Layer::Help => self.help(cmd), + Layer::Completion => self.completion(cmd), Layer::Which => unreachable!(), } } - fn app(&mut self, exec: Exec) { + fn app(&mut self, cmd: Cmd) { macro_rules! on { ($name:ident) => { - if exec.cmd == stringify!($name) { - return self.app.$name(exec); + if cmd.name == stringify!($name) { + return self.app.$name(cmd); } }; } @@ -42,21 +42,21 @@ impl<'a> Executor<'a> { on!(resume); } - fn manager(&mut self, exec: Exec) { + fn manager(&mut self, cmd: Cmd) { macro_rules! on { (MANAGER, $name:ident $(,$args:expr)*) => { - if exec.cmd == stringify!($name) { - return self.app.cx.manager.$name(exec, $($args),*); + if cmd.name == stringify!($name) { + return self.app.cx.manager.$name(cmd, $($args),*); } }; (ACTIVE, $name:ident $(,$args:expr)*) => { - if exec.cmd == stringify!($name) { - return self.app.cx.manager.active_mut().$name(exec, $($args),*); + if cmd.name == stringify!($name) { + return self.app.cx.manager.active_mut().$name(cmd, $($args),*); } }; (TABS, $name:ident) => { - if exec.cmd == concat!("tab_", stringify!($name)) { - return self.app.cx.manager.tabs.$name(exec); + if cmd.name == concat!("tab_", stringify!($name)) { + return self.app.cx.manager.tabs.$name(cmd); } }; } @@ -122,27 +122,27 @@ impl<'a> Executor<'a> { on!(TABS, switch); on!(TABS, swap); - match exec.cmd.as_bytes() { + match cmd.name.as_bytes() { // Tasks b"tasks_show" => self.app.cx.tasks.toggle(()), // Help b"help" => self.app.cx.help.toggle(Layer::Manager), // Plugin - b"plugin" => self.app.plugin(exec), + b"plugin" => self.app.plugin(cmd), _ => {} } } - fn tasks(&mut self, exec: Exec) { + fn tasks(&mut self, cmd: Cmd) { macro_rules! on { ($name:ident) => { - if exec.cmd == stringify!($name) { - return self.app.cx.tasks.$name(exec); + if cmd.name == stringify!($name) { + return self.app.cx.tasks.$name(cmd); } }; ($name:ident, $alias:literal) => { - if exec.cmd == $alias { - return self.app.cx.tasks.$name(exec); + if cmd.name == $alias { + return self.app.cx.tasks.$name(cmd); } }; } @@ -154,17 +154,17 @@ impl<'a> Executor<'a> { on!(cancel); #[allow(clippy::single_match)] - match exec.cmd.as_str() { + match cmd.name.as_str() { "help" => self.app.cx.help.toggle(Layer::Tasks), _ => {} } } - fn select(&mut self, exec: Exec) { + fn select(&mut self, cmd: Cmd) { macro_rules! on { ($name:ident) => { - if exec.cmd == stringify!($name) { - return self.app.cx.select.$name(exec); + if cmd.name == stringify!($name) { + return self.app.cx.select.$name(cmd); } }; } @@ -174,22 +174,22 @@ impl<'a> Executor<'a> { on!(arrow); #[allow(clippy::single_match)] - match exec.cmd.as_str() { + match cmd.name.as_str() { "help" => self.app.cx.help.toggle(Layer::Select), _ => {} } } - fn input(&mut self, exec: Exec) { + fn input(&mut self, cmd: Cmd) { macro_rules! on { ($name:ident) => { - if exec.cmd == stringify!($name) { - return self.app.cx.input.$name(exec); + if cmd.name == stringify!($name) { + return self.app.cx.input.$name(cmd); } }; ($name:ident, $alias:literal) => { - if exec.cmd == $alias { - return self.app.cx.input.$name(exec); + if cmd.name == $alias { + return self.app.cx.input.$name(cmd); } }; } @@ -201,11 +201,11 @@ impl<'a> Executor<'a> { on!(backward); on!(forward); - if exec.cmd.as_str() == "complete" { - return if exec.named.contains_key("trigger") { - self.app.cx.completion.trigger(exec) + if cmd.name.as_str() == "complete" { + return if cmd.named.contains_key("trigger") { + self.app.cx.completion.trigger(cmd) } else { - self.app.cx.input.complete(exec) + self.app.cx.input.complete(cmd) }; } @@ -222,7 +222,7 @@ impl<'a> Executor<'a> { on!(redo); #[allow(clippy::single_match)] - match exec.cmd.as_str() { + match cmd.name.as_str() { "help" => self.app.cx.help.toggle(Layer::Input), _ => {} } @@ -234,11 +234,11 @@ impl<'a> Executor<'a> { } } - fn help(&mut self, exec: Exec) { + fn help(&mut self, cmd: Cmd) { macro_rules! on { ($name:ident) => { - if exec.cmd == stringify!($name) { - return self.app.cx.help.$name(exec); + if cmd.name == stringify!($name) { + return self.app.cx.help.$name(cmd); } }; } @@ -248,17 +248,17 @@ impl<'a> Executor<'a> { on!(filter); #[allow(clippy::single_match)] - match exec.cmd.as_str() { + match cmd.name.as_str() { "close" => self.app.cx.help.toggle(Layer::Help), _ => {} } } - fn completion(&mut self, exec: Exec) { + fn completion(&mut self, cmd: Cmd) { macro_rules! on { ($name:ident) => { - if exec.cmd == stringify!($name) { - return self.app.cx.completion.$name(exec); + if cmd.name == stringify!($name) { + return self.app.cx.completion.$name(cmd); } }; } @@ -269,9 +269,9 @@ impl<'a> Executor<'a> { on!(arrow); #[allow(clippy::single_match)] - match exec.cmd.as_str() { + match cmd.name.as_str() { "help" => self.app.cx.help.toggle(Layer::Completion), - "close_input" => self.app.cx.input.close(exec), + "close_input" => self.app.cx.input.close(cmd), _ => {} } } diff --git a/yazi-fm/src/which/layout.rs b/yazi-fm/src/which/layout.rs index 31b0d9a1d..4f1aac1f4 100644 --- a/yazi-fm/src/which/layout.rs +++ b/yazi-fm/src/which/layout.rs @@ -48,7 +48,7 @@ impl Widget for Which<'_> { for y in 0..area.height { for (x, chunk) in chunks.iter().enumerate() { - let Some(&cand) = which.cands.get(y as usize * cols + x) else { + let Some(cand) = which.cands.get(y as usize * cols + x) else { break; }; diff --git a/yazi-plugin/src/isolate/peek.rs b/yazi-plugin/src/isolate/peek.rs index 3faff38ff..36303ff3f 100644 --- a/yazi-plugin/src/isolate/peek.rs +++ b/yazi-plugin/src/isolate/peek.rs @@ -3,19 +3,19 @@ use tokio::{runtime::Handle, select}; use tokio_util::sync::CancellationToken; use tracing::error; use yazi_config::LAYOUT; -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Cmd, Layer}; use super::slim_lua; use crate::{bindings::{Cast, File, Window}, elements::Rect, OptData, LOADED, LUA}; -pub fn peek(exec: &Exec, file: yazi_shared::fs::File, skip: usize) -> CancellationToken { +pub fn peek(cmd: &Cmd, file: yazi_shared::fs::File, skip: usize) -> CancellationToken { let ct = CancellationToken::new(); - let cmd = exec.cmd.to_owned(); + let name = cmd.name.to_owned(); let (ct1, ct2) = (ct.clone(), ct.clone()); tokio::task::spawn_blocking(move || { let future = async { - LOADED.ensure(&cmd).await.into_lua_err()?; + LOADED.ensure(&name).await.into_lua_err()?; let lua = slim_lua()?; lua.set_hook( @@ -25,7 +25,7 @@ pub fn peek(exec: &Exec, file: yazi_shared::fs::File, skip: usize) -> Cancellati }, ); - let plugin: Table = if let Some(b) = LOADED.read().get(&cmd) { + let plugin: Table = if let Some(b) = LOADED.read().get(&name) { lua.load(b).call(())? } else { return Err("unloaded plugin".into_lua_err()); @@ -55,7 +55,7 @@ pub fn peek(exec: &Exec, file: yazi_shared::fs::File, skip: usize) -> Cancellati ct } -pub fn peek_sync(exec: &Exec, file: yazi_shared::fs::File, skip: usize) { +pub fn peek_sync(cmd: &Cmd, file: yazi_shared::fs::File, skip: usize) { let data = OptData { args: vec![], cb: Some(Box::new(move |plugin| { @@ -68,7 +68,7 @@ pub fn peek_sync(exec: &Exec, file: yazi_shared::fs::File, skip: usize) { tx: None, }; emit!(Call( - Exec::call("plugin", vec![exec.cmd.to_owned()]).with_bool("sync", true).with_data(data), + Cmd::args("plugin", vec![cmd.name.to_owned()]).with_bool("sync", true).with_data(data), Layer::App )); } diff --git a/yazi-plugin/src/isolate/seek.rs b/yazi-plugin/src/isolate/seek.rs index 6527cd990..851022b85 100644 --- a/yazi-plugin/src/isolate/seek.rs +++ b/yazi-plugin/src/isolate/seek.rs @@ -1,10 +1,10 @@ use mlua::TableExt; use yazi_config::LAYOUT; -use yazi_shared::{emit, event::Exec, Layer}; +use yazi_shared::{emit, event::Cmd, Layer}; use crate::{bindings::{Cast, File}, elements::Rect, OptData, LUA}; -pub fn seek_sync(exec: &Exec, file: yazi_shared::fs::File, units: i16) { +pub fn seek_sync(cmd: &Cmd, file: yazi_shared::fs::File, units: i16) { let data = OptData { args: vec![], cb: Some(Box::new(move |plugin| { @@ -15,7 +15,7 @@ pub fn seek_sync(exec: &Exec, file: yazi_shared::fs::File, units: i16) { tx: None, }; emit!(Call( - Exec::call("plugin", vec![exec.cmd.to_owned()]).with_bool("sync", true).with_data(data), + Cmd::args("plugin", vec![cmd.name.to_owned()]).with_bool("sync", true).with_data(data), Layer::App )); } diff --git a/yazi-plugin/src/opt.rs b/yazi-plugin/src/opt.rs index 503e50743..423513df2 100644 --- a/yazi-plugin/src/opt.rs +++ b/yazi-plugin/src/opt.rs @@ -1,7 +1,7 @@ use anyhow::bail; use mlua::{Table, Value}; use tokio::sync::oneshot; -use yazi_shared::event::Exec; +use yazi_shared::event::Cmd; use crate::ValueSendable; @@ -18,23 +18,23 @@ pub struct OptData { pub tx: Option>, } -impl TryFrom for Opt { +impl TryFrom for Opt { type Error = anyhow::Error; - fn try_from(mut e: Exec) -> Result { - let Some(name) = e.take_first().filter(|s| !s.is_empty()) else { + fn try_from(mut c: Cmd) -> Result { + let Some(name) = c.take_first().filter(|s| !s.is_empty()) else { bail!("invalid plugin name"); }; - let mut data: OptData = e.take_data().unwrap_or_default(); + let mut data: OptData = c.take_data().unwrap_or_default(); - if let Some(args) = e.named.get("args") { + if let Some(args) = c.named.get("args") { data.args = shell_words::split(args)? .into_iter() .map(|s| ValueSendable::String(s.into_bytes())) .collect(); } - Ok(Self { name, sync: e.named.contains_key("sync"), data }) + Ok(Self { name, sync: c.named.contains_key("sync"), data }) } } diff --git a/yazi-plugin/src/utils/call.rs b/yazi-plugin/src/utils/call.rs index 056dcd02b..adeb237b0 100644 --- a/yazi-plugin/src/utils/call.rs +++ b/yazi-plugin/src/utils/call.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use mlua::{ExternalError, Lua, Table, Value}; -use yazi_shared::{emit, event::Exec, render, Layer}; +use yazi_shared::{emit, event::Cmd, render, Layer}; use super::Utils; use crate::ValueSendable; @@ -29,9 +29,9 @@ impl Utils { } #[inline] - fn create_exec(cmd: String, table: Table, data: Option) -> mlua::Result { + fn create_cmd(name: String, table: Table, data: Option) -> mlua::Result { let (args, named) = Self::parse_args(table)?; - let mut exec = Exec { cmd, args, named, ..Default::default() }; + let mut exec = Cmd { name, args, named, ..Default::default() }; if let Some(data) = data.and_then(|v| ValueSendable::try_from(v).ok()) { exec = exec.with_data(data); @@ -50,16 +50,16 @@ impl Utils { ya.set( "app_emit", - lua.create_function(|_, (cmd, table, data): (String, Table, Option)| { - emit!(Call(Self::create_exec(cmd, table, data)?, Layer::App)); + lua.create_function(|_, (name, table, data): (String, Table, Option)| { + emit!(Call(Self::create_cmd(name, table, data)?, Layer::App)); Ok(()) })?, )?; ya.set( "manager_emit", - lua.create_function(|_, (cmd, table, data): (String, Table, Option)| { - emit!(Call(Self::create_exec(cmd, table, data)?, Layer::Manager)); + lua.create_function(|_, (name, table, data): (String, Table, Option)| { + emit!(Call(Self::create_cmd(name, table, data)?, Layer::Manager)); Ok(()) })?, )?; diff --git a/yazi-plugin/src/utils/preview.rs b/yazi-plugin/src/utils/preview.rs index f3afc84d6..f5bce8b9a 100644 --- a/yazi-plugin/src/utils/preview.rs +++ b/yazi-plugin/src/utils/preview.rs @@ -1,5 +1,5 @@ use mlua::{AnyUserData, IntoLuaMulti, Lua, Table, Value}; -use yazi_shared::{emit, event::Exec, Layer, PeekError}; +use yazi_shared::{emit, event::Cmd, Layer, PeekError}; use super::Utils; use crate::{bindings::{FileRef, Window}, cast_to_renderable, elements::{Paragraph, RectRef, Renderable}, external::{self, Highlighter}}; @@ -44,7 +44,7 @@ impl Utils { }; lock.data = vec![Box::new(Paragraph { area: *area, text, ..Default::default() })]; - emit!(Call(Exec::call("preview", vec![]).with_data(lock), Layer::Manager)); + emit!(Call(Cmd::new("preview").with_data(lock), Layer::Manager)); (true, Value::Nil).into_lua_multi(lua) })?, )?; @@ -67,7 +67,7 @@ impl Utils { ..Default::default() })]; - emit!(Call(Exec::call("preview", vec![]).with_data(lock), Layer::Manager)); + emit!(Call(Cmd::new("preview").with_data(lock), Layer::Manager)); (true, Value::Nil).into_lua_multi(lua) })?, )?; @@ -78,7 +78,7 @@ impl Utils { let mut lock = PreviewLock::try_from(t)?; lock.data = widgets.into_iter().filter_map(cast_to_renderable).collect(); - emit!(Call(Exec::call("preview", vec![]).with_data(lock), Layer::Manager)); + emit!(Call(Cmd::new("preview").with_data(lock), Layer::Manager)); Ok(()) })?, )?; diff --git a/yazi-scheduler/src/preload/preload.rs b/yazi-scheduler/src/preload/preload.rs index 77557e328..19f492575 100644 --- a/yazi-scheduler/src/preload/preload.rs +++ b/yazi-scheduler/src/preload/preload.rs @@ -31,7 +31,7 @@ impl Preload { match op { PreloadOp::Rule(task) => { let urls: Vec<_> = task.targets.iter().map(|f| f.url()).collect(); - let result = isolate::preload(&task.plugin.cmd, task.targets, task.plugin.multi).await; + let result = isolate::preload(&task.plugin.name, task.targets, task.plugin.multi).await; if let Err(e) = result { self.fail(task.id, format!("Preload task failed:\n{e}"))?; return Err(e.into()); @@ -39,7 +39,7 @@ impl Preload { let code = result.unwrap(); if code & 1 == 0 { - error!("Preload task `{}` returned {code}", task.plugin.cmd); + error!("Preload task `{}` returned {code}", task.plugin.name); } if code >> 1 & 1 != 0 { let mut loaded = self.rule_loaded.write(); diff --git a/yazi-scheduler/src/scheduler.rs b/yazi-scheduler/src/scheduler.rs index df7de96e6..fc6dbf4cf 100644 --- a/yazi-scheduler/src/scheduler.rs +++ b/yazi-scheduler/src/scheduler.rs @@ -5,7 +5,7 @@ use parking_lot::Mutex; use tokio::{fs, select, sync::{mpsc::{self, UnboundedReceiver}, oneshot}}; use yazi_config::{open::Opener, plugin::PluginRule, TASKS}; use yazi_plugin::ValueSendable; -use yazi_shared::{emit, event::Exec, fs::{unique_path, Url}, Layer, Throttle}; +use yazi_shared::{emit, event::Cmd, fs::{unique_path, Url}, Layer, Throttle}; use super::{Running, TaskProg, TaskStage}; use crate::{file::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash}, plugin::{Plugin, PluginOpEntry}, preload::{Preload, PreloadOpRule, PreloadOpSize}, process::{Process, ProcessOpOpen}, TaskKind, TaskOp, HIGH, LOW, NORMAL}; @@ -165,12 +165,12 @@ impl Scheduler { pub async fn app_stop() { let (tx, rx) = oneshot::channel::<()>(); - emit!(Call(Exec::call("stop", vec![]).with_data(tx), Layer::App)); + emit!(Call(Cmd::new("stop").with_data(tx), Layer::App)); rx.await.ok(); } pub fn app_resume() { - emit!(Call(Exec::call("resume", vec![]), Layer::App)); + emit!(Call(Cmd::new("resume"), Layer::App)); } pub fn file_cut(&self, from: Url, mut to: Url, force: bool) { @@ -307,7 +307,7 @@ impl Scheduler { pub fn preload_paged(&self, rule: &PluginRule, targets: Vec<&yazi_shared::fs::File>) { let id = self.running.lock().add( TaskKind::Preload, - format!("Run preloader `{}` with {} target(s)", rule.exec.cmd, targets.len()), + format!("Run preloader `{}` with {} target(s)", rule.cmd.name, targets.len()), ); let plugin = rule.into(); diff --git a/yazi-shared/src/event/exec.rs b/yazi-shared/src/event/cmd.rs similarity index 76% rename from yazi-shared/src/event/exec.rs rename to yazi-shared/src/event/cmd.rs index 5a05ee4e6..c519dd6b6 100644 --- a/yazi-shared/src/event/exec.rs +++ b/yazi-shared/src/event/cmd.rs @@ -1,22 +1,20 @@ use std::{any::Any, collections::BTreeMap, fmt::{self, Display}, mem}; #[derive(Debug, Default)] -pub struct Exec { - pub cmd: String, +pub struct Cmd { + pub name: String, pub args: Vec, pub named: BTreeMap, pub data: Option>, } -impl Exec { +impl Cmd { #[inline] - pub fn call(cwd: &str, args: Vec) -> Self { - Exec { cmd: cwd.to_owned(), args, ..Default::default() } - } + pub fn new(name: &str) -> Self { Self { name: name.to_owned(), ..Default::default() } } #[inline] - pub fn call_named(cwd: &str, named: BTreeMap) -> Self { - Exec { cmd: cwd.to_owned(), named, ..Default::default() } + pub fn args(name: &str, args: Vec) -> Self { + Self { name: name.to_owned(), args, ..Default::default() } } #[inline] @@ -55,17 +53,17 @@ impl Exec { #[inline] pub fn clone_without_data(&self) -> Self { Self { - cmd: self.cmd.clone(), - args: self.args.clone(), + name: self.name.clone(), + args: self.args.clone(), named: self.named.clone(), - ..Default::default() + data: None, } } } -impl Display for Exec { +impl Display for Cmd { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.cmd)?; + write!(f, "{}", self.name)?; if !self.args.is_empty() { write!(f, " {}", self.args.join(" "))?; } diff --git a/yazi-shared/src/event/event.rs b/yazi-shared/src/event/event.rs index 7f03f8975..02cd08581 100644 --- a/yazi-shared/src/event/event.rs +++ b/yazi-shared/src/event/event.rs @@ -3,15 +3,15 @@ use std::{collections::VecDeque, ffi::OsString}; use crossterm::event::KeyEvent; use tokio::sync::{mpsc, oneshot}; -use super::Exec; +use super::Cmd; use crate::{term::Term, Layer, RoCell}; static TX: RoCell> = RoCell::new(); #[derive(Debug)] pub enum Event { - Call(Exec, Layer), - Seq(VecDeque, Layer), + Call(Cmd, Layer), + Seq(VecDeque, Layer), Render, Key(KeyEvent), Resize, diff --git a/yazi-shared/src/event/mod.rs b/yazi-shared/src/event/mod.rs index 643d570c3..2e32f12fc 100644 --- a/yazi-shared/src/event/mod.rs +++ b/yazi-shared/src/event/mod.rs @@ -1,9 +1,9 @@ #![allow(clippy::module_inception)] +mod cmd; mod event; -mod exec; mod render; +pub use cmd::*; pub use event::*; -pub use exec::*; pub use render::*; diff --git a/yazi-shared/src/fs/op.rs b/yazi-shared/src/fs/op.rs index 856f226c0..61993dce5 100644 --- a/yazi-shared/src/fs/op.rs +++ b/yazi-shared/src/fs/op.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeMap, sync::atomic::{AtomicU64, Ordering}, time::SystemTime}; use super::File; -use crate::{emit, event::Exec, fs::Url, Layer}; +use crate::{emit, event::Cmd, fs::Url, Layer}; pub static FILES_TICKET: AtomicU64 = AtomicU64::new(0); @@ -36,7 +36,7 @@ impl FilesOp { #[inline] pub fn emit(self) { - emit!(Call(Exec::call("update_files", vec![]).with_data(self), Layer::Manager)); + emit!(Call(Cmd::new("update_files").with_data(self), Layer::Manager)); } pub fn prepare(url: &Url) -> u64 {