feat: new cf.args to access startup arguments (#2392)

This commit is contained in:
三咲雅 · Misaki Masa 2025-02-24 00:39:15 +08:00 committed by GitHub
parent 6ca27597f9
commit f11f77d7b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,8 @@
use mlua::{IntoLua, Lua, LuaSerdeExt, SerializeOptions, Value};
use yazi_boot::ARGS;
use yazi_config::{MANAGER, PREVIEW, THEME};
use crate::Composer;
use crate::{Composer, url::Url};
pub const OPTS: SerializeOptions =
SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false);
@ -14,6 +15,7 @@ impl<'a> Config<'a> {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
Composer::make(lua, 5, |lua, key| {
match key {
b"args" => Self::args(lua)?,
b"manager" => Self::manager(lua)?,
b"plugin" => super::Plugin::compose(lua)?,
b"preview" => Self::preview(lua)?,
@ -23,6 +25,16 @@ impl<'a> Config<'a> {
})
}
fn args(lua: &Lua) -> mlua::Result<Value> {
Composer::make(lua, 5, |lua, key| {
match key {
b"chooser_file" => ARGS.chooser_file.as_ref().map(Url::from).into_lua(lua)?,
_ => return Ok(Value::Nil),
}
.into_lua(lua)
})
}
fn manager(lua: &Lua) -> mlua::Result<Value> {
Composer::make(lua, 5, |lua, key| {
match key {