diff --git a/cspell.json b/cspell.json index e7d11ab99..690e62352 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip"],"version":"0.2","language":"en","flagWords":[]} \ No newline at end of file +{"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","fract"],"flagWords":[],"version":"0.2"} \ No newline at end of file diff --git a/yazi-cli/src/args.rs b/yazi-cli/src/args.rs index f314bc2cc..2fd287adf 100644 --- a/yazi-cli/src/args.rs +++ b/yazi-cli/src/args.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, collections::HashMap}; +use std::borrow::Cow; use anyhow::{bail, Result}; use clap::{command, Parser, Subcommand}; @@ -106,10 +106,10 @@ macro_rules! impl_body { Ok(json.into()) } else if let Some(str) = &self.str { Ok(serde_json::to_string(str)?.into()) + } else if !self.list.is_empty() { + Ok(serde_json::to_string(&self.list)?.into()) } else { - let map: HashMap = - self.list.iter().enumerate().map(|(i, s)| (i + 1, s.as_str())).collect(); - Ok(serde_json::to_string(&map)?.into()) + Ok("".into()) } } } diff --git a/yazi-core/src/manager/commands/update_mimetype.rs b/yazi-core/src/manager/commands/update_mimetype.rs index 15f24e0ba..c3720a01a 100644 --- a/yazi-core/src/manager/commands/update_mimetype.rs +++ b/yazi-core/src/manager/commands/update_mimetype.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use tracing::error; use yazi_shared::{event::Cmd, fs::Url, render}; use crate::{manager::{Manager, LINKED}, tasks::Tasks}; @@ -12,14 +13,14 @@ impl TryFrom for Opt { type Error = (); fn try_from(mut c: Cmd) -> Result { - Ok(Self { updates: c.take("updates").ok_or(())?.into_table_string() }) + Ok(Self { updates: c.take("updates").ok_or(())?.into_dict_string() }) } } impl Manager { pub fn update_mimetype(&mut self, opt: impl TryInto, tasks: &Tasks) { let Ok(opt) = opt.try_into() else { - return; + return error!("invalid arguments for update_mimetype"); }; let linked = LINKED.read(); diff --git a/yazi-dds/src/sendable.rs b/yazi-dds/src/sendable.rs index d9957420a..18ad43744 100644 --- a/yazi-dds/src/sendable.rs +++ b/yazi-dds/src/sendable.rs @@ -15,12 +15,22 @@ impl Sendable { Value::Number(n) => Data::Number(n), Value::String(s) => Data::String(s.to_str()?.to_owned()), Value::Table(t) => { - let mut map = HashMap::with_capacity(t.raw_len()); + let (mut i, mut map) = (0, HashMap::with_capacity(t.raw_len())); for result in t.pairs::() { let (k, v) = result?; - map.insert(Self::value_to_key(k)?, Self::value_to_data(v)?); + let k = Self::value_to_key(k)?; + + if k == DataKey::Integer(i) { + i += 1; + } + map.insert(k, Self::value_to_data(v)?); + } + + if i as usize == map.len() { + Data::List(map.into_values().collect()) + } else { + Data::Dict(map) } - Data::Table(map) } Value::Function(_) => Err("function is not supported".into_lua_err())?, Value::Thread(_) => Err("thread is not supported".into_lua_err())?, @@ -44,8 +54,9 @@ impl Sendable { Data::Integer(v) => Value::Integer(v), Data::Number(v) => Value::Number(v), Data::String(v) => Value::String(lua.create_string(v)?), - Data::Table(t) => { - let seq_len = t.keys().filter(|&k| !k.is_numeric()).count(); + Data::List(v) => Value::Table(Self::list_to_table(lua, v)?), + Data::Dict(t) => { + let seq_len = t.keys().filter(|&k| !k.is_integer()).count(); let table = lua.create_table_with_capacity(seq_len, t.len() - seq_len)?; for (k, v) in t { table.raw_set(Self::key_to_value(lua, k)?, Self::data_to_value(lua, v)?)?; @@ -63,7 +74,7 @@ impl Sendable { }) } - pub fn vec_to_table(lua: &Lua, data: Vec) -> mlua::Result { + pub fn list_to_table(lua: &Lua, data: Vec) -> mlua::Result
{ let mut vec = Vec::with_capacity(data.len()); for v in data.into_iter() { vec.push(Self::data_to_value(lua, v)?); @@ -71,7 +82,7 @@ impl Sendable { lua.create_sequence_from(vec) } - pub fn vec_to_variadic(lua: &Lua, data: Vec) -> mlua::Result> { + pub fn list_to_variadic(lua: &Lua, data: Vec) -> mlua::Result> { let mut vec = Vec::with_capacity(data.len()); for v in data { vec.push(Self::data_to_value(lua, v)?); diff --git a/yazi-fm/src/app/commands/plugin.rs b/yazi-fm/src/app/commands/plugin.rs index 7c981dbfe..b5c5f14a0 100644 --- a/yazi-fm/src/app/commands/plugin.rs +++ b/yazi-fm/src/app/commands/plugin.rs @@ -58,7 +58,7 @@ impl App { if let Some(cb) = opt.cb { cb(&LUA, plugin) } else { - plugin.call_method("entry", Sendable::vec_to_table(&LUA, opt.args)?) + plugin.call_method("entry", Sendable::list_to_table(&LUA, opt.args)?) } }); } diff --git a/yazi-plugin/src/isolate/entry.rs b/yazi-plugin/src/isolate/entry.rs index 425e96016..9fea86040 100644 --- a/yazi-plugin/src/isolate/entry.rs +++ b/yazi-plugin/src/isolate/entry.rs @@ -18,7 +18,7 @@ pub async fn entry(name: String, args: Vec) -> mlua::Result<()> { }; Handle::current() - .block_on(plugin.call_async_method("entry", Sendable::vec_to_table(&lua, args))) + .block_on(plugin.call_async_method("entry", Sendable::list_to_table(&lua, args))) }) .await .into_lua_err()? diff --git a/yazi-plugin/src/utils/sync.rs b/yazi-plugin/src/utils/sync.rs index 667c3f44f..99d4a8244 100644 --- a/yazi-plugin/src/utils/sync.rs +++ b/yazi-plugin/src/utils/sync.rs @@ -37,7 +37,7 @@ impl Utils { return Err("`ya.sync()` must be called in a plugin").into_lua_err(); }; - Sendable::vec_to_variadic(lua, Self::retrieve(cur, block, args).await?) + Sendable::list_to_variadic(lua, Self::retrieve(cur, block, args).await?) }) })?, )?; diff --git a/yazi-shared/src/event/data.rs b/yazi-shared/src/event/data.rs index 2b833e7e4..1cd618332 100644 --- a/yazi-shared/src/event/data.rs +++ b/yazi-shared/src/event/data.rs @@ -13,7 +13,8 @@ pub enum Data { Integer(i64), Number(f64), String(String), - Table(HashMap), + List(Vec), + Dict(HashMap), #[serde(skip_deserializing)] Url(Url), #[serde(skip)] @@ -64,13 +65,13 @@ impl Data { } } - pub fn into_table_string(self) -> HashMap { - let Self::Table(table) = self else { + pub fn into_dict_string(self) -> HashMap { + let Self::Dict(dict) = self else { return Default::default(); }; - let mut map = HashMap::with_capacity(table.len()); - for pair in table { + let mut map = HashMap::with_capacity(dict.len()); + for pair in dict { if let (DataKey::String(k), Self::String(v)) = pair { map.insert(k, v); } @@ -103,7 +104,7 @@ pub enum DataKey { impl DataKey { #[inline] - pub fn is_numeric(&self) -> bool { matches!(self, Self::Integer(_) | Self::Number(_)) } + pub fn is_integer(&self) -> bool { matches!(self, Self::Integer(_)) } } // --- Macros diff --git a/yazi-shared/src/number.rs b/yazi-shared/src/number.rs index 3ef13f559..0633a8c78 100644 --- a/yazi-shared/src/number.rs +++ b/yazi-shared/src/number.rs @@ -14,7 +14,7 @@ impl OrderedFloat { } #[inline] - pub fn get(&self) -> f64 { self.0 } + pub const fn get(&self) -> f64 { self.0 } } impl Hash for OrderedFloat {