Skip to content

Commit 41b00c8

Browse files
authored
feat: allow DDS events to change command arguments (#3037)
1 parent 0b45ed8 commit 41b00c8

118 files changed

Lines changed: 1358 additions & 774 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ syntect = { version = "5.2.0", default-features = false, features =
4848
tokio = { version = "1.47.1", features = [ "full" ] }
4949
tokio-stream = "0.1.17"
5050
tokio-util = "0.7.16"
51-
toml = { version = "0.9.4" }
51+
toml = { version = "0.9.5" }
5252
tracing = { version = "0.1.41", features = [ "max_level_debug", "release_max_level_debug" ] }
5353
twox-hash = { version = "2.1.1", default-features = false, features = [ "std", "random", "xxhash3_128" ] }
5454
unicode-width = { version = "0.2.0", default-features = false }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Yazi (means "duck") is a terminal file manager written in Rust, based on non-blo
2929
- 💫 Vim-like input/pick/confirm/which/notify component, auto-completion for cd paths
3030
- 🏷️ Multi-Tab Support, Cross-directory selection, Scrollable Preview (for videos, PDFs, archives, code, directories, etc.)
3131
- 🔄 Bulk Renaming, Archive Extraction, Visual Mode, File Chooser, [Git Integration](https://github.com/yazi-rs/plugins/tree/main/git.yazi), [Mount Manager](https://github.com/yazi-rs/plugins/tree/main/mount.yazi)
32-
- 🎨 Theme System, Mouse Support, Trash Bin, Custom Layouts, CSI u, OSC 52
32+
- 🎨 Theme System, Mouse Support, Trash Bin, Custom Layouts, Virtual Filesystem, CSI u, OSC 52
3333
- ... and more!
3434

3535
https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265cc7

yazi-actor/src/actor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Result;
2+
use yazi_dds::spark::SparkKind;
23
use yazi_shared::event::Data;
34

45
use crate::Ctx;
@@ -10,5 +11,5 @@ pub trait Actor {
1011

1112
fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data>;
1213

13-
fn hook(_cx: &Ctx, _opt: &Self::Options) -> Option<&'static str> { None }
14+
fn hook(_cx: &Ctx, _opt: &Self::Options) -> Option<SparkKind> { None }
1415
}

yazi-actor/src/core/preflight.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
11
use std::marker::PhantomData;
22

33
use anyhow::Result;
4-
use mlua::{IntoLua, Value};
5-
use tracing::error;
4+
use mlua::{ErrorContext, ExternalError, IntoLua, Value};
65
use yazi_binding::runtime_mut;
7-
use yazi_dds::{LOCAL, body::Body};
8-
use yazi_macro::succ;
6+
use yazi_dds::{LOCAL, spark::{Spark, SparkKind}};
97
use yazi_plugin::LUA;
10-
use yazi_shared::event::Data;
118

12-
use crate::{Actor, Ctx, lives::Lives};
9+
use crate::{Ctx, lives::Lives};
1310

1411
pub struct Preflight<'a> {
1512
_lifetime: PhantomData<&'a ()>,
1613
}
1714

18-
impl<'a> Actor for Preflight<'a> {
19-
type Options = (&'static str, Body<'a>);
20-
21-
const NAME: &'static str = "preflight";
22-
23-
fn act(cx: &mut Ctx, opt: Self::Options) -> Result<Data> {
15+
impl<'a> Preflight<'a> {
16+
pub fn act(cx: &mut Ctx, opt: (SparkKind, Spark<'a>)) -> Result<Spark<'a>> {
2417
let kind = opt.0;
25-
let Some(handlers) = LOCAL.read().get(kind).filter(|&m| !m.is_empty()).cloned() else {
26-
succ!(false)
18+
let Some(handlers) = LOCAL.read().get(kind.as_ref()).filter(|&m| !m.is_empty()).cloned() else {
19+
return Ok(opt.1);
2720
};
2821

29-
succ!(Lives::scope(cx.core, || {
30-
let body = opt.1.into_lua(&LUA)?;
22+
Ok(Lives::scope(cx.core, || {
23+
let mut body = opt.1.into_lua(&LUA)?;
3124
for (id, cb) in handlers {
3225
runtime_mut!(LUA)?.push(&id);
33-
let result = cb.call::<Value>(body.clone());
26+
let result = cb.call::<Value>(&body);
3427
runtime_mut!(LUA)?.pop();
3528

3629
match result {
37-
Ok(Value::Boolean(true)) => return Ok(true),
38-
Ok(Value::Nil | Value::Boolean(false)) => {}
39-
Ok(v) => {
40-
error!("Unexpected return type from `{kind}` event handler in `{id}` plugin: {v:?}")
41-
}
42-
Err(e) => error!("Failed to run `{kind}` event handler in `{id}` plugin: {e}"),
43-
}
30+
Ok(Value::Nil) => Err(
31+
format!("Cancelled by `{kind}` event handler in `{id}` plugin on preflight")
32+
.into_lua_err(),
33+
)?,
34+
Ok(v) => body = v,
35+
Err(e) => Err(
36+
format!("Failed to run `{kind}` event handler in `{id}` plugin: {e}").into_lua_err(),
37+
)?,
38+
};
4439
}
45-
Ok(false)
40+
41+
Spark::from_lua(&LUA, kind, body)
42+
.with_context(|e| format!("Unexpected return type from `{kind}` event handlers: {e}"))
4643
})?)
4744
}
4845
}

yazi-actor/src/mgr/quit.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use anyhow::Result;
44
use tokio::{select, time};
55
use yazi_boot::ARGS;
66
use yazi_config::popup::ConfirmCfg;
7+
use yazi_dds::spark::SparkKind;
78
use yazi_macro::{emit, succ};
89
use yazi_parser::mgr::{OpenOpt, QuitOpt};
910
use yazi_proxy::ConfirmProxy;
@@ -60,8 +61,8 @@ impl Actor for Quit {
6061
succ!();
6162
}
6263

63-
fn hook(cx: &Ctx, _opt: &Self::Options) -> Option<&'static str> {
64-
Some("key-quit").filter(|_| cx.source().is_key())
64+
fn hook(cx: &Ctx, _opt: &Self::Options) -> Option<SparkKind> {
65+
Some(SparkKind::KeyQuit).filter(|_| cx.source().is_key())
6566
}
6667
}
6768

yazi-config/src/popup/options.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use yazi_shared::{IntoStringLossy, url::Url};
44
use super::{Offset, Position};
55
use crate::YAZI;
66

7-
#[derive(Default)]
7+
#[derive(Debug, Default)]
88
pub struct InputCfg {
99
pub title: String,
1010
pub value: String,
@@ -15,14 +15,14 @@ pub struct InputCfg {
1515
pub completion: bool,
1616
}
1717

18-
#[derive(Default)]
18+
#[derive(Debug, Default)]
1919
pub struct PickCfg {
2020
pub title: String,
2121
pub items: Vec<String>,
2222
pub position: Position,
2323
}
2424

25-
#[derive(Default)]
25+
#[derive(Debug, Default)]
2626
pub struct ConfirmCfg {
2727
pub position: Position,
2828
pub title: Line<'static>,

0 commit comments

Comments
 (0)