Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3f48e26

Browse files
committedMar 7, 2025··
feat: custom search engine Lua API (#2452)
1 parent dc46e90 commit 3f48e26

File tree

26 files changed

+216
-119
lines changed

26 files changed

+216
-119
lines changed
 

‎Cargo.lock

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎yazi-adapter/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-adapter"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-config = { path = "../yazi-config", version = "25.3.2" }
13-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
14-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
12+
yazi-config = { path = "../yazi-config", version = "25.3.7" }
13+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
14+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
1515

1616
# External dependencies
1717
ansi-to-tui = { workspace = true }

‎yazi-boot/Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-boot"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,11 +9,11 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" }
13-
yazi-config = { path = "../yazi-config", version = "25.3.2" }
14-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
15-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
16-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
12+
yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" }
13+
yazi-config = { path = "../yazi-config", version = "25.3.7" }
14+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
15+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
16+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
1717

1818
# External dependencies
1919
clap = { workspace = true }

‎yazi-cli/Cargo.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-cli"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,11 +9,11 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-boot = { path = "../yazi-boot", version = "25.3.2" }
13-
yazi-dds = { path = "../yazi-dds", version = "25.3.2" }
14-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
15-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
16-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
12+
yazi-boot = { path = "../yazi-boot", version = "25.3.7" }
13+
yazi-dds = { path = "../yazi-dds", version = "25.3.7" }
14+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
15+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
16+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
1717

1818
# External dependencies
1919
anyhow = { workspace = true }
@@ -26,7 +26,7 @@ toml = { workspace = true }
2626
twox-hash = { workspace = true }
2727

2828
[build-dependencies]
29-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
29+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
3030

3131
# External build dependencies
3232
anyhow = { workspace = true }

‎yazi-codegen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-codegen"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]

‎yazi-config/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-config"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
13-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
14-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
12+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
13+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
14+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
1515

1616
# External dependencies
1717
anyhow = { workspace = true }

‎yazi-core/Cargo.toml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-core"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,17 +9,17 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" }
13-
yazi-boot = { path = "../yazi-boot", version = "25.3.2" }
14-
yazi-codegen = { path = "../yazi-codegen", version = "25.3.2" }
15-
yazi-config = { path = "../yazi-config", version = "25.3.2" }
16-
yazi-dds = { path = "../yazi-dds", version = "25.3.2" }
17-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
18-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
19-
yazi-plugin = { path = "../yazi-plugin", version = "25.3.2" }
20-
yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" }
21-
yazi-scheduler = { path = "../yazi-scheduler", version = "25.3.2" }
22-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
12+
yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" }
13+
yazi-boot = { path = "../yazi-boot", version = "25.3.7" }
14+
yazi-codegen = { path = "../yazi-codegen", version = "25.3.7" }
15+
yazi-config = { path = "../yazi-config", version = "25.3.7" }
16+
yazi-dds = { path = "../yazi-dds", version = "25.3.7" }
17+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
18+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
19+
yazi-plugin = { path = "../yazi-plugin", version = "25.3.7" }
20+
yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" }
21+
yazi-scheduler = { path = "../yazi-scheduler", version = "25.3.7" }
22+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
2323

2424
# External dependencies
2525
anyhow = { workspace = true }

‎yazi-dds/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-dds"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -13,10 +13,10 @@ default = [ "vendored-lua" ]
1313
vendored-lua = [ "mlua/vendored" ]
1414

1515
[dependencies]
16-
yazi-boot = { path = "../yazi-boot", version = "25.3.2" }
17-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
18-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
19-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
16+
yazi-boot = { path = "../yazi-boot", version = "25.3.7" }
17+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
18+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
19+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
2020

2121
# External dependencies
2222
anyhow = { workspace = true }

‎yazi-dds/src/sendable.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl Sendable {
4343
Value::UserData(ud) => {
4444
if let Ok(t) = ud.take::<yazi_shared::url::Url>() {
4545
Data::Url(t)
46+
} else if let Ok(t) = ud.take::<yazi_fs::FilesOp>() {
47+
Data::Any(Box::new(t))
4648
} else if let Ok(t) = ud.take::<super::body::BodyYankIter>() {
4749
Data::Any(Box::new(t))
4850
} else {
@@ -72,13 +74,13 @@ impl Sendable {
7274
Value::Table(tbl)
7375
}
7476
Data::Url(u) => Value::UserData(lua.create_any_userdata(u)?),
75-
Data::Any(a) => {
76-
if let Ok(t) = a.downcast::<super::body::BodyYankIter>() {
77-
Value::UserData(lua.create_userdata(*t)?)
78-
} else {
79-
Err("unsupported userdata included".into_lua_err())?
80-
}
81-
}
77+
Data::Any(a) => Value::UserData(if a.is::<yazi_fs::FilesOp>() {
78+
lua.create_any_userdata(*a.downcast::<yazi_fs::FilesOp>().unwrap())?
79+
} else if a.is::<super::body::BodyYankIter>() {
80+
lua.create_userdata(*a.downcast::<super::body::BodyYankIter>().unwrap())?
81+
} else {
82+
Err("unsupported userdata included".into_lua_err())?
83+
}),
8284
data => Self::data_to_value_ref(lua, &data)?,
8385
})
8486
}
@@ -107,13 +109,13 @@ impl Sendable {
107109
}
108110
Data::Url(u) => Value::UserData(lua.create_any_userdata(u.clone())?),
109111
Data::Bytes(b) => Value::String(lua.create_string(b)?),
110-
Data::Any(a) => {
111-
if let Some(t) = a.downcast_ref::<super::body::BodyYankIter>() {
112-
Value::UserData(lua.create_userdata(t.clone())?)
113-
} else {
114-
Err("unsupported userdata included".into_lua_err())?
115-
}
116-
}
112+
Data::Any(a) => Value::UserData(if let Some(t) = a.downcast_ref::<yazi_fs::FilesOp>() {
113+
lua.create_any_userdata(t.clone())?
114+
} else if let Some(t) = a.downcast_ref::<super::body::BodyYankIter>() {
115+
lua.create_userdata(t.clone())?
116+
} else {
117+
Err("unsupported userdata included".into_lua_err())?
118+
}),
117119
})
118120
}
119121

‎yazi-ffi/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-ffi"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,7 +9,7 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
12+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
1313

1414
# External dependencies
1515
anyhow = { workspace = true }

‎yazi-fm/Cargo.toml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-fm"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -13,17 +13,17 @@ default = [ "vendored-lua" ]
1313
vendored-lua = [ "mlua/vendored" ]
1414

1515
[dependencies]
16-
yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" }
17-
yazi-boot = { path = "../yazi-boot", version = "25.3.2" }
18-
yazi-codegen = { path = "../yazi-codegen", version = "25.3.2" }
19-
yazi-config = { path = "../yazi-config", version = "25.3.2" }
20-
yazi-core = { path = "../yazi-core", version = "25.3.2" }
21-
yazi-dds = { path = "../yazi-dds", version = "25.3.2" }
22-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
23-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
24-
yazi-plugin = { path = "../yazi-plugin", version = "25.3.2" }
25-
yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" }
26-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
16+
yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" }
17+
yazi-boot = { path = "../yazi-boot", version = "25.3.7" }
18+
yazi-codegen = { path = "../yazi-codegen", version = "25.3.7" }
19+
yazi-config = { path = "../yazi-config", version = "25.3.7" }
20+
yazi-core = { path = "../yazi-core", version = "25.3.7" }
21+
yazi-dds = { path = "../yazi-dds", version = "25.3.7" }
22+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
23+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
24+
yazi-plugin = { path = "../yazi-plugin", version = "25.3.7" }
25+
yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" }
26+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
2727

2828
# External dependencies
2929
anyhow = { workspace = true }

‎yazi-fs/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-fs"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-ffi = { path = "../yazi-ffi", version = "25.3.2" }
13-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
14-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
12+
yazi-ffi = { path = "../yazi-ffi", version = "25.3.7" }
13+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
14+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
1515

1616
# External dependencies
1717
anyhow = { workspace = true }

‎yazi-macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-macro"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]

‎yazi-plugin/Cargo.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-plugin"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -13,14 +13,14 @@ default = [ "vendored-lua" ]
1313
vendored-lua = [ "mlua/vendored" ]
1414

1515
[dependencies]
16-
yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" }
17-
yazi-boot = { path = "../yazi-boot", version = "25.3.2" }
18-
yazi-config = { path = "../yazi-config", version = "25.3.2" }
19-
yazi-dds = { path = "../yazi-dds", version = "25.3.2" }
20-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
21-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
22-
yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" }
23-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
16+
yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" }
17+
yazi-boot = { path = "../yazi-boot", version = "25.3.7" }
18+
yazi-config = { path = "../yazi-config", version = "25.3.7" }
19+
yazi-dds = { path = "../yazi-dds", version = "25.3.7" }
20+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
21+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
22+
yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" }
23+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
2424

2525
# External dependencies
2626
ansi-to-tui = { workspace = true }

‎yazi-plugin/src/file/file.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use mlua::{AnyUserData, IntoLua, Lua, Table, UserDataRef};
1+
use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, Table, UserDataRef, Value};
22

33
use crate::{bindings::Cha, impl_file_fields, impl_file_methods};
44

@@ -29,8 +29,17 @@ impl File {
2929
}
3030
}
3131

32+
impl FromLua for File {
33+
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
34+
match value {
35+
Value::UserData(ud) => ud.take().map(Self),
36+
_ => Err("Expected a File".into_lua_err()),
37+
}
38+
}
39+
}
40+
3241
impl IntoLua for File {
33-
fn into_lua(self, lua: &Lua) -> mlua::Result<mlua::Value> {
42+
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
3443
lua.create_any_userdata(self.0)?.into_lua(lua)
3544
}
3645
}

‎yazi-plugin/src/fs/fs.rs

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{Composer, Error, bindings::Cha, file::File, url::{Url, UrlRef}};
88
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
99
Composer::make(lua, 10, |lua, key| {
1010
match key {
11+
b"op" => op(lua)?,
1112
b"cwd" => cwd(lua)?,
1213
b"cha" => cha(lua)?,
1314
b"write" => write(lua)?,
@@ -22,6 +23,14 @@ pub fn compose(lua: &Lua) -> mlua::Result<Value> {
2223
})
2324
}
2425

26+
fn op(lua: &Lua) -> mlua::Result<Function> {
27+
lua.create_function(|lua, (name, t): (mlua::String, Table)| match name.as_bytes().as_ref() {
28+
b"part" => super::FilesOp::part(lua, t),
29+
b"done" => super::FilesOp::done(lua, t),
30+
_ => Err("Unknown operation".into_lua_err())?,
31+
})
32+
}
33+
2534
fn cwd(lua: &Lua) -> mlua::Result<Function> {
2635
lua.create_function(|lua, ()| match std::env::current_dir() {
2736
Ok(p) => (Url::from(p), Value::Nil).into_lua_multi(lua),

‎yazi-plugin/src/fs/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#![allow(clippy::module_inception)]
22

3-
yazi_macro::mod_flat!(fs);
3+
yazi_macro::mod_flat!(fs op);

‎yazi-plugin/src/fs/op.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use mlua::{IntoLua, Lua, Table};
2+
3+
use crate::{Id, bindings::Cha, file::File, url::Url};
4+
5+
pub(super) struct FilesOp(yazi_fs::FilesOp);
6+
7+
impl FilesOp {
8+
pub(super) fn part(_: &Lua, t: Table) -> mlua::Result<Self> {
9+
let id: Id = t.raw_get("id")?;
10+
let url: Url = t.raw_get("url")?;
11+
let files: Table = t.raw_get("files")?;
12+
13+
Ok(Self(yazi_fs::FilesOp::Part(
14+
url.0,
15+
files.sequence_values::<File>().map(|f| f.map(|f| f.0)).collect::<mlua::Result<Vec<_>>>()?,
16+
*id,
17+
)))
18+
}
19+
20+
pub(super) fn done(_: &Lua, t: Table) -> mlua::Result<Self> {
21+
let id: Id = t.raw_get("id")?;
22+
let cha: Cha = t.raw_get("cha")?;
23+
let url: Url = t.raw_get("url")?;
24+
25+
Ok(Self(yazi_fs::FilesOp::Done(url.0, *cha, *id)))
26+
}
27+
}
28+
29+
impl IntoLua for FilesOp {
30+
fn into_lua(self, lua: &Lua) -> mlua::Result<mlua::Value> {
31+
lua.create_any_userdata(self.0)?.into_lua(lua)
32+
}
33+
}

‎yazi-plugin/src/id.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::ops::Deref;
2+
3+
use mlua::{FromLua, UserData};
4+
5+
#[derive(Clone, Copy, FromLua)]
6+
pub struct Id(pub yazi_shared::Id);
7+
8+
impl Deref for Id {
9+
type Target = yazi_shared::Id;
10+
11+
#[inline]
12+
fn deref(&self) -> &Self::Target { &self.0 }
13+
}
14+
15+
impl UserData for Id {}

‎yazi-plugin/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod macros;
44

55
yazi_macro::mod_pub!(bindings config elements external file fs isolate loader process pubsub url utils);
66

7-
yazi_macro::mod_flat!(clipboard composer error lua runtime);
7+
yazi_macro::mod_flat!(clipboard composer error id lua runtime);
88

99
pub fn init() -> anyhow::Result<()> {
1010
CLIPBOARD.with(<_>::default);

‎yazi-plugin/src/url/url.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use mlua::{ExternalError, IntoLua, Lua, MetaMethod, UserDataFields, UserDataMethods, UserDataRef, Value};
1+
use mlua::{ExternalError, FromLua, IntoLua, Lua, MetaMethod, UserDataFields, UserDataMethods, UserDataRef, Value};
22

33
pub type UrlRef = UserDataRef<yazi_shared::url::Url>;
44

@@ -54,6 +54,10 @@ impl Url {
5454
Ok(path.ok().map(Self::from))
5555
});
5656

57+
reg.add_method("to_search", |_, me, frag: mlua::String| {
58+
Ok(Self(me.to_search(&frag.to_str()?)))
59+
});
60+
5761
reg.add_meta_method(MetaMethod::Eq, |_, me, other: UrlRef| Ok(me == &*other));
5862
reg.add_meta_method(MetaMethod::ToString, |lua, me, ()| {
5963
lua.create_string(me.as_os_str().as_encoded_bytes())
@@ -67,7 +71,13 @@ impl Url {
6771
pub fn install(lua: &Lua) -> mlua::Result<()> {
6872
lua.globals().raw_set(
6973
"Url",
70-
lua.create_function(|_, url: mlua::String| Ok(Self::from(url.to_str()?.as_ref())))?,
74+
lua.create_function(|_, value: Value| {
75+
Ok(match value {
76+
Value::String(s) => Self::from(s.to_str()?.as_ref()),
77+
Value::UserData(ud) => Self(ud.borrow::<yazi_shared::url::Url>()?.clone()),
78+
_ => Err("Expected a string or a Url".into_lua_err())?,
79+
})
80+
})?,
7181
)
7282
}
7383
}
@@ -76,6 +86,15 @@ impl<T: Into<yazi_shared::url::Url>> From<T> for Url {
7686
fn from(value: T) -> Self { Self(value.into()) }
7787
}
7888

89+
impl FromLua for Url {
90+
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
91+
match value {
92+
Value::UserData(ud) => ud.take().map(Self),
93+
_ => Err("Expected a Url".into_lua_err()),
94+
}
95+
}
96+
}
97+
7998
impl IntoLua for Url {
8099
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
81100
lua.create_any_userdata(self.0)?.into_lua(lua)

‎yazi-plugin/src/utils/app.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ use mlua::{AnyUserData, ExternalError, Function, Lua};
22
use yazi_proxy::{AppProxy, HIDER};
33

44
use super::Utils;
5-
use crate::bindings::{Permit, PermitRef};
5+
use crate::{Id, bindings::{Permit, PermitRef}};
66

77
impl Utils {
8+
pub(super) fn id(lua: &Lua) -> mlua::Result<Function> {
9+
lua.create_function(|_, type_: mlua::String| {
10+
Ok(Id(match type_.as_bytes().as_ref() {
11+
b"ft" => yazi_fs::FILES_TICKET.next(),
12+
_ => Err("Invalid id type".into_lua_err())?,
13+
}))
14+
})
15+
}
16+
817
pub(super) fn hide(lua: &Lua) -> mlua::Result<Function> {
918
lua.create_async_function(|lua, ()| async move {
1019
if lua.named_registry_value::<PermitRef<fn()>>("HIDE_PERMIT").is_ok_and(|h| h.is_some()) {

‎yazi-plugin/src/utils/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Value> {
88
Composer::make(lua, 45, move |lua, key| {
99
match key {
1010
// App
11+
b"id" => Utils::id(lua)?,
1112
b"hide" => Utils::hide(lua)?,
1213

1314
// Cache

‎yazi-proxy/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-proxy"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -13,9 +13,9 @@ default = [ "vendored-lua" ]
1313
vendored-lua = [ "mlua/vendored" ]
1414

1515
[dependencies]
16-
yazi-config = { path = "../yazi-config", version = "25.3.2" }
17-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
18-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
16+
yazi-config = { path = "../yazi-config", version = "25.3.7" }
17+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
18+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
1919

2020
# External dependencies
2121
anyhow = { workspace = true }

‎yazi-scheduler/Cargo.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-scheduler"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -9,13 +9,13 @@ homepage = "https://yazi-rs.github.io"
99
repository = "https://github.com/sxyazi/yazi"
1010

1111
[dependencies]
12-
yazi-config = { path = "../yazi-config", version = "25.3.2" }
13-
yazi-dds = { path = "../yazi-dds", version = "25.3.2" }
14-
yazi-fs = { path = "../yazi-fs", version = "25.3.2" }
15-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
16-
yazi-plugin = { path = "../yazi-plugin", version = "25.3.2" }
17-
yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" }
18-
yazi-shared = { path = "../yazi-shared", version = "25.3.2" }
12+
yazi-config = { path = "../yazi-config", version = "25.3.7" }
13+
yazi-dds = { path = "../yazi-dds", version = "25.3.7" }
14+
yazi-fs = { path = "../yazi-fs", version = "25.3.7" }
15+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
16+
yazi-plugin = { path = "../yazi-plugin", version = "25.3.7" }
17+
yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" }
18+
yazi-shared = { path = "../yazi-shared", version = "25.3.7" }
1919

2020
# External dependencies
2121
anyhow = { workspace = true }

‎yazi-shared/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yazi-shared"
3-
version = "25.3.2"
3+
version = "25.3.7"
44
edition = "2021"
55
license = "MIT"
66
authors = [ "sxyazi <sxyazi@gmail.com>" ]
@@ -10,7 +10,7 @@ repository = "https://github.com/sxyazi/yazi"
1010
rust-version = "1.83.0"
1111

1212
[dependencies]
13-
yazi-macro = { path = "../yazi-macro", version = "25.3.2" }
13+
yazi-macro = { path = "../yazi-macro", version = "25.3.7" }
1414

1515
# External dependencies
1616
anyhow = { workspace = true }

0 commit comments

Comments
 (0)
Please sign in to comment.