diff --git a/Cargo.lock b/Cargo.lock index db0466ad..817a7391 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2595,9 +2595,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.38" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb041120f25f8fbe8fd2dbe4671c7c2ed74d83be2e7a77529bf7e0790ae3f472" +checksum = "dad298b01a40a23aac4580b67e3dbedb7cc8402f3592d7f49469de2ea4aecdd8" dependencies = [ "deranged", "itoa", @@ -3321,7 +3321,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" [[package]] name = "yazi-adapter" -version = "25.3.2" +version = "25.3.7" dependencies = [ "ansi-to-tui", "anyhow", @@ -3342,7 +3342,7 @@ dependencies = [ [[package]] name = "yazi-boot" -version = "25.3.2" +version = "25.3.7" dependencies = [ "clap", "clap_complete", @@ -3360,7 +3360,7 @@ dependencies = [ [[package]] name = "yazi-cli" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "clap", @@ -3383,7 +3383,7 @@ dependencies = [ [[package]] name = "yazi-codegen" -version = "25.3.2" +version = "25.3.7" dependencies = [ "quote", "syn", @@ -3391,7 +3391,7 @@ dependencies = [ [[package]] name = "yazi-config" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "bitflags 2.9.0", @@ -3411,7 +3411,7 @@ dependencies = [ [[package]] name = "yazi-core" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "bitflags 2.9.0", @@ -3445,7 +3445,7 @@ dependencies = [ [[package]] name = "yazi-dds" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "mlua", @@ -3466,7 +3466,7 @@ dependencies = [ [[package]] name = "yazi-ffi" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "core-foundation-sys", @@ -3477,7 +3477,7 @@ dependencies = [ [[package]] name = "yazi-fm" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "better-panic", @@ -3513,7 +3513,7 @@ dependencies = [ [[package]] name = "yazi-fs" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "arc-swap", @@ -3539,11 +3539,11 @@ dependencies = [ [[package]] name = "yazi-macro" -version = "25.3.2" +version = "25.3.7" [[package]] name = "yazi-plugin" -version = "25.3.2" +version = "25.3.7" dependencies = [ "ansi-to-tui", "anyhow", @@ -3584,7 +3584,7 @@ checksum = "f4b6c8e12e39ac0f79fa96f36e5b88e0da8d230691abd729eec709b43c74f632" [[package]] name = "yazi-proxy" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "mlua", @@ -3597,7 +3597,7 @@ dependencies = [ [[package]] name = "yazi-scheduler" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "async-priority-channel", @@ -3620,7 +3620,7 @@ dependencies = [ [[package]] name = "yazi-shared" -version = "25.3.2" +version = "25.3.7" dependencies = [ "anyhow", "crossterm", diff --git a/yazi-adapter/Cargo.toml b/yazi-adapter/Cargo.toml index dbe7e640..46f5aad6 100644 --- a/yazi-adapter/Cargo.toml +++ b/yazi-adapter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-adapter" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-config = { path = "../yazi-config", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-config = { path = "../yazi-config", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies ansi-to-tui = { workspace = true } diff --git a/yazi-boot/Cargo.toml b/yazi-boot/Cargo.toml index 118b2984..da9f6b59 100644 --- a/yazi-boot/Cargo.toml +++ b/yazi-boot/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-boot" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,11 +9,11 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" } -yazi-config = { path = "../yazi-config", version = "25.3.2" } -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" } +yazi-config = { path = "../yazi-config", version = "25.3.7" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies clap = { workspace = true } diff --git a/yazi-cli/Cargo.toml b/yazi-cli/Cargo.toml index c4d8da82..302801dc 100644 --- a/yazi-cli/Cargo.toml +++ b/yazi-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-cli" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,11 +9,11 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-boot = { path = "../yazi-boot", version = "25.3.2" } -yazi-dds = { path = "../yazi-dds", version = "25.3.2" } -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-boot = { path = "../yazi-boot", version = "25.3.7" } +yazi-dds = { path = "../yazi-dds", version = "25.3.7" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } @@ -26,7 +26,7 @@ toml = { workspace = true } twox-hash = { workspace = true } [build-dependencies] -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External build dependencies anyhow = { workspace = true } diff --git a/yazi-codegen/Cargo.toml b/yazi-codegen/Cargo.toml index 2c755b9f..8cadb9bf 100644 --- a/yazi-codegen/Cargo.toml +++ b/yazi-codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-codegen" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] diff --git a/yazi-config/Cargo.toml b/yazi-config/Cargo.toml index 6d2ee35f..a37f6a86 100644 --- a/yazi-config/Cargo.toml +++ b/yazi-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-config" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-core/Cargo.toml b/yazi-core/Cargo.toml index 1b3ced04..d7ad6db4 100644 --- a/yazi-core/Cargo.toml +++ b/yazi-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-core" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,17 +9,17 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" } -yazi-boot = { path = "../yazi-boot", version = "25.3.2" } -yazi-codegen = { path = "../yazi-codegen", version = "25.3.2" } -yazi-config = { path = "../yazi-config", version = "25.3.2" } -yazi-dds = { path = "../yazi-dds", version = "25.3.2" } -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-plugin = { path = "../yazi-plugin", version = "25.3.2" } -yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" } -yazi-scheduler = { path = "../yazi-scheduler", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" } +yazi-boot = { path = "../yazi-boot", version = "25.3.7" } +yazi-codegen = { path = "../yazi-codegen", version = "25.3.7" } +yazi-config = { path = "../yazi-config", version = "25.3.7" } +yazi-dds = { path = "../yazi-dds", version = "25.3.7" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-plugin = { path = "../yazi-plugin", version = "25.3.7" } +yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" } +yazi-scheduler = { path = "../yazi-scheduler", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-dds/Cargo.toml b/yazi-dds/Cargo.toml index e90ba04a..191c4453 100644 --- a/yazi-dds/Cargo.toml +++ b/yazi-dds/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-dds" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -13,10 +13,10 @@ default = [ "vendored-lua" ] vendored-lua = [ "mlua/vendored" ] [dependencies] -yazi-boot = { path = "../yazi-boot", version = "25.3.2" } -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-boot = { path = "../yazi-boot", version = "25.3.7" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-dds/src/sendable.rs b/yazi-dds/src/sendable.rs index a08727a7..a060cab8 100644 --- a/yazi-dds/src/sendable.rs +++ b/yazi-dds/src/sendable.rs @@ -43,6 +43,8 @@ impl Sendable { Value::UserData(ud) => { if let Ok(t) = ud.take::() { Data::Url(t) + } else if let Ok(t) = ud.take::() { + Data::Any(Box::new(t)) } else if let Ok(t) = ud.take::() { Data::Any(Box::new(t)) } else { @@ -72,13 +74,13 @@ impl Sendable { Value::Table(tbl) } Data::Url(u) => Value::UserData(lua.create_any_userdata(u)?), - Data::Any(a) => { - if let Ok(t) = a.downcast::() { - Value::UserData(lua.create_userdata(*t)?) - } else { - Err("unsupported userdata included".into_lua_err())? - } - } + Data::Any(a) => Value::UserData(if a.is::() { + lua.create_any_userdata(*a.downcast::().unwrap())? + } else if a.is::() { + lua.create_userdata(*a.downcast::().unwrap())? + } else { + Err("unsupported userdata included".into_lua_err())? + }), data => Self::data_to_value_ref(lua, &data)?, }) } @@ -107,13 +109,13 @@ impl Sendable { } Data::Url(u) => Value::UserData(lua.create_any_userdata(u.clone())?), Data::Bytes(b) => Value::String(lua.create_string(b)?), - Data::Any(a) => { - if let Some(t) = a.downcast_ref::() { - Value::UserData(lua.create_userdata(t.clone())?) - } else { - Err("unsupported userdata included".into_lua_err())? - } - } + Data::Any(a) => Value::UserData(if let Some(t) = a.downcast_ref::() { + lua.create_any_userdata(t.clone())? + } else if let Some(t) = a.downcast_ref::() { + lua.create_userdata(t.clone())? + } else { + Err("unsupported userdata included".into_lua_err())? + }), }) } diff --git a/yazi-ffi/Cargo.toml b/yazi-ffi/Cargo.toml index 0d7f30ec..873f6545 100644 --- a/yazi-ffi/Cargo.toml +++ b/yazi-ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-ffi" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,7 +9,7 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-fm/Cargo.toml b/yazi-fm/Cargo.toml index 1e881cb3..4dba97a9 100644 --- a/yazi-fm/Cargo.toml +++ b/yazi-fm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-fm" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -13,17 +13,17 @@ default = [ "vendored-lua" ] vendored-lua = [ "mlua/vendored" ] [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" } -yazi-boot = { path = "../yazi-boot", version = "25.3.2" } -yazi-codegen = { path = "../yazi-codegen", version = "25.3.2" } -yazi-config = { path = "../yazi-config", version = "25.3.2" } -yazi-core = { path = "../yazi-core", version = "25.3.2" } -yazi-dds = { path = "../yazi-dds", version = "25.3.2" } -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-plugin = { path = "../yazi-plugin", version = "25.3.2" } -yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" } +yazi-boot = { path = "../yazi-boot", version = "25.3.7" } +yazi-codegen = { path = "../yazi-codegen", version = "25.3.7" } +yazi-config = { path = "../yazi-config", version = "25.3.7" } +yazi-core = { path = "../yazi-core", version = "25.3.7" } +yazi-dds = { path = "../yazi-dds", version = "25.3.7" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-plugin = { path = "../yazi-plugin", version = "25.3.7" } +yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-fs/Cargo.toml b/yazi-fs/Cargo.toml index c3753faf..4b530916 100644 --- a/yazi-fs/Cargo.toml +++ b/yazi-fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-fs" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,9 +9,9 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-ffi = { path = "../yazi-ffi", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-ffi = { path = "../yazi-ffi", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-macro/Cargo.toml b/yazi-macro/Cargo.toml index eb6d8347..2479458d 100644 --- a/yazi-macro/Cargo.toml +++ b/yazi-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-macro" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index 9c2b9169..135d97f2 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-plugin" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -13,14 +13,14 @@ default = [ "vendored-lua" ] vendored-lua = [ "mlua/vendored" ] [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "25.3.2" } -yazi-boot = { path = "../yazi-boot", version = "25.3.2" } -yazi-config = { path = "../yazi-config", version = "25.3.2" } -yazi-dds = { path = "../yazi-dds", version = "25.3.2" } -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-adapter = { path = "../yazi-adapter", version = "25.3.7" } +yazi-boot = { path = "../yazi-boot", version = "25.3.7" } +yazi-config = { path = "../yazi-config", version = "25.3.7" } +yazi-dds = { path = "../yazi-dds", version = "25.3.7" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies ansi-to-tui = { workspace = true } diff --git a/yazi-plugin/src/file/file.rs b/yazi-plugin/src/file/file.rs index bf2f5a8b..53a1006f 100644 --- a/yazi-plugin/src/file/file.rs +++ b/yazi-plugin/src/file/file.rs @@ -1,4 +1,4 @@ -use mlua::{AnyUserData, IntoLua, Lua, Table, UserDataRef}; +use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, Table, UserDataRef, Value}; use crate::{bindings::Cha, impl_file_fields, impl_file_methods}; @@ -29,8 +29,17 @@ impl File { } } +impl FromLua for File { + fn from_lua(value: Value, _: &Lua) -> mlua::Result { + match value { + Value::UserData(ud) => ud.take().map(Self), + _ => Err("Expected a File".into_lua_err()), + } + } +} + impl IntoLua for File { - fn into_lua(self, lua: &Lua) -> mlua::Result { + fn into_lua(self, lua: &Lua) -> mlua::Result { lua.create_any_userdata(self.0)?.into_lua(lua) } } diff --git a/yazi-plugin/src/fs/fs.rs b/yazi-plugin/src/fs/fs.rs index bae09a18..8419514a 100644 --- a/yazi-plugin/src/fs/fs.rs +++ b/yazi-plugin/src/fs/fs.rs @@ -8,6 +8,7 @@ use crate::{Composer, Error, bindings::Cha, file::File, url::{Url, UrlRef}}; pub fn compose(lua: &Lua) -> mlua::Result { Composer::make(lua, 10, |lua, key| { match key { + b"op" => op(lua)?, b"cwd" => cwd(lua)?, b"cha" => cha(lua)?, b"write" => write(lua)?, @@ -22,6 +23,14 @@ pub fn compose(lua: &Lua) -> mlua::Result { }) } +fn op(lua: &Lua) -> mlua::Result { + lua.create_function(|lua, (name, t): (mlua::String, Table)| match name.as_bytes().as_ref() { + b"part" => super::FilesOp::part(lua, t), + b"done" => super::FilesOp::done(lua, t), + _ => Err("Unknown operation".into_lua_err())?, + }) +} + fn cwd(lua: &Lua) -> mlua::Result { lua.create_function(|lua, ()| match std::env::current_dir() { Ok(p) => (Url::from(p), Value::Nil).into_lua_multi(lua), diff --git a/yazi-plugin/src/fs/mod.rs b/yazi-plugin/src/fs/mod.rs index f1b5496e..5d5a2756 100644 --- a/yazi-plugin/src/fs/mod.rs +++ b/yazi-plugin/src/fs/mod.rs @@ -1,3 +1,3 @@ #![allow(clippy::module_inception)] -yazi_macro::mod_flat!(fs); +yazi_macro::mod_flat!(fs op); diff --git a/yazi-plugin/src/fs/op.rs b/yazi-plugin/src/fs/op.rs new file mode 100644 index 00000000..31f687e2 --- /dev/null +++ b/yazi-plugin/src/fs/op.rs @@ -0,0 +1,33 @@ +use mlua::{IntoLua, Lua, Table}; + +use crate::{Id, bindings::Cha, file::File, url::Url}; + +pub(super) struct FilesOp(yazi_fs::FilesOp); + +impl FilesOp { + pub(super) fn part(_: &Lua, t: Table) -> mlua::Result { + let id: Id = t.raw_get("id")?; + let url: Url = t.raw_get("url")?; + let files: Table = t.raw_get("files")?; + + Ok(Self(yazi_fs::FilesOp::Part( + url.0, + files.sequence_values::().map(|f| f.map(|f| f.0)).collect::>>()?, + *id, + ))) + } + + pub(super) fn done(_: &Lua, t: Table) -> mlua::Result { + let id: Id = t.raw_get("id")?; + let cha: Cha = t.raw_get("cha")?; + let url: Url = t.raw_get("url")?; + + Ok(Self(yazi_fs::FilesOp::Done(url.0, *cha, *id))) + } +} + +impl IntoLua for FilesOp { + fn into_lua(self, lua: &Lua) -> mlua::Result { + lua.create_any_userdata(self.0)?.into_lua(lua) + } +} diff --git a/yazi-plugin/src/id.rs b/yazi-plugin/src/id.rs new file mode 100644 index 00000000..8f14e4d4 --- /dev/null +++ b/yazi-plugin/src/id.rs @@ -0,0 +1,15 @@ +use std::ops::Deref; + +use mlua::{FromLua, UserData}; + +#[derive(Clone, Copy, FromLua)] +pub struct Id(pub yazi_shared::Id); + +impl Deref for Id { + type Target = yazi_shared::Id; + + #[inline] + fn deref(&self) -> &Self::Target { &self.0 } +} + +impl UserData for Id {} diff --git a/yazi-plugin/src/lib.rs b/yazi-plugin/src/lib.rs index ca4bb83a..9cbf8e96 100644 --- a/yazi-plugin/src/lib.rs +++ b/yazi-plugin/src/lib.rs @@ -4,7 +4,7 @@ mod macros; yazi_macro::mod_pub!(bindings config elements external file fs isolate loader process pubsub url utils); -yazi_macro::mod_flat!(clipboard composer error lua runtime); +yazi_macro::mod_flat!(clipboard composer error id lua runtime); pub fn init() -> anyhow::Result<()> { CLIPBOARD.with(<_>::default); diff --git a/yazi-plugin/src/url/url.rs b/yazi-plugin/src/url/url.rs index e497d50a..23ec448f 100644 --- a/yazi-plugin/src/url/url.rs +++ b/yazi-plugin/src/url/url.rs @@ -1,4 +1,4 @@ -use mlua::{ExternalError, IntoLua, Lua, MetaMethod, UserDataFields, UserDataMethods, UserDataRef, Value}; +use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, MetaMethod, UserDataFields, UserDataMethods, UserDataRef, Value}; pub type UrlRef = UserDataRef; @@ -54,6 +54,10 @@ impl Url { Ok(path.ok().map(Self::from)) }); + reg.add_function_mut("into_search", |_, (ud, frag): (AnyUserData, mlua::String)| { + Ok(Self(ud.take::()?.into_search(&frag.to_str()?))) + }); + reg.add_meta_method(MetaMethod::Eq, |_, me, other: UrlRef| Ok(me == &*other)); reg.add_meta_method(MetaMethod::ToString, |lua, me, ()| { lua.create_string(me.as_os_str().as_encoded_bytes()) @@ -67,7 +71,13 @@ impl Url { pub fn install(lua: &Lua) -> mlua::Result<()> { lua.globals().raw_set( "Url", - lua.create_function(|_, url: mlua::String| Ok(Self::from(url.to_str()?.as_ref())))?, + lua.create_function(|_, value: Value| { + Ok(match value { + Value::String(s) => Self::from(s.to_str()?.as_ref()), + Value::UserData(ud) => Self(ud.borrow::()?.clone()), + _ => Err("Expected a string or a Url".into_lua_err())?, + }) + })?, ) } } @@ -76,6 +86,15 @@ impl> From for Url { fn from(value: T) -> Self { Self(value.into()) } } +impl FromLua for Url { + fn from_lua(value: Value, _: &Lua) -> mlua::Result { + match value { + Value::UserData(ud) => ud.take().map(Self), + _ => Err("Expected a Url".into_lua_err()), + } + } +} + impl IntoLua for Url { fn into_lua(self, lua: &Lua) -> mlua::Result { lua.create_any_userdata(self.0)?.into_lua(lua) diff --git a/yazi-plugin/src/utils/app.rs b/yazi-plugin/src/utils/app.rs index 154f4064..dee784b8 100644 --- a/yazi-plugin/src/utils/app.rs +++ b/yazi-plugin/src/utils/app.rs @@ -2,9 +2,18 @@ use mlua::{AnyUserData, ExternalError, Function, Lua}; use yazi_proxy::{AppProxy, HIDER}; use super::Utils; -use crate::bindings::{Permit, PermitRef}; +use crate::{Id, bindings::{Permit, PermitRef}}; impl Utils { + pub(super) fn id(lua: &Lua) -> mlua::Result { + lua.create_function(|_, type_: mlua::String| { + Ok(Id(match type_.as_bytes().as_ref() { + b"ft" => yazi_fs::FILES_TICKET.next(), + _ => Err("Invalid id type".into_lua_err())?, + })) + }) + } + pub(super) fn hide(lua: &Lua) -> mlua::Result { lua.create_async_function(|lua, ()| async move { if lua.named_registry_value::>("HIDE_PERMIT").is_ok_and(|h| h.is_some()) { diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 51ef6dff..ff27922f 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -8,6 +8,7 @@ pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result { Composer::make(lua, 45, move |lua, key| { match key { // App + b"id" => Utils::id(lua)?, b"hide" => Utils::hide(lua)?, // Cache diff --git a/yazi-proxy/Cargo.toml b/yazi-proxy/Cargo.toml index 4abe5717..40b77b6c 100644 --- a/yazi-proxy/Cargo.toml +++ b/yazi-proxy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-proxy" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -13,9 +13,9 @@ default = [ "vendored-lua" ] vendored-lua = [ "mlua/vendored" ] [dependencies] -yazi-config = { path = "../yazi-config", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-config = { path = "../yazi-config", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-scheduler/Cargo.toml b/yazi-scheduler/Cargo.toml index 555369e2..85958a41 100644 --- a/yazi-scheduler/Cargo.toml +++ b/yazi-scheduler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-scheduler" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -9,13 +9,13 @@ homepage = "https://yazi-rs.github.io" repository = "https://github.com/sxyazi/yazi" [dependencies] -yazi-config = { path = "../yazi-config", version = "25.3.2" } -yazi-dds = { path = "../yazi-dds", version = "25.3.2" } -yazi-fs = { path = "../yazi-fs", version = "25.3.2" } -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } -yazi-plugin = { path = "../yazi-plugin", version = "25.3.2" } -yazi-proxy = { path = "../yazi-proxy", version = "25.3.2" } -yazi-shared = { path = "../yazi-shared", version = "25.3.2" } +yazi-config = { path = "../yazi-config", version = "25.3.7" } +yazi-dds = { path = "../yazi-dds", version = "25.3.7" } +yazi-fs = { path = "../yazi-fs", version = "25.3.7" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } +yazi-plugin = { path = "../yazi-plugin", version = "25.3.7" } +yazi-proxy = { path = "../yazi-proxy", version = "25.3.7" } +yazi-shared = { path = "../yazi-shared", version = "25.3.7" } # External dependencies anyhow = { workspace = true } diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index e3316b01..67f23ef5 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yazi-shared" -version = "25.3.2" +version = "25.3.7" edition = "2021" license = "MIT" authors = [ "sxyazi " ] @@ -10,7 +10,7 @@ repository = "https://github.com/sxyazi/yazi" rust-version = "1.83.0" [dependencies] -yazi-macro = { path = "../yazi-macro", version = "25.3.2" } +yazi-macro = { path = "../yazi-macro", version = "25.3.7" } # External dependencies anyhow = { workspace = true }