mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: new cx.layer API to determine the current UI layer (#2247)
This commit is contained in:
parent
af9a875512
commit
da36cd6ab8
33 changed files with 199 additions and 147 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, pick::Pick, tab::{Folder, Tab}, tasks::Tasks, which::Which};
|
use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, pick::Pick, tab::{Folder, Tab}, tasks::Tasks, which::Which};
|
||||||
|
use yazi_shared::Layer;
|
||||||
|
|
||||||
pub struct Ctx {
|
pub struct Ctx {
|
||||||
pub manager: Manager,
|
pub manager: Manager,
|
||||||
|
|
@ -39,6 +40,29 @@ impl Ctx {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn layer(&self) -> Layer {
|
||||||
|
if self.which.visible {
|
||||||
|
Layer::Which
|
||||||
|
} else if self.completion.visible {
|
||||||
|
Layer::Completion
|
||||||
|
} else if self.help.visible {
|
||||||
|
Layer::Help
|
||||||
|
} else if self.confirm.visible {
|
||||||
|
Layer::Confirm
|
||||||
|
} else if self.input.visible {
|
||||||
|
Layer::Input
|
||||||
|
} else if self.pick.visible {
|
||||||
|
Layer::Pick
|
||||||
|
} else if self.active().spot.visible() {
|
||||||
|
Layer::Spot
|
||||||
|
} else if self.tasks.visible {
|
||||||
|
Layer::Tasks
|
||||||
|
} else {
|
||||||
|
Layer::Manager
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ctx {
|
impl Ctx {
|
||||||
|
|
|
||||||
38
yazi-fm/src/lives/context.rs
Normal file
38
yazi-fm/src/lives/context.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
use mlua::{AnyUserData, IntoLua, MetaMethod, UserData, Value};
|
||||||
|
|
||||||
|
use super::Lives;
|
||||||
|
|
||||||
|
pub(super) struct Ctx {
|
||||||
|
inner: *const crate::Ctx,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for Ctx {
|
||||||
|
type Target = crate::Ctx;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target { unsafe { &*self.inner } }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ctx {
|
||||||
|
#[inline]
|
||||||
|
pub(super) fn make(inner: &crate::Ctx) -> mlua::Result<AnyUserData> {
|
||||||
|
Lives::scoped_userdata(Self { inner })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserData for Ctx {
|
||||||
|
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||||
|
methods.add_meta_method(MetaMethod::Index, |lua, me, key: mlua::String| {
|
||||||
|
match key.as_bytes().as_ref() {
|
||||||
|
b"active" => super::Tab::make(me.active())?,
|
||||||
|
b"tabs" => super::Tabs::make(&me.manager.tabs)?,
|
||||||
|
b"tasks" => super::Tasks::make(&me.tasks)?,
|
||||||
|
b"yanked" => super::Yanked::make(&me.manager.yanked)?,
|
||||||
|
b"layer" => return yazi_plugin::bindings::Layer::from(me.layer()).into_lua(lua),
|
||||||
|
_ => return Ok(Value::Nil),
|
||||||
|
}
|
||||||
|
.into_lua(lua)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,16 +27,7 @@ impl Lives {
|
||||||
});
|
});
|
||||||
|
|
||||||
LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(cx)?)?;
|
LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(cx)?)?;
|
||||||
LUA.globals().raw_set(
|
LUA.globals().raw_set("cx", super::Ctx::make(cx)?)?;
|
||||||
"cx",
|
|
||||||
LUA.create_table_from([
|
|
||||||
("active", super::Tab::make(cx.active())?),
|
|
||||||
("tabs", super::Tabs::make(&cx.manager.tabs)?),
|
|
||||||
("tasks", super::Tasks::make(&cx.tasks)?),
|
|
||||||
("yanked", super::Yanked::make(&cx.manager.yanked)?),
|
|
||||||
])?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
f()
|
f()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
#![allow(clippy::module_inception)]
|
#![allow(clippy::module_inception)]
|
||||||
|
|
||||||
yazi_macro::mod_flat!(
|
yazi_macro::mod_flat!(context file files filter finder folder iter lives mode preference preview selected tab tabs tasks yanked);
|
||||||
preference file files filter finder folder iter lives mode preview selected tab tabs
|
|
||||||
tasks yanked
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,8 @@ impl<'a> Router<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn route(&mut self, key: Key) -> bool {
|
pub(super) fn route(&mut self, key: Key) -> bool {
|
||||||
let cx = &mut self.app.cx;
|
let cx = &mut self.app.cx;
|
||||||
|
let layer = cx.layer();
|
||||||
|
|
||||||
if cx.which.visible {
|
|
||||||
return cx.which.type_(key);
|
|
||||||
}
|
|
||||||
if cx.help.visible && cx.help.type_(&key) {
|
if cx.help.visible && cx.help.type_(&key) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -26,22 +24,14 @@ impl<'a> Router<'a> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if cx.completion.visible {
|
use Layer as L;
|
||||||
self.matches(Layer::Completion, key) || self.matches(Layer::Input, key)
|
match layer {
|
||||||
} else if cx.help.visible {
|
L::App => unreachable!(),
|
||||||
self.matches(Layer::Help, key)
|
L::Manager | L::Tasks | L::Spot | L::Pick | L::Input | L::Confirm | L::Help => {
|
||||||
} else if cx.input.visible {
|
self.matches(layer, key)
|
||||||
self.matches(Layer::Input, key)
|
}
|
||||||
} else if cx.confirm.visible {
|
L::Completion => self.matches(L::Completion, key) || self.matches(L::Input, key),
|
||||||
self.matches(Layer::Confirm, key)
|
L::Which => cx.which.type_(key),
|
||||||
} else if cx.pick.visible {
|
|
||||||
self.matches(Layer::Pick, key)
|
|
||||||
} else if cx.active().spot.visible() {
|
|
||||||
self.matches(Layer::Spot, key)
|
|
||||||
} else if cx.tasks.visible {
|
|
||||||
self.matches(Layer::Tasks, key)
|
|
||||||
} else {
|
|
||||||
self.matches(Layer::Manager, key)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
Entity = {
|
Entity = {
|
||||||
_inc = 1000,
|
_inc = 1000,
|
||||||
_children = {
|
_children = {
|
||||||
{ "space", id = 1, order = 1000 },
|
{ "spacer", id = 1, order = 1000 },
|
||||||
{ "icon", id = 2, order = 2000 },
|
{ "icon", id = 2, order = 2000 },
|
||||||
{ "prefix", id = 3, order = 3000 },
|
{ "prefix", id = 3, order = 3000 },
|
||||||
{ "highlights", id = 4, order = 4000 },
|
{ "highlights", id = 4, order = 4000 },
|
||||||
|
|
@ -12,7 +12,7 @@ Entity = {
|
||||||
|
|
||||||
function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
||||||
|
|
||||||
function Entity:space() return " " end
|
function Entity:spacer() return " " end
|
||||||
|
|
||||||
function Entity:icon()
|
function Entity:icon()
|
||||||
local icon = self._file:icon()
|
local icon = self._file:icon()
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ Linemode = {
|
||||||
_inc = 1000,
|
_inc = 1000,
|
||||||
_children = {
|
_children = {
|
||||||
{ "solo", id = 1, order = 1000 },
|
{ "solo", id = 1, order = 1000 },
|
||||||
{ "space", id = 2, order = 2000 },
|
{ "spacer", id = 2, order = 2000 },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
||||||
|
|
||||||
function Linemode:space() return " " end
|
function Linemode:spacer() return " " end
|
||||||
|
|
||||||
function Linemode:solo()
|
function Linemode:solo()
|
||||||
local mode = cx.active.pref.linemode
|
local mode = cx.active.pref.linemode
|
||||||
|
|
|
||||||
|
|
@ -48,16 +48,25 @@ end
|
||||||
|
|
||||||
-- Mouse events
|
-- Mouse events
|
||||||
function Root:click(event, up)
|
function Root:click(event, up)
|
||||||
|
if tostring(cx.layer) ~= "manager" then
|
||||||
|
return
|
||||||
|
end
|
||||||
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
||||||
return c and c:click(event, up)
|
return c and c:click(event, up)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Root:scroll(event, step)
|
function Root:scroll(event, step)
|
||||||
|
if tostring(cx.layer) ~= "manager" then
|
||||||
|
return
|
||||||
|
end
|
||||||
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
||||||
return c and c:scroll(event, step)
|
return c and c:scroll(event, step)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Root:touch(event, step)
|
function Root:touch(event, step)
|
||||||
|
if tostring(cx.layer) ~= "manager" then
|
||||||
|
return
|
||||||
|
end
|
||||||
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
||||||
return c and c:touch(event, step)
|
return c and c:touch(event, step)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
14
yazi-plugin/src/bindings/layer.rs
Normal file
14
yazi-plugin/src/bindings/layer.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
use mlua::{MetaMethod, UserData};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct Layer(yazi_shared::Layer);
|
||||||
|
|
||||||
|
impl From<yazi_shared::Layer> for Layer {
|
||||||
|
fn from(event: yazi_shared::Layer) -> Self { Self(event) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserData for Layer {
|
||||||
|
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||||
|
methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.0.to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
#![allow(clippy::module_inception)]
|
#![allow(clippy::module_inception)]
|
||||||
|
|
||||||
yazi_macro::mod_flat!(bindings cha chan icon image input mouse permit range window);
|
yazi_macro::mod_flat!(bindings cha chan icon image input layer mouse permit range window);
|
||||||
|
|
|
||||||
20
yazi-plugin/src/composer.rs
Normal file
20
yazi-plugin/src/composer.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
use mlua::{IntoLua, Lua, MetaMethod, Table, Value};
|
||||||
|
|
||||||
|
pub struct Composer;
|
||||||
|
|
||||||
|
impl Composer {
|
||||||
|
pub fn make<F>(lua: &Lua, cap: usize, f: F) -> mlua::Result<Value>
|
||||||
|
where
|
||||||
|
F: Fn(&Lua, &[u8]) -> mlua::Result<Value> + 'static,
|
||||||
|
{
|
||||||
|
let index = lua.create_function(move |lua, (ts, key): (Table, mlua::String)| {
|
||||||
|
let v = f(lua, key.as_bytes().as_ref())?;
|
||||||
|
ts.raw_set(key, v.clone())?;
|
||||||
|
Ok(v)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let tbl = lua.create_table_with_capacity(0, cap)?;
|
||||||
|
tbl.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
|
||||||
|
tbl.into_lua(lua)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use mlua::{IntoLua, Lua, LuaSerdeExt, MetaMethod, SerializeOptions, Table, Value};
|
use mlua::{IntoLua, Lua, LuaSerdeExt, SerializeOptions, Value};
|
||||||
use yazi_boot::BOOT;
|
use yazi_boot::BOOT;
|
||||||
use yazi_config::{MANAGER, PREVIEW, THEME};
|
use yazi_config::{MANAGER, PREVIEW, THEME};
|
||||||
|
|
||||||
use super::Plugin;
|
use super::Plugin;
|
||||||
|
use crate::Composer;
|
||||||
|
|
||||||
pub const SER_OPTS: SerializeOptions =
|
pub const SER_OPTS: SerializeOptions =
|
||||||
SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false);
|
SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false);
|
||||||
|
|
@ -35,24 +36,19 @@ impl<'a> Config<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn install_plugin(self) -> mlua::Result<Self> {
|
pub fn install_plugin(self) -> mlua::Result<Self> {
|
||||||
let index = self.lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
|
self.lua.globals().raw_set(
|
||||||
let value = match key.as_bytes().as_ref() {
|
"PLUGIN",
|
||||||
b"fetchers" => Plugin::fetchers(lua)?,
|
Composer::make(self.lua, 5, |lua, name| {
|
||||||
b"spotter" => Plugin::spotter(lua)?,
|
match name {
|
||||||
b"preloaders" => Plugin::preloaders(lua)?,
|
b"fetchers" => Plugin::fetchers(lua)?,
|
||||||
b"previewer" => Plugin::previewer(lua)?,
|
b"spotter" => Plugin::spotter(lua)?,
|
||||||
_ => return Ok(Value::Nil),
|
b"preloaders" => Plugin::preloaders(lua)?,
|
||||||
}
|
b"previewer" => Plugin::previewer(lua)?,
|
||||||
.into_lua(lua)?;
|
_ => return Ok(Value::Nil),
|
||||||
|
}
|
||||||
ts.raw_set(key, value.clone())?;
|
.into_lua(lua)
|
||||||
Ok(value)
|
})?,
|
||||||
})?;
|
)?;
|
||||||
|
|
||||||
let fetcher = self.lua.create_table()?;
|
|
||||||
fetcher.set_metatable(Some(self.lua.create_table_from([(MetaMethod::Index.name(), index)])?));
|
|
||||||
|
|
||||||
self.lua.globals().raw_set("PLUGIN", fetcher)?;
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{Lua, Table, UserData};
|
use mlua::{Lua, MetaMethod, Table, UserData};
|
||||||
use ratatui::widgets::Borders;
|
use ratatui::widgets::Borders;
|
||||||
|
|
||||||
use super::Area;
|
use super::Area;
|
||||||
|
|
@ -28,7 +28,7 @@ impl Bar {
|
||||||
("ALL", Borders::ALL.bits()),
|
("ALL", Borders::ALL.bits()),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
bar.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
bar.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
Ok(bar)
|
Ok(bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{Lua, Table, UserData, Value};
|
use mlua::{Lua, MetaMethod, Table, UserData, Value};
|
||||||
use ratatui::widgets::{Borders, Widget};
|
use ratatui::widgets::{Borders, Widget};
|
||||||
|
|
||||||
use super::Area;
|
use super::Area;
|
||||||
|
|
@ -49,7 +49,7 @@ impl Border {
|
||||||
("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE),
|
("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
border.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
border.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
Ok(border)
|
Ok(border)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use mlua::{Lua, Table, UserData};
|
use mlua::{Lua, MetaMethod, Table, UserData};
|
||||||
use yazi_adapter::ADAPTOR;
|
use yazi_adapter::ADAPTOR;
|
||||||
|
|
||||||
use super::Area;
|
use super::Area;
|
||||||
|
|
@ -17,7 +17,7 @@ impl Clear {
|
||||||
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Clear { area }))?;
|
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Clear { area }))?;
|
||||||
|
|
||||||
let clear = lua.create_table()?;
|
let clear = lua.create_table()?;
|
||||||
clear.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
clear.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(clear)
|
Ok(clear)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, Value};
|
use mlua::{AnyUserData, IntoLua, Lua, Table, Value};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use super::Renderable;
|
use super::Renderable;
|
||||||
|
use crate::Composer;
|
||||||
|
|
||||||
pub fn compose(lua: &Lua) -> mlua::Result<Table> {
|
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||||
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
|
Composer::make(lua, 20, |lua, key| {
|
||||||
let value = match key.as_bytes().as_ref() {
|
match key {
|
||||||
b"Bar" => super::Bar::compose(lua)?,
|
b"Bar" => super::Bar::compose(lua)?,
|
||||||
b"Border" => super::Border::compose(lua)?,
|
b"Border" => super::Border::compose(lua)?,
|
||||||
b"Clear" => super::Clear::compose(lua)?,
|
b"Clear" => super::Clear::compose(lua)?,
|
||||||
|
|
@ -26,16 +27,8 @@ pub fn compose(lua: &Lua) -> mlua::Result<Table> {
|
||||||
b"Text" => super::Text::compose(lua)?,
|
b"Text" => super::Text::compose(lua)?,
|
||||||
_ => return Ok(Value::Nil),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)?;
|
.into_lua(lua)
|
||||||
|
})
|
||||||
ts.raw_set(key, value.clone())?;
|
|
||||||
Ok(value)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let ui = lua.create_table_with_capacity(0, 20)?;
|
|
||||||
ui.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
|
|
||||||
|
|
||||||
Ok(ui)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_once<F>(widgets: Table, buf: &mut ratatui::buffer::Buffer, trans: F)
|
pub fn render_once<F>(widgets: Table, buf: &mut ratatui::buffer::Buffer, trans: F)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{ExternalError, Lua, Table, UserData, UserDataMethods, Value};
|
use mlua::{ExternalError, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||||
use ratatui::widgets::Widget;
|
use ratatui::widgets::Widget;
|
||||||
|
|
||||||
use super::{Area, Span};
|
use super::{Area, Span};
|
||||||
|
|
@ -19,7 +19,7 @@ impl Gauge {
|
||||||
let new = lua.create_function(|_, _: Table| Ok(Gauge::default()))?;
|
let new = lua.create_function(|_, _: Table| Ok(Gauge::default()))?;
|
||||||
|
|
||||||
let gauge = lua.create_table()?;
|
let gauge = lua.create_table()?;
|
||||||
gauge.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
gauge.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(gauge)
|
Ok(gauge)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{AnyUserData, Lua, Table, UserData, UserDataMethods};
|
use mlua::{AnyUserData, Lua, MetaMethod, Table, UserData, UserDataMethods};
|
||||||
|
|
||||||
use super::{Constraint, Rect};
|
use super::{Constraint, Rect};
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ impl Layout {
|
||||||
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
|
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
|
||||||
|
|
||||||
let layout = lua.create_table_from([("HORIZONTAL", HORIZONTAL), ("VERTICAL", VERTICAL)])?;
|
let layout = lua.create_table_from([("HORIZONTAL", HORIZONTAL), ("VERTICAL", VERTICAL)])?;
|
||||||
layout.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
layout.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(layout)
|
Ok(layout)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use ansi_to_tui::IntoText;
|
use ansi_to_tui::IntoText;
|
||||||
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, Table, UserData, UserDataMethods, Value};
|
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
use super::Span;
|
use super::Span;
|
||||||
|
|
@ -41,7 +41,7 @@ impl Line {
|
||||||
("RIGHT", RIGHT.into_lua(lua)?),
|
("RIGHT", RIGHT.into_lua(lua)?),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
line.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
line.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
Ok(line)
|
Ok(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{ExternalError, Lua, Table, UserData, Value};
|
use mlua::{ExternalError, Lua, MetaMethod, Table, UserData, Value};
|
||||||
use ratatui::widgets::Widget;
|
use ratatui::widgets::Widget;
|
||||||
|
|
||||||
use super::{Area, Text};
|
use super::{Area, Text};
|
||||||
|
|
@ -25,7 +25,7 @@ impl List {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let list = lua.create_table()?;
|
let list = lua.create_table()?;
|
||||||
list.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
list.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::{Add, AddAssign, Deref};
|
use std::ops::{Add, AddAssign, Deref};
|
||||||
|
|
||||||
use mlua::{FromLua, Lua, Table, UserData};
|
use mlua::{FromLua, Lua, MetaMethod, Table, UserData};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, FromLua)]
|
#[derive(Clone, Copy, Default, FromLua)]
|
||||||
pub struct Pad(ratatui::widgets::Padding);
|
pub struct Pad(ratatui::widgets::Padding);
|
||||||
|
|
@ -51,7 +51,7 @@ impl Pad {
|
||||||
),
|
),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
pad.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
pad.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
Ok(pad)
|
Ok(pad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{ops::Deref, str::FromStr};
|
use std::{ops::Deref, str::FromStr};
|
||||||
|
|
||||||
use mlua::{AnyUserData, ExternalResult, Lua, Table, UserData};
|
use mlua::{AnyUserData, ExternalResult, Lua, MetaMethod, Table, UserData};
|
||||||
|
|
||||||
use super::Pad;
|
use super::Pad;
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ impl Pos {
|
||||||
let new = lua.create_function(|_, (_, t): (Table, Table)| Self::try_from(t))?;
|
let new = lua.create_function(|_, (_, t): (Table, Table)| Self::try_from(t))?;
|
||||||
|
|
||||||
let position = lua.create_table()?;
|
let position = lua.create_table()?;
|
||||||
position.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
position.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(position)
|
Ok(position)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use mlua::{FromLua, Lua, Table, UserData};
|
use mlua::{FromLua, Lua, MetaMethod, Table, UserData};
|
||||||
|
|
||||||
use super::Pad;
|
use super::Pad;
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ impl Rect {
|
||||||
|
|
||||||
let rect = lua.create_table_from([("default", Self(ratatui::layout::Rect::default()))])?;
|
let rect = lua.create_table_from([("default", Self(ratatui::layout::Rect::default()))])?;
|
||||||
|
|
||||||
rect.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
rect.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
Ok(rect)
|
Ok(rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{AnyUserData, FromLua, Lua, Table, UserData};
|
use mlua::{AnyUserData, FromLua, Lua, MetaMethod, Table, UserData};
|
||||||
|
|
||||||
use super::Cell;
|
use super::Cell;
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ impl Row {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let row = lua.create_table()?;
|
let row = lua.create_table()?;
|
||||||
row.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
row.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(row)
|
Ok(row)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{ExternalError, FromLua, Lua, Table, UserData, UserDataMethods, Value};
|
use mlua::{ExternalError, FromLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
const EXPECTED: &str = "expected a string or Span";
|
const EXPECTED: &str = "expected a string or Span";
|
||||||
|
|
@ -11,7 +11,7 @@ impl Span {
|
||||||
let new = lua.create_function(|_, (_, value): (Table, Value)| Span::try_from(value))?;
|
let new = lua.create_function(|_, (_, value): (Table, Value)| Span::try_from(value))?;
|
||||||
|
|
||||||
let span = lua.create_table()?;
|
let span = lua.create_table()?;
|
||||||
span.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
span.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(span)
|
Ok(span)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use mlua::{AnyUserData, ExternalError, ExternalResult, Lua, Table, UserData, UserDataMethods, Value};
|
use mlua::{AnyUserData, ExternalError, ExternalResult, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
|
||||||
use yazi_shared::theme::Color;
|
use yazi_shared::theme::Color;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default)]
|
#[derive(Clone, Copy, Default)]
|
||||||
|
|
@ -11,7 +11,7 @@ impl Style {
|
||||||
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
|
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
|
||||||
|
|
||||||
let style = lua.create_table()?;
|
let style = lua.create_table()?;
|
||||||
style.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
style.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(style)
|
Ok(style)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use mlua::{AnyUserData, Lua, UserData, Value};
|
use mlua::{AnyUserData, Lua, MetaMethod, UserData, Value};
|
||||||
use ratatui::widgets::StatefulWidget;
|
use ratatui::widgets::StatefulWidget;
|
||||||
|
|
||||||
use super::{Area, Row};
|
use super::{Area, Row};
|
||||||
|
|
@ -36,7 +36,7 @@ impl Table {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let table = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
table.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
table.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
Ok(table)
|
Ok(table)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use ansi_to_tui::IntoText;
|
use ansi_to_tui::IntoText;
|
||||||
use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, Table, UserData, Value};
|
use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||||
use ratatui::widgets::Widget;
|
use ratatui::widgets::Widget;
|
||||||
|
|
||||||
use super::{Area, Line, Span};
|
use super::{Area, Line, Span};
|
||||||
|
|
@ -48,7 +48,7 @@ impl Text {
|
||||||
("WRAP_TRIM", WRAP_TRIM.into_lua(lua)?),
|
("WRAP_TRIM", WRAP_TRIM.into_lua(lua)?),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
text.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
text.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
Ok(text)
|
Ok(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
use globset::GlobBuilder;
|
use globset::GlobBuilder;
|
||||||
use mlua::{ExternalError, ExternalResult, Function, IntoLua, IntoLuaMulti, Lua, MetaMethod, Table, Value};
|
use mlua::{ExternalError, ExternalResult, Function, IntoLua, IntoLuaMulti, Lua, Table, Value};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use yazi_fs::{mounts::PARTITIONS, remove_dir_clean};
|
use yazi_fs::{mounts::PARTITIONS, remove_dir_clean};
|
||||||
|
|
||||||
use crate::{Error, bindings::{Cast, Cha}, file::File, url::{Url, UrlRef}};
|
use crate::{Composer, Error, bindings::{Cast, Cha}, file::File, url::{Url, UrlRef}};
|
||||||
|
|
||||||
pub fn compose(lua: &Lua) -> mlua::Result<Table> {
|
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||||
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
|
Composer::make(lua, 10, |lua, key| {
|
||||||
let value = match key.as_bytes().as_ref() {
|
match key {
|
||||||
b"cwd" => cwd(lua)?,
|
b"cwd" => cwd(lua)?,
|
||||||
b"cha" => cha(lua)?,
|
b"cha" => cha(lua)?,
|
||||||
b"write" => write(lua)?,
|
b"write" => write(lua)?,
|
||||||
|
|
@ -18,16 +18,8 @@ pub fn compose(lua: &Lua) -> mlua::Result<Table> {
|
||||||
b"partitions" => partitions(lua)?,
|
b"partitions" => partitions(lua)?,
|
||||||
_ => return Ok(Value::Nil),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)?;
|
.into_lua(lua)
|
||||||
|
})
|
||||||
ts.raw_set(key, value.clone())?;
|
|
||||||
Ok(value)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let fs = lua.create_table_with_capacity(0, 10)?;
|
|
||||||
fs.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
|
|
||||||
|
|
||||||
Ok(fs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cwd(lua: &Lua) -> mlua::Result<Function> {
|
fn cwd(lua: &Lua) -> mlua::Result<Function> {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ mod macros;
|
||||||
|
|
||||||
yazi_macro::mod_pub!(bindings config elements external file fs isolate loader process pubsub url utils);
|
yazi_macro::mod_pub!(bindings config elements external file fs isolate loader process pubsub url utils);
|
||||||
|
|
||||||
yazi_macro::mod_flat!(clipboard error lua runtime);
|
yazi_macro::mod_flat!(clipboard composer error lua runtime);
|
||||||
|
|
||||||
pub fn init() -> anyhow::Result<()> {
|
pub fn init() -> anyhow::Result<()> {
|
||||||
CLIPBOARD.with(<_>::default);
|
CLIPBOARD.with(<_>::default);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
use mlua::{AnyUserData, ExternalError, IntoLuaMulti, Lua, Table, UserData, Value};
|
use mlua::{AnyUserData, ExternalError, IntoLuaMulti, Lua, MetaMethod, Table, UserData, Value};
|
||||||
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
|
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
|
||||||
|
|
||||||
use super::{Child, output::Output};
|
use super::{Child, output::Output};
|
||||||
|
|
@ -30,7 +30,7 @@ impl Command {
|
||||||
("INHERIT", INHERIT),
|
("INHERIT", INHERIT),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
command.set_metatable(Some(lua.create_table_from([("__call", new)])?));
|
command.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
||||||
|
|
||||||
lua.globals().raw_set("Command", command)
|
lua.globals().raw_set("Command", command)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
#![allow(clippy::module_inception)]
|
#![allow(clippy::module_inception)]
|
||||||
|
|
||||||
use mlua::{IntoLua, Lua, MetaMethod, Table, Value};
|
use mlua::{IntoLua, Lua, Value};
|
||||||
|
|
||||||
|
use crate::Composer;
|
||||||
|
|
||||||
yazi_macro::mod_flat!(pubsub);
|
yazi_macro::mod_flat!(pubsub);
|
||||||
|
|
||||||
pub(super) fn compose(lua: &Lua) -> mlua::Result<Table> {
|
pub(super) fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||||
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
|
Composer::make(lua, 10, |lua, key| {
|
||||||
let value = match key.as_bytes().as_ref() {
|
match key {
|
||||||
b"pub" => Pubsub::pub_(lua)?,
|
b"pub" => Pubsub::pub_(lua)?,
|
||||||
b"pub_to" => Pubsub::pub_to(lua)?,
|
b"pub_to" => Pubsub::pub_to(lua)?,
|
||||||
b"sub" => Pubsub::sub(lua)?,
|
b"sub" => Pubsub::sub(lua)?,
|
||||||
|
|
@ -15,14 +17,6 @@ pub(super) fn compose(lua: &Lua) -> mlua::Result<Table> {
|
||||||
b"unsub_remote" => Pubsub::unsub_remote(lua)?,
|
b"unsub_remote" => Pubsub::unsub_remote(lua)?,
|
||||||
_ => return Ok(Value::Nil),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)?;
|
.into_lua(lua)
|
||||||
|
})
|
||||||
ts.raw_set(key, value.clone())?;
|
|
||||||
Ok(value)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let ps = lua.create_table_with_capacity(0, 10)?;
|
|
||||||
ps.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
|
|
||||||
|
|
||||||
Ok(ps)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
use mlua::{IntoLua, Lua, MetaMethod, Table, Value};
|
use mlua::{IntoLua, Lua, Value};
|
||||||
|
|
||||||
|
use crate::Composer;
|
||||||
|
|
||||||
pub(super) struct Utils;
|
pub(super) struct Utils;
|
||||||
|
|
||||||
pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Table> {
|
pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Value> {
|
||||||
let index = lua.create_function(move |lua, (ts, key): (Table, mlua::String)| {
|
Composer::make(lua, 40, move |lua, key| {
|
||||||
let value = match key.as_bytes().as_ref() {
|
match key {
|
||||||
// App
|
// App
|
||||||
b"hide" => Utils::hide(lua)?,
|
b"hide" => Utils::hide(lua)?,
|
||||||
|
|
||||||
|
|
@ -80,14 +82,6 @@ pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Table> {
|
||||||
|
|
||||||
_ => return Ok(Value::Nil),
|
_ => return Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
.into_lua(lua)?;
|
.into_lua(lua)
|
||||||
|
})
|
||||||
ts.raw_set(key, value.clone())?;
|
|
||||||
Ok(value)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let ya = lua.create_table_with_capacity(0, 40)?;
|
|
||||||
ya.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
|
|
||||||
|
|
||||||
Ok(ya)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue