From 4e32cd91cabc6d9c8f10eefe34fdf798566ffe8a Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Sun, 2 Mar 2025 20:44:36 +0800 Subject: [PATCH] feat: expose almost the entirety of the user's configuration in Lua (#2413) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 三咲雅 · Misaki Masa --- yazi-plugin/src/config/runtime.rs | 35 +++++++++++++++++++++++++++---- yazi-plugin/src/config/theme.rs | 2 +- yazi-plugin/src/utils/utils.rs | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/yazi-plugin/src/config/runtime.rs b/yazi-plugin/src/config/runtime.rs index 00f840cd..1a745813 100644 --- a/yazi-plugin/src/config/runtime.rs +++ b/yazi-plugin/src/config/runtime.rs @@ -13,7 +13,7 @@ pub struct Runtime<'a> { impl<'a> Runtime<'a> { pub fn compose(lua: &Lua) -> mlua::Result { - Composer::make(lua, 5, |lua, key| { + Composer::make(lua, 10, |lua, key| { match key { b"args" => Self::args(lua)?, b"mgr" => Self::mgr(lua)?, @@ -30,6 +30,7 @@ impl<'a> Runtime<'a> { Composer::make(lua, 5, |lua, key| { match key { b"chooser_file" => ARGS.chooser_file.as_ref().map(Url::from).into_lua(lua)?, + b"cwd_file" => ARGS.cwd_file.as_ref().map(Url::from).into_lua(lua)?, _ => return Ok(Value::Nil), } .into_lua(lua) @@ -37,10 +38,22 @@ impl<'a> Runtime<'a> { } fn mgr(lua: &Lua) -> mlua::Result { - Composer::make(lua, 5, |lua, key| { + Composer::make(lua, 15, |lua, key| { match key { b"ratio" => lua.to_value_with(&MGR.ratio, OPTS)?, + + b"sort_by" => lua.to_value_with(&MGR.sort_by, OPTS)?, + b"sort_sensitive" => lua.to_value_with(&MGR.sort_sensitive, OPTS)?, + b"sort_reverse" => lua.to_value_with(&MGR.sort_reverse, OPTS)?, + b"sort_dir_first" => lua.to_value_with(&MGR.sort_dir_first, OPTS)?, + b"sort_translit" => lua.to_value_with(&MGR.sort_translit, OPTS)?, + + b"linemode" => lua.to_value_with(&MGR.linemode, OPTS)?, + b"show_hidden" => lua.to_value_with(&MGR.show_hidden, OPTS)?, b"show_symlink" => lua.to_value_with(&MGR.show_symlink, OPTS)?, + b"scrolloff" => lua.to_value_with(&MGR.scrolloff, OPTS)?, + b"mouse_events" => lua.to_value_with(&MGR.mouse_events, OPTS)?, + b"title_format" => lua.to_value_with(&MGR.title_format, OPTS)?, _ => return Ok(Value::Nil), } .into_lua(lua) @@ -48,15 +61,22 @@ impl<'a> Runtime<'a> { } fn preview(lua: &Lua) -> mlua::Result { - Composer::make(lua, 10, |lua, key| { + Composer::make(lua, 15, |lua, key| { match key { b"wrap" => lua.to_value_with(&PREVIEW.wrap, OPTS)?, b"tab_size" => lua.to_value_with(&PREVIEW.tab_size, OPTS)?, b"max_width" => lua.to_value_with(&PREVIEW.max_width, OPTS)?, b"max_height" => lua.to_value_with(&PREVIEW.max_height, OPTS)?, + b"cache_dir" => lua.to_value_with(&PREVIEW.cache_dir, OPTS)?, + b"image_delay" => lua.to_value_with(&PREVIEW.image_delay, OPTS)?, + b"image_filter" => lua.to_value_with(&PREVIEW.image_filter, OPTS)?, b"image_quality" => lua.to_value_with(&PREVIEW.image_quality, OPTS)?, + b"sixel_fraction" => lua.to_value_with(&PREVIEW.sixel_fraction, OPTS)?, + + b"ueberzug_scale" => lua.to_value_with(&PREVIEW.ueberzug_scale, OPTS)?, + b"ueberzug_offset" => lua.to_value_with(&PREVIEW.ueberzug_offset, OPTS)?, _ => return Ok(Value::Nil), } .into_lua(lua) @@ -64,9 +84,16 @@ impl<'a> Runtime<'a> { } fn tasks(lua: &Lua) -> mlua::Result { - Composer::make(lua, 5, |lua, key| { + Composer::make(lua, 10, |lua, key| { match key { + b"micro_workers" => lua.to_value_with(&TASKS.micro_workers, OPTS)?, + b"macro_workers" => lua.to_value_with(&TASKS.macro_workers, OPTS)?, + b"bizarre_retry" => lua.to_value_with(&TASKS.bizarre_retry, OPTS)?, + b"image_alloc" => lua.to_value_with(&TASKS.image_alloc, OPTS)?, + b"image_bound" => lua.to_value_with(&TASKS.image_bound, OPTS)?, + + b"suppress_preload" => lua.to_value_with(&TASKS.suppress_preload, OPTS)?, _ => return Ok(Value::Nil), } .into_lua(lua) diff --git a/yazi-plugin/src/config/theme.rs b/yazi-plugin/src/config/theme.rs index 679435e8..06f5b91b 100644 --- a/yazi-plugin/src/config/theme.rs +++ b/yazi-plugin/src/config/theme.rs @@ -8,7 +8,7 @@ pub struct Theme; impl Theme { pub fn compose(lua: &Lua) -> mlua::Result { - Composer::make(lua, 5, |lua, key| { + Composer::make(lua, 15, |lua, key| { match key { b"mgr" => lua.to_value_with(&THEME.mgr, OPTS)?, b"mode" => lua.to_value_with(&THEME.mode, OPTS)?, diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 4b19dd54..51ef6dff 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -5,7 +5,7 @@ use crate::Composer; pub(super) struct Utils; pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result { - Composer::make(lua, 40, move |lua, key| { + Composer::make(lua, 45, move |lua, key| { match key { // App b"hide" => Utils::hide(lua)?,