mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: expose almost the entirety of the user's configuration in Lua (#2413)
Co-authored-by: 三咲雅 · Misaki Masa <sxyazi@gmail.com>
This commit is contained in:
parent
94ff413e23
commit
4e32cd91ca
3 changed files with 33 additions and 6 deletions
|
|
@ -13,7 +13,7 @@ pub struct Runtime<'a> {
|
||||||
|
|
||||||
impl<'a> Runtime<'a> {
|
impl<'a> Runtime<'a> {
|
||||||
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||||
Composer::make(lua, 5, |lua, key| {
|
Composer::make(lua, 10, |lua, key| {
|
||||||
match key {
|
match key {
|
||||||
b"args" => Self::args(lua)?,
|
b"args" => Self::args(lua)?,
|
||||||
b"mgr" => Self::mgr(lua)?,
|
b"mgr" => Self::mgr(lua)?,
|
||||||
|
|
@ -30,6 +30,7 @@ impl<'a> Runtime<'a> {
|
||||||
Composer::make(lua, 5, |lua, key| {
|
Composer::make(lua, 5, |lua, key| {
|
||||||
match key {
|
match key {
|
||||||
b"chooser_file" => ARGS.chooser_file.as_ref().map(Url::from).into_lua(lua)?,
|
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),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)
|
.into_lua(lua)
|
||||||
|
|
@ -37,10 +38,22 @@ impl<'a> Runtime<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mgr(lua: &Lua) -> mlua::Result<Value> {
|
fn mgr(lua: &Lua) -> mlua::Result<Value> {
|
||||||
Composer::make(lua, 5, |lua, key| {
|
Composer::make(lua, 15, |lua, key| {
|
||||||
match key {
|
match key {
|
||||||
b"ratio" => lua.to_value_with(&MGR.ratio, OPTS)?,
|
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"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),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)
|
.into_lua(lua)
|
||||||
|
|
@ -48,15 +61,22 @@ impl<'a> Runtime<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preview(lua: &Lua) -> mlua::Result<Value> {
|
fn preview(lua: &Lua) -> mlua::Result<Value> {
|
||||||
Composer::make(lua, 10, |lua, key| {
|
Composer::make(lua, 15, |lua, key| {
|
||||||
match key {
|
match key {
|
||||||
b"wrap" => lua.to_value_with(&PREVIEW.wrap, OPTS)?,
|
b"wrap" => lua.to_value_with(&PREVIEW.wrap, OPTS)?,
|
||||||
b"tab_size" => lua.to_value_with(&PREVIEW.tab_size, 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_width" => lua.to_value_with(&PREVIEW.max_width, OPTS)?,
|
||||||
b"max_height" => lua.to_value_with(&PREVIEW.max_height, 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_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"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),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)
|
.into_lua(lua)
|
||||||
|
|
@ -64,9 +84,16 @@ impl<'a> Runtime<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tasks(lua: &Lua) -> mlua::Result<Value> {
|
fn tasks(lua: &Lua) -> mlua::Result<Value> {
|
||||||
Composer::make(lua, 5, |lua, key| {
|
Composer::make(lua, 10, |lua, key| {
|
||||||
match 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_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),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)
|
.into_lua(lua)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub struct Theme;
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||||
Composer::make(lua, 5, |lua, key| {
|
Composer::make(lua, 15, |lua, key| {
|
||||||
match key {
|
match key {
|
||||||
b"mgr" => lua.to_value_with(&THEME.mgr, OPTS)?,
|
b"mgr" => lua.to_value_with(&THEME.mgr, OPTS)?,
|
||||||
b"mode" => lua.to_value_with(&THEME.mode, OPTS)?,
|
b"mode" => lua.to_value_with(&THEME.mode, OPTS)?,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::Composer;
|
||||||
pub(super) struct Utils;
|
pub(super) struct Utils;
|
||||||
|
|
||||||
pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Value> {
|
pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Value> {
|
||||||
Composer::make(lua, 40, move |lua, key| {
|
Composer::make(lua, 45, move |lua, key| {
|
||||||
match key {
|
match key {
|
||||||
// App
|
// App
|
||||||
b"hide" => Utils::hide(lua)?,
|
b"hide" => Utils::hide(lua)?,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue