feat: add children_add and children_remove methods to the Header component as well (#1297)

This commit is contained in:
三咲雅 · Misaki Masa 2024-07-15 14:59:24 +08:00 committed by sxyazi
parent ec33085f67
commit ed6ae000d6
No known key found for this signature in database
14 changed files with 184 additions and 134 deletions

View file

@ -1 +1 @@
{"version":"0.2","language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","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"],"flagWords":[]} {"flagWords":[],"version":"0.2","language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","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"]}

View file

@ -17,15 +17,15 @@ impl App {
}; };
if !opt.sync { if !opt.sync {
return self.cx.tasks.plugin_micro(opt.name, opt.args); return self.cx.tasks.plugin_micro(opt.id, opt.args);
} }
if LOADER.read().contains_key(&opt.name) { if LOADER.read().contains_key(&opt.id) {
return self.plugin_do(opt); return self.plugin_do(opt);
} }
tokio::spawn(async move { tokio::spawn(async move {
if LOADER.ensure(&opt.name).await.is_ok() { if LOADER.ensure(&opt.id).await.is_ok() {
Self::_plugin_do(opt); Self::_plugin_do(opt);
} }
}); });
@ -44,12 +44,12 @@ impl App {
}; };
match LUA.named_registry_value::<RtRef>("rt") { match LUA.named_registry_value::<RtRef>("rt") {
Ok(mut r) => r.swap(&opt.name), Ok(mut r) => r.swap(&opt.id),
Err(e) => return warn!("{e}"), Err(e) => return warn!("{e}"),
} }
defer! { LUA.named_registry_value::<RtRef>("rt").map(|mut r| r.reset()).ok(); }; defer! { LUA.named_registry_value::<RtRef>("rt").map(|mut r| r.reset()).ok(); };
let plugin = match LOADER.load(&opt.name) { let plugin = match LOADER.load(&opt.id) {
Ok(plugin) => plugin, Ok(plugin) => plugin,
Err(e) => return warn!("{e}"), Err(e) => return warn!("{e}"),
}; };

View file

@ -4,37 +4,43 @@ Manager = {}
Folder = {} Folder = {}
File = {} File = {}
local b = false local function warn(name)
function __yazi_check_and_warn_deprecated_api() ya.notify {
if b then title = "Deprecated API",
return content = string.format(
end [[The `%s` global variable has been removed in Yazi v0.3, please remove it from your `init.lua`.
local warn = function(name)
ya.notify {
title = "Deprecated API",
content = string.format(
[[The `%s` global variable has been removed in Yazi v0.3, please remove it from your `init.lua`.
See https://github.com/sxyazi/yazi/pull/1257 for details.]], See https://github.com/sxyazi/yazi/pull/1257 for details.]],
name name
), ),
timeout = 20, timeout = 20,
level = "warn", level = "warn",
} }
end
local b1, b2, b3 = false, false, false
function __yazi_check_and_warn_deprecated_api()
if not b1 then
for _ in pairs(Manager) do
b1 = true
warn("Manager")
break
end
end end
b = true if not b2 then
for _ in pairs(Manager) do for _ in pairs(Folder) do
warn("Manager") b2 = true
break warn("Folder")
break
end
end end
for _ in pairs(Folder) do
warn("Folder") if not b3 then
break for _ in pairs(File) do
end b3 = true
for _ in pairs(File) do warn("File")
warn("File") break
break end
end end
end end

View file

@ -29,14 +29,17 @@ function Current:render()
return self:empty() return self:empty()
end end
local items = {} local entities, linemodes = {}, {}
for _, f in ipairs(files) do for _, f in ipairs(files) do
items[#items + 1] = ui.ListItem(Entity:render(f)):style(Entity:style(f)) linemodes[#linemodes + 1] = Linemode:new(f):render()
local entity = Entity:new(f)
entities[#entities + 1] = ui.ListItem(entity:render()):style(entity:style())
end end
return { return {
ui.List(self._area, items), ui.List(self._area, entities),
ui.Paragraph(self._area, Linemode:render(files)):align(ui.Paragraph.RIGHT), ui.Paragraph(self._area, linemodes):align(ui.Paragraph.RIGHT),
} }
end end

View file

@ -1,37 +1,35 @@
Entity = { Entity = {
_inc = 1000, _inc = 1000,
_children = {
{ "icon", id = 1, order = 1000 },
{ "prefix", id = 2, order = 2000 },
{ "highlights", id = 3, order = 3000 },
{ "found", id = 4, order = 4000 },
{ "symlink", id = 5, order = 5000 },
},
} }
function Entity:style(file) function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end
local style = file:style()
if not file:is_hovered() then
return style
elseif file:in_preview() then
return style and style:patch(THEME.manager.preview_hovered) or THEME.manager.preview_hovered
else
return style and style:patch(THEME.manager.hovered) or THEME.manager.hovered
end
end
function Entity:icon(file) function Entity:icon()
local icon = file:icon() local icon = self._file:icon()
if not icon then if not icon then
return ui.Line("") return ui.Line("")
elseif file:is_hovered() then elseif self._file:is_hovered() then
return ui.Line(" " .. icon.text .. " ") return ui.Line(" " .. icon.text .. " ")
else else
return ui.Line(" " .. icon.text .. " "):style(icon.style) return ui.Line(" " .. icon.text .. " "):style(icon.style)
end end
end end
function Entity:prefix(file) function Entity:prefix()
local prefix = file:prefix() or "" local prefix = self._file:prefix() or ""
return ui.Line(prefix ~= "" and prefix .. "/" or "") return ui.Line(prefix ~= "" and prefix .. "/" or "")
end end
function Entity:highlights(file) function Entity:highlights()
local name = file.name:gsub("\r", "?", 1) local name = self._file.name:gsub("\r", "?", 1)
local highlights = file:highlights() local highlights = self._file:highlights()
if not highlights or #highlights == 0 then if not highlights or #highlights == 0 then
return ui.Line(name) return ui.Line(name)
end end
@ -50,12 +48,12 @@ function Entity:highlights(file)
return ui.Line(spans) return ui.Line(spans)
end end
function Entity:found(file) function Entity:found()
if not file:is_hovered() then if not self._file:is_hovered() then
return ui.Line {} return ui.Line {}
end end
local found = file:found() local found = self._file:found()
if not found then if not found then
return ui.Line {} return ui.Line {}
end end
@ -66,32 +64,35 @@ function Entity:found(file)
} }
end end
function Entity:symlink(file) function Entity:symlink()
if not MANAGER.show_symlink then if not MANAGER.show_symlink then
return ui.Line {} return ui.Line {}
end end
local to = file.link_to local to = self._file.link_to
return ui.Line(to and { ui.Span(" -> " .. tostring(to)):italic() } or {}) return ui.Line(to and { ui.Span(" -> " .. tostring(to)):italic() } or {})
end end
function Entity:render(file) function Entity:render()
local lines = {} local lines = {}
for _, child in ipairs(self._children) do for _, c in ipairs(self._children) do
lines[#lines + 1] = child[1](self, file) lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self)
end end
return ui.Line(lines) return ui.Line(lines)
end end
-- Initialize children function Entity:style()
Entity._children = { local s = self._file:style()
{ Entity.icon, id = 1, order = 1000 }, if not self._file:is_hovered() then
{ Entity.prefix, id = 2, order = 2000 }, return s
{ Entity.highlights, id = 3, order = 3000 }, elseif self._file:in_preview() then
{ Entity.found, id = 4, order = 4000 }, return s and s:patch(THEME.manager.preview_hovered) or THEME.manager.preview_hovered
{ Entity.symlink, id = 5, order = 5000 }, else
} return s and s:patch(THEME.manager.hovered) or THEME.manager.hovered
end
end
-- Children
function Entity:children_add(fn, order) function Entity:children_add(fn, order)
self._inc = self._inc + 1 self._inc = self._inc + 1
self._children[#self._children + 1] = { fn, id = self._inc, order = order } self._children[#self._children + 1] = { fn, id = self._inc, order = order }

View file

@ -1,5 +1,16 @@
Header = { Header = {
LEFT = 0,
RIGHT = 1,
_id = "header", _id = "header",
_inc = 1000,
_left = {
{ "cwd", id = 1, order = 1000 },
},
_right = {
{ "count", id = 1, order = 1000 },
{ "tabs", id = 2, order = 2000 },
},
} }
function Header:new(area, tab) function Header:new(area, tab)
@ -9,7 +20,12 @@ function Header:new(area, tab)
}, { __index = self }) }, { __index = self })
end end
function Header:cwd(max) function Header:cwd()
local max = self._area.w - self._right_width
if max <= 0 then
return ui.Span("")
end
local s = ya.readable_path(tostring(self._tab.current.cwd)) .. self:flags() local s = ya.readable_path(tostring(self._tab.current.cwd)) .. self:flags()
return ui.Span(ya.truncate(s, { max = max, rtl = true })):style(THEME.manager.cwd) return ui.Span(ya.truncate(s, { max = max, rtl = true })):style(THEME.manager.cwd)
end end
@ -75,8 +91,10 @@ function Header:tabs()
end end
function Header:render() function Header:render()
local right = ui.Line { self:count(), self:tabs() } local right = self:children_render(self.RIGHT)
local left = ui.Line { self:cwd(math.max(0, self._area.w - right:width())) } self._right_width = right:width()
local left = self:children_render(self.LEFT)
return { return {
ui.Paragraph(self._area, { left }), ui.Paragraph(self._area, { left }),
ui.Paragraph(self._area, { right }):align(ui.Paragraph.RIGHT), ui.Paragraph(self._area, { right }):align(ui.Paragraph.RIGHT),
@ -89,3 +107,32 @@ function Header:click(event, up) end
function Header:scroll(event, step) end function Header:scroll(event, step) end
function Header:touch(event, step) end function Header:touch(event, step) end
-- Children
function Header:children_add(fn, order, side)
self._inc = self._inc + 1
local children = side == self.RIGHT and self._right or self._left
children[#children + 1] = { fn, id = self._inc, order = order }
table.sort(children, function(a, b) return a.order < b.order end)
return self._inc
end
function Header:children_remove(id, side)
local children = side == self.RIGHT and self._right or self._left
for i, child in ipairs(children) do
if child.id == id then
table.remove(children, i)
break
end
end
end
function Header:children_render(side)
local lines = {}
for _, c in ipairs(side == self.RIGHT and self._right or self._left) do
lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self)
end
return ui.Line(lines)
end

View file

@ -1,8 +1,13 @@
Linemode = { Linemode = {
_inc = 1000, _inc = 1000,
_children = {
{ "solo", id = 1, order = 1000 },
},
} }
function Linemode:solo(file) function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end
function Linemode:solo()
local mode = cx.active.conf.linemode local mode = cx.active.conf.linemode
if mode == "none" or mode == "solo" then if mode == "none" or mode == "solo" then
return ui.Line("") return ui.Line("")
@ -14,18 +19,18 @@ function Linemode:solo(file)
return ui.Line { return ui.Line {
ui.Span(" "), ui.Span(" "),
self[mode](self, file), self[mode](self),
ui.Span(" "), ui.Span(" "),
} }
end end
function Linemode:size(file) function Linemode:size()
local size = file:size() local size = self._file:size()
return ui.Line(size and ya.readable_size(size) or "") return ui.Line(size and ya.readable_size(size) or "")
end end
function Linemode:ctime(file) function Linemode:ctime()
local time = (file.cha.created or 0) // 1 local time = (self._file.cha.created or 0) // 1
if time == 0 then if time == 0 then
return ui.Line("") return ui.Line("")
elseif os.date("%Y", time) == os.date("%Y") then elseif os.date("%Y", time) == os.date("%Y") then
@ -35,8 +40,8 @@ function Linemode:ctime(file)
end end
end end
function Linemode:mtime(file) function Linemode:mtime()
local time = (file.cha.modified or 0) // 1 local time = (self._file.cha.modified or 0) // 1
if time == 0 then if time == 0 then
return ui.Line("") return ui.Line("")
elseif os.date("%Y", time) == os.date("%Y") then elseif os.date("%Y", time) == os.date("%Y") then
@ -46,27 +51,23 @@ function Linemode:mtime(file)
end end
end end
function Linemode:permissions(file) return ui.Line(file.cha:permissions() or "") end function Linemode:permissions() return ui.Line(self._file.cha:permissions() or "") end
function Linemode:owner(file) function Linemode:owner()
local user = file.cha.uid and ya.user_name(file.cha.uid) or file.cha.uid local user = self._file.cha.uid and ya.user_name(self._file.cha.uid) or self._file.cha.uid
local group = file.cha.gid and ya.group_name(file.cha.gid) or file.cha.gid local group = self._file.cha.gid and ya.group_name(self._file.cha.gid) or self._file.cha.gid
return ui.Line(string.format("%s:%s", user or "-", group or "-")) return ui.Line(string.format("%s:%s", user or "-", group or "-"))
end end
function Linemode:render(files) function Linemode:render()
local lines = {} local lines = {}
for _, f in ipairs(files) do for _, c in ipairs(self._children) do
lines[#lines + 1] = self:children_render(f) lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self)
end end
return lines return ui.Line(lines)
end end
-- Initialize children -- Children
Linemode._children = {
{ Linemode.solo, id = 1, order = 1000 },
}
function Linemode:children_add(fn, order) function Linemode:children_add(fn, order)
self._inc = self._inc + 1 self._inc = self._inc + 1
self._children[#self._children + 1] = { fn, id = self._inc, order = order } self._children[#self._children + 1] = { fn, id = self._inc, order = order }
@ -82,11 +83,3 @@ function Linemode:children_remove(id)
end end
end end
end end
function Linemode:children_render(file)
local lines = {}
for _, child in ipairs(self._children) do
lines[#lines + 1] = child[1](self, file)
end
return ui.Line(lines)
end

View file

@ -17,7 +17,8 @@ function Parent:render()
local items = {} local items = {}
for _, f in ipairs(self._folder.window) do for _, f in ipairs(self._folder.window) do
items[#items + 1] = ui.ListItem(Entity:render(f)):style(Entity:style(f)) local entity = Entity:new(f)
items[#items + 1] = ui.ListItem(entity:render()):style(entity:style())
end end
return { return {

View file

@ -4,6 +4,16 @@ Status = {
_id = "status", _id = "status",
_inc = 1000, _inc = 1000,
_left = {
{ "mode", id = 1, order = 1000 },
{ "size", id = 2, order = 2000 },
{ "name", id = 3, order = 3000 },
},
_right = {
{ "permissions", id = 4, order = 1000 },
{ "percentage", id = 5, order = 2000 },
{ "position", id = 6, order = 3000 },
},
} }
function Status:new(area, tab) function Status:new(area, tab)
@ -138,18 +148,7 @@ function Status:scroll(event, step) end
function Status:touch(event, step) end function Status:touch(event, step) end
-- Initialize children -- Children
Status._left = {
{ Status.mode, id = 1, order = 1000 },
{ Status.size, id = 2, order = 2000 },
{ Status.name, id = 3, order = 3000 },
}
Status._right = {
{ Status.permissions, id = 4, order = 1000 },
{ Status.percentage, id = 5, order = 2000 },
{ Status.position, id = 6, order = 3000 },
}
function Status:children_add(fn, order, side) function Status:children_add(fn, order, side)
self._inc = self._inc + 1 self._inc = self._inc + 1
local children = side == self.RIGHT and self._right or self._left local children = side == self.RIGHT and self._right or self._left
@ -172,8 +171,8 @@ end
function Status:children_render(side) function Status:children_render(side)
local lines = {} local lines = {}
for _, child in ipairs(side == self.RIGHT and self._right or self._left) do for _, c in ipairs(side == self.RIGHT and self._right or self._left) do
lines[#lines + 1] = child[1](self) lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self)
end end
return ui.Line(lines) return ui.Line(lines)
end end

View file

@ -20,7 +20,8 @@ function M:peek()
local items = {} local items = {}
for _, f in ipairs(folder.window) do for _, f in ipairs(folder.window) do
items[#items + 1] = ui.ListItem(Entity:render(f)):style(Entity:style(f)) local entity = Entity:new(f)
items[#items + 1] = ui.ListItem(entity:render()):style(entity:style())
end end
ya.preview_widgets(self, { ya.preview_widgets(self, {

View file

@ -65,7 +65,7 @@ pub fn peek_sync(cmd: &Cmd, file: yazi_shared::fs::File, skip: usize) {
}); });
let cmd: Cmd = let cmd: Cmd =
Opt { name: cmd.name.to_owned(), sync: true, cb: Some(cb), ..Default::default() }.into(); Opt { id: cmd.name.to_owned(), sync: true, cb: Some(cb), ..Default::default() }.into();
emit!(Call(cmd.with_name("plugin"), Layer::App)); emit!(Call(cmd.with_name("plugin"), Layer::App));
} }

View file

@ -12,7 +12,7 @@ pub fn seek_sync(cmd: &Cmd, file: yazi_shared::fs::File, units: i16) {
}); });
let cmd: Cmd = let cmd: Cmd =
Opt { name: cmd.name.to_owned(), sync: true, cb: Some(cb), ..Default::default() }.into(); Opt { id: cmd.name.to_owned(), sync: true, cb: Some(cb), ..Default::default() }.into();
emit!(Call(cmd.with_name("plugin"), Layer::App)); emit!(Call(cmd.with_name("plugin"), Layer::App));
} }

View file

@ -52,21 +52,20 @@ impl Loader {
Ok(()) Ok(())
} }
pub fn load(&self, name: &str) -> mlua::Result<Table> { pub fn load(&self, id: &str) -> mlua::Result<Table> {
let globals = LUA.globals(); let globals = LUA.globals();
let loaded: Table = globals.raw_get::<_, Table>("package")?.raw_get("loaded")?; let loaded: Table = globals.raw_get::<_, Table>("package")?.raw_get("loaded")?;
if let Ok(t) = loaded.raw_get::<_, Table>(name) { if let Ok(t) = loaded.raw_get::<_, Table>(id) {
return Ok(t); return Ok(t);
} }
let t: Table = match self.read().get(name) { let t: Table = match self.read().get(id) {
Some(b) => LUA.load(b.as_ref()).set_name(name).call(())?, Some(b) => LUA.load(b.as_ref()).set_name(id).call(())?,
None => Err(format!("plugin `{name}` not found").into_lua_err())?, None => Err(format!("plugin `{id}` not found").into_lua_err())?,
}; };
// TODO: rename to `_id` t.raw_set("_id", LUA.create_string(id)?)?;
t.raw_set("_name", LUA.create_string(name)?)?; loaded.raw_set(id, t.clone())?;
loaded.raw_set(name, t.clone())?;
Ok(t) Ok(t)
} }
} }

View file

@ -6,7 +6,7 @@ pub(super) type OptCallback = Box<dyn FnOnce(&Lua, Table) -> mlua::Result<()> +
#[derive(Default)] #[derive(Default)]
pub struct Opt { pub struct Opt {
pub name: String, pub id: String,
pub sync: bool, pub sync: bool,
pub args: Vec<Data>, pub args: Vec<Data>,
pub cb: Option<OptCallback>, pub cb: Option<OptCallback>,
@ -16,8 +16,8 @@ impl TryFrom<Cmd> for Opt {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(mut c: Cmd) -> Result<Self, Self::Error> { fn try_from(mut c: Cmd) -> Result<Self, Self::Error> {
let Some(name) = c.take_first_str().filter(|s| !s.is_empty()) else { let Some(id) = c.take_first_str().filter(|s| !s.is_empty()) else {
bail!("plugin name cannot be empty"); bail!("plugin id cannot be empty");
}; };
let args = if let Some(s) = c.str("args") { let args = if let Some(s) = c.str("args") {
@ -26,14 +26,14 @@ impl TryFrom<Cmd> for Opt {
c.take_any::<Vec<Data>>("args").unwrap_or_default() c.take_any::<Vec<Data>>("args").unwrap_or_default()
}; };
Ok(Self { name, sync: c.bool("sync"), args, cb: c.take_any("callback") }) Ok(Self { id, sync: c.bool("sync"), args, cb: c.take_any("callback") })
} }
} }
impl From<Opt> for Cmd { impl From<Opt> for Cmd {
fn from(value: Opt) -> Self { fn from(value: Opt) -> Self {
let mut cmd = let mut cmd =
Cmd::args("", vec![value.name]).with_bool("sync", value.sync).with_any("args", value.args); Cmd::args("", vec![value.id]).with_bool("sync", value.sync).with_any("args", value.args);
if let Some(cb) = value.cb { if let Some(cb) = value.cb {
cmd = cmd.with_any("callback", cb); cmd = cmd.with_any("callback", cb);