diff --git a/Cargo.lock b/Cargo.lock index f3c9ed85..28a575b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -274,15 +274,6 @@ dependencies = [ "wyz", ] -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - [[package]] name = "block2" version = "0.5.1" @@ -627,16 +618,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - [[package]] name = "darling" version = "0.20.11" @@ -733,16 +714,6 @@ dependencies = [ "syn", ] -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "dirs" version = "6.0.0" @@ -1023,16 +994,6 @@ dependencies = [ "slab", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.16" @@ -1456,16 +1417,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "md-5" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" -dependencies = [ - "cfg-if", - "digest", -] - [[package]] name = "memchr" version = "2.7.4" @@ -2845,12 +2796,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" -[[package]] -name = "typenum" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" - [[package]] name = "unicode-ident" version = "1.0.18" @@ -2976,12 +2921,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "walkdir" version = "2.5.0" @@ -3606,7 +3545,6 @@ dependencies = [ "futures", "globset", "libc", - "md-5", "mlua", "parking_lot", "paste", diff --git a/Cargo.toml b/Cargo.toml index 539679ca..96324ff7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,6 @@ globset = "0.4.16" indexmap = { version = "2.9.0", features = [ "serde" ] } libc = "0.2.172" lru = "0.14.0" -md-5 = "0.10.6" mlua = { version = "0.10.3", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serialize" ] } objc = "0.2.7" parking_lot = "0.12.3" diff --git a/yazi-binding/src/error.rs b/yazi-binding/src/error.rs index 69feed13..bea31adf 100644 --- a/yazi-binding/src/error.rs +++ b/yazi-binding/src/error.rs @@ -66,11 +66,11 @@ impl UserData for Error { match (lhs, rhs) { (Value::String(l), Value::UserData(r)) => { let r = r.borrow::()?; - lua.create_string([l.as_bytes().as_ref(), r.to_string().as_bytes()].concat()) + lua.create_string([&l.as_bytes(), r.to_string().as_bytes()].concat()) } (Value::UserData(l), Value::String(r)) => { let l = l.borrow::()?; - lua.create_string([l.to_string().as_bytes(), r.as_bytes().as_ref()].concat()) + lua.create_string([l.to_string().as_bytes(), &r.as_bytes()].concat()) } _ => Err("only string can be concatenated with Error".into_lua_err()), } diff --git a/yazi-binding/src/url.rs b/yazi-binding/src/url.rs index 41fd151e..ebf29aaf 100644 --- a/yazi-binding/src/url.rs +++ b/yazi-binding/src/url.rs @@ -138,7 +138,7 @@ impl UserData for Url { lua.create_string(me.as_os_str().as_encoded_bytes()) }); methods.add_meta_method(MetaMethod::Concat, |lua, lhs, rhs: mlua::String| { - lua.create_string([lhs.as_os_str().as_encoded_bytes(), rhs.as_bytes().as_ref()].concat()) + lua.create_string([lhs.as_os_str().as_encoded_bytes(), &rhs.as_bytes()].concat()) }); } } diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index 35c8e6a0..cf807a5f 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -1,4 +1,4 @@ -#![allow(clippy::module_inception, clippy::unit_arg)] +#![allow(clippy::if_same_then_else, clippy::module_inception, clippy::unit_arg)] #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] #[global_allocator] diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index d4ba8f26..188e341e 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -31,7 +31,6 @@ base64 = { workspace = true } crossterm = { workspace = true } futures = { workspace = true } globset = { workspace = true } -md-5 = { workspace = true } mlua = { workspace = true } parking_lot = { workspace = true } paste = { workspace = true } diff --git a/yazi-plugin/preset/plugins/archive.lua b/yazi-plugin/preset/plugins/archive.lua index 575d3422..a32ca5e9 100644 --- a/yazi-plugin/preset/plugins/archive.lua +++ b/yazi-plugin/preset/plugins/archive.lua @@ -48,7 +48,7 @@ function M.spawn_7z(args) local last_err = nil local try = function(name) local stdout = args[1] == "l" and Command.PIPED or Command.NULL - local child, err = Command(name):args(args):stdout(stdout):stderr(Command.PIPED):spawn() + local child, err = Command(name):arg(args):stdout(stdout):stderr(Command.PIPED):spawn() if not child then last_err = err end diff --git a/yazi-plugin/preset/plugins/file.lua b/yazi-plugin/preset/plugins/file.lua index 3713604b..50694ab3 100644 --- a/yazi-plugin/preset/plugins/file.lua +++ b/yazi-plugin/preset/plugins/file.lua @@ -2,7 +2,7 @@ local M = {} function M:peek(job) local cmd = os.getenv("YAZI_FILE_ONE") or "file" - local output, err = Command(cmd):args({ "-bL", "--", tostring(job.file.url) }):stdout(Command.PIPED):output() + local output, err = Command(cmd):arg({ "-bL", "--", tostring(job.file.url) }):stdout(Command.PIPED):output() local text if output then diff --git a/yazi-plugin/preset/plugins/font.lua b/yazi-plugin/preset/plugins/font.lua index fd9d7c53..0aa01d8d 100644 --- a/yazi-plugin/preset/plugins/font.lua +++ b/yazi-plugin/preset/plugins/font.lua @@ -27,7 +27,7 @@ function M:preload(job) return true end - local status, err = Command("magick"):args({ + local status, err = Command("magick"):arg({ "-size", "800x560", "-gravity", diff --git a/yazi-plugin/preset/plugins/json.lua b/yazi-plugin/preset/plugins/json.lua index d1055f35..bb56179b 100644 --- a/yazi-plugin/preset/plugins/json.lua +++ b/yazi-plugin/preset/plugins/json.lua @@ -2,7 +2,7 @@ local M = {} function M:peek(job) local child = Command("jq") - :args({ "-b", "-C", "--tab", ".", tostring(job.file.url) }) + :arg({ "-b", "-C", "--tab", ".", tostring(job.file.url) }) :stdout(Command.PIPED) :stderr(Command.PIPED) :spawn() diff --git a/yazi-plugin/preset/plugins/magick.lua b/yazi-plugin/preset/plugins/magick.lua index db4ec8f5..1844989a 100644 --- a/yazi-plugin/preset/plugins/magick.lua +++ b/yazi-plugin/preset/plugins/magick.lua @@ -50,13 +50,13 @@ function M:spot(job) require("file"):spot(job) end function M.with_limit() local cmd = Command("magick"):args { "-limit", "thread", 1 } if rt.tasks.image_alloc > 0 then - cmd = cmd:args({ "-limit", "memory", rt.tasks.image_alloc }):args { "-limit", "disk", "1MiB" } + cmd:arg { "-limit", "memory", rt.tasks.image_alloc, "-limit", "disk", "1MiB" } end if rt.tasks.image_bound[1] > 0 then - cmd = cmd:args { "-limit", "width", rt.tasks.image_bound[1] } + cmd:arg { "-limit", "width", rt.tasks.image_bound[1] } end if rt.tasks.image_bound[2] > 0 then - cmd = cmd:args { "-limit", "height", rt.tasks.image_bound[2] } + cmd:arg { "-limit", "height", rt.tasks.image_bound[2] } end return cmd end diff --git a/yazi-plugin/preset/plugins/mime.lua b/yazi-plugin/preset/plugins/mime.lua index 863ec7c1..1ba263a9 100644 --- a/yazi-plugin/preset/plugins/mime.lua +++ b/yazi-plugin/preset/plugins/mime.lua @@ -16,7 +16,7 @@ function M:fetch(job) end local cmd = os.getenv("YAZI_FILE_ONE") or "file" - local child, err = Command(cmd):args({ "-bL", "--mime-type", "--" }):args(urls):stdout(Command.PIPED):spawn() + local child, err = Command(cmd):arg({ "-bL", "--mime-type", "--" }):arg(urls):stdout(Command.PIPED):spawn() if not child then return true, Err("Failed to start `%s`, error: %s", cmd, err) end diff --git a/yazi-plugin/preset/plugins/pdf.lua b/yazi-plugin/preset/plugins/pdf.lua index 8cffdfa0..c40b7dce 100644 --- a/yazi-plugin/preset/plugins/pdf.lua +++ b/yazi-plugin/preset/plugins/pdf.lua @@ -33,7 +33,7 @@ function M:preload(job) -- stylua: ignore local output, err = Command("pdftoppm") - :args({ + :arg({ "-f", job.skip + 1, "-l", job.skip + 1, "-singlefile", diff --git a/yazi-plugin/preset/plugins/video.lua b/yazi-plugin/preset/plugins/video.lua index 9a4c8c53..3a0b7057 100644 --- a/yazi-plugin/preset/plugins/video.lua +++ b/yazi-plugin/preset/plugins/video.lua @@ -53,7 +53,7 @@ function M:preload(job) end -- stylua: ignore - local cmd = Command("ffmpeg"):args({ + local cmd = Command("ffmpeg"):arg({ "-v", "quiet", "-threads", 1, "-hwaccel", "auto", "-skip_frame", "nokey", "-an", "-sn", "-dn", @@ -68,7 +68,7 @@ function M:preload(job) end -- stylua: ignore - local status, err = cmd:args({ + local status, err = cmd:arg({ "-vframes", 1, "-q:v", 31 - math.floor(rt.preview.image_quality * 0.3), "-vf", string.format("scale='min(%d,iw)':'min(%d,ih)':force_original_aspect_ratio=decrease:flags=fast_bilinear", rt.preview.max_width, rt.preview.max_height), @@ -131,7 +131,7 @@ function M.list_meta(url, entries) cmd = cmd:args { "-select_streams", "v" } end - local output, err = cmd:args({ "-show_entries", entries, "-of", "json=c=1", tostring(url) }):output() + local output, err = cmd:arg({ "-show_entries", entries, "-of", "json=c=1", tostring(url) }):output() if not output then return nil, Err("Failed to start `ffprobe`, error: %s", err) end diff --git a/yazi-plugin/preset/plugins/zoxide.lua b/yazi-plugin/preset/plugins/zoxide.lua index 9503ce6a..6a9dab18 100644 --- a/yazi-plugin/preset/plugins/zoxide.lua +++ b/yazi-plugin/preset/plugins/zoxide.lua @@ -49,7 +49,7 @@ local function options() end local function empty(cwd) - local child = Command("zoxide"):args({ "query", "-l", "--exclude" }):arg(cwd):stdout(Command.PIPED):spawn() + local child = Command("zoxide"):arg({ "query", "-l", "--exclude", cwd }):stdout(Command.PIPED):spawn() if not child then return true end @@ -89,8 +89,7 @@ local function entry() local _permit = ya.hide() local child, err1 = Command("zoxide") - :args({ "query", "-i", "--exclude" }) - :arg(st.cwd) + :arg({ "query", "-i", "--exclude", st.cwd }) :env("SHELL", "sh") :env("CLICOLOR", 1) :env("CLICOLOR_FORCE", 1) diff --git a/yazi-plugin/src/composer.rs b/yazi-plugin/src/composer.rs index 82c419eb..4f65d2e0 100644 --- a/yazi-plugin/src/composer.rs +++ b/yazi-plugin/src/composer.rs @@ -8,7 +8,7 @@ impl Composer { F: Fn(&Lua, &[u8]) -> mlua::Result + 'static, { let index = lua.create_function(move |lua, (ts, key): (Table, mlua::String)| { - let v = f(lua, key.as_bytes().as_ref())?; + let v = f(lua, &key.as_bytes())?; ts.raw_set(key, v.clone())?; Ok(v) })?; diff --git a/yazi-plugin/src/lib.rs b/yazi-plugin/src/lib.rs index a254bff2..5f648cbb 100644 --- a/yazi-plugin/src/lib.rs +++ b/yazi-plugin/src/lib.rs @@ -1,4 +1,4 @@ -#![allow(clippy::unit_arg)] +#![allow(clippy::if_same_then_else, clippy::unit_arg)] mod macros; diff --git a/yazi-plugin/src/process/command.rs b/yazi-plugin/src/process/command.rs index a956fcd2..f9315fe1 100644 --- a/yazi-plugin/src/process/command.rs +++ b/yazi-plugin/src/process/command.rs @@ -135,11 +135,30 @@ impl UserData for Command { ) } - methods.add_function_mut("arg", |_, (ud, arg): (AnyUserData, mlua::String)| { - ud.borrow_mut::()?.inner.arg(arg.to_string_lossy()); + methods.add_function_mut("arg", |_, (ud, arg): (AnyUserData, Value)| { + { + let mut me = ud.borrow_mut::()?; + match arg { + Value::String(s) => { + me.inner.arg(String::from_utf8_lossy(&s.as_bytes()).as_ref()); + } + Value::Table(t) => { + for s in t.sequence_values::() { + me.inner.arg(String::from_utf8_lossy(&s?.as_bytes()).as_ref()); + } + } + _ => return Err("arg must be a string or table of strings".into_lua_err()), + } + } Ok(ud) }); - methods.add_function_mut("args", |_, (ud, args): (AnyUserData, Vec)| { + // TODO: remove this + methods.add_function_mut("args", |lua, (ud, args): (AnyUserData, Vec)| { + crate::deprecate!( + lua, + "The `args()` method on `Command` is deprecated, use `arg()` instead in your {}\n\nSee #2752 for more details: https://github.com/sxyazi/yazi/pull/2752" + ); + { let mut me = ud.borrow_mut::()?; for arg in args { @@ -155,7 +174,10 @@ impl UserData for Command { methods.add_function_mut( "env", |_, (ud, key, value): (AnyUserData, mlua::String, mlua::String)| { - ud.borrow_mut::()?.inner.env(key.to_string_lossy(), value.to_string_lossy()); + ud.borrow_mut::()?.inner.env( + String::from_utf8_lossy(&key.as_bytes()).as_ref(), + String::from_utf8_lossy(&value.as_bytes()).as_ref(), + ); Ok(ud) }, ); diff --git a/yazi-plugin/src/utils/text.rs b/yazi-plugin/src/utils/text.rs index 809efcb2..a133d68e 100644 --- a/yazi-plugin/src/utils/text.rs +++ b/yazi-plugin/src/utils/text.rs @@ -1,6 +1,4 @@ use std::ops::ControlFlow; - -use md5::{Digest, Md5}; use mlua::{Function, Lua, Table}; use twox_hash::XxHash3_128; use unicode_width::UnicodeWidthChar; @@ -9,17 +7,9 @@ use super::Utils; use crate::CLIPBOARD; impl Utils { - pub(super) fn hash(lua: &Lua, deprecated: bool) -> mlua::Result { - lua.create_async_function(move |lua, s: mlua::String| async move { - if deprecated { - crate::deprecate!( - lua, - "The `ya.md5()` function is deprecated, please use `ya.hash()` instead, in your {}" - ); - Ok(format!("{:x}", Md5::new_with_prefix(s.as_bytes()).finalize())) - } else { - Ok(format!("{:x}", XxHash3_128::oneshot(s.as_bytes().as_ref()))) - } + pub(super) fn hash(lua: &Lua) -> mlua::Result { + lua.create_async_function(move |_, s: mlua::String| async move { + Ok(format!("{:x}", XxHash3_128::oneshot(&s.as_bytes()))) }) } @@ -39,20 +29,20 @@ impl Utils { fn truncate_impl(mut chars: impl Iterator, max: usize) -> Vec { let mut width = 0; let flow = chars.try_fold(Vec::with_capacity(max), |mut v, c| { - width += c.width().unwrap_or(0); + width += c.width().unwrap_or(0); if width < max { v.push(c); ControlFlow::Continue(v) } else { ControlFlow::Break(v) - } + } }); match flow { ControlFlow::Break(v) => v, ControlFlow::Continue(v) => v, } - } + } lua.create_function(|_, (text, t): (mlua::String, Table)| { let (max, text) = (t.raw_get("max")?, text.to_string_lossy()); diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 1c143598..2f0984b3 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -65,7 +65,7 @@ pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result { b"target_family" => Utils::target_family(lua)?, // Text - b"hash" => Utils::hash(lua, false)?, + b"hash" => Utils::hash(lua)?, b"quote" => Utils::quote(lua)?, b"truncate" => Utils::truncate(lua)?, b"clipboard" => Utils::clipboard(lua)?,