mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: support passing arguments to plugin
This commit is contained in:
parent
f31f78b063
commit
c344dcd1a1
4 changed files with 14 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2730,6 +2730,7 @@ dependencies = [
|
|||
"ratatui",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shell-words",
|
||||
"syntect",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
|
|
|
|||
|
|
@ -37,14 +37,13 @@ impl App {
|
|||
Lives::scope(&self.cx, |_| {
|
||||
let mut plugin: Option<Table> = None;
|
||||
if let Some(b) = LOADED.read().get(&opt.name) {
|
||||
match LUA.load(b).call(()) {
|
||||
match LUA.load(b).call(args) {
|
||||
Ok(t) => plugin = Some(t),
|
||||
Err(e) => ret = Err(e),
|
||||
}
|
||||
}
|
||||
if let Some(plugin) = plugin {
|
||||
ret =
|
||||
if let Some(cb) = opt.data.cb { cb(plugin) } else { plugin.call_method("entry", args) };
|
||||
ret = if let Some(cb) = opt.data.cb { cb(plugin) } else { plugin.call_method("entry", ()) };
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ parking_lot = "^0"
|
|||
ratatui = "^0"
|
||||
serde = "^1"
|
||||
serde_json = "^1"
|
||||
shell-words = "^1"
|
||||
syntect = { version = "^5", default-features = false, features = [ "parsing", "plist-load", "regex-onig" ] }
|
||||
tokio = { version = "^1", features = [ "parking_lot", "rt-multi-thread" ] }
|
||||
tokio-util = "^0"
|
||||
|
|
|
|||
|
|
@ -26,6 +26,15 @@ impl TryFrom<Exec> for Opt {
|
|||
bail!("invalid plugin name");
|
||||
};
|
||||
|
||||
Ok(Self { name, sync: e.named.contains_key("sync"), data: e.take_data().unwrap_or_default() })
|
||||
let mut data: OptData = e.take_data().unwrap_or_default();
|
||||
|
||||
if let Some(args) = e.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 })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue