Compare commits

...

2 Commits

Author SHA1 Message Date
三咲雅 · Misaki Masa
f4be44ea53
Merge c98fc3f907 into 11547eefe0 2024-07-07 01:36:25 +00:00
sxyazi
c98fc3f907
.. 2024-07-07 09:36:12 +08:00
15 changed files with 155 additions and 94 deletions

View File

@ -773,9 +773,9 @@ conds = [
{ if = "sticky", text = "" },
# Fallback
{ if = "dir", text = "" },
{ if = "exec", text = "" },
{ if = "!dir", text = "" },
{ if = "dir", text = "󰉋" },
{ if = "exec", text = "" },
{ if = "!dir", text = "󰈔" },
]
# : }}}

View File

@ -54,13 +54,15 @@ impl Lives {
let ret = f(scope)?;
LAYOUT.store(Arc::new(yazi_config::Layout {
header: *globals.raw_get::<_, Table>("Header")?.raw_get::<_, RectRef>("_area")?,
parent: *globals.raw_get::<_, Table>("Parent")?.raw_get::<_, RectRef>("_area")?,
current: *globals.raw_get::<_, Table>("Current")?.raw_get::<_, RectRef>("_area")?,
preview: *globals.raw_get::<_, Table>("Preview")?.raw_get::<_, RectRef>("_area")?,
status: *globals.raw_get::<_, Table>("Status")?.raw_get::<_, RectRef>("_area")?,
}));
// TODO
// LAYOUT.store(Arc::new(yazi_config::Layout {
// header: *globals.raw_get::<_, Table>("Header")?.raw_get::<_,
// RectRef>("_area")?, parent: *globals.raw_get::<_,
// Table>("Parent")?.raw_get::<_, RectRef>("_area")?, current: *globals.
// raw_get::<_, Table>("Current")?.raw_get::<_, RectRef>("_area")?, preview:
// *globals.raw_get::<_, Table>("Preview")?.raw_get::<_, RectRef>("_area")?,
// status: *globals.raw_get::<_, Table>("Status")?.raw_get::<_,
// RectRef>("_area")?, }));
Ok(ret)
});

View File

@ -19,12 +19,13 @@ impl<'a> Widget for Root<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let mut f = || {
let area = yazi_plugin::elements::Rect::cast(&LUA, area)?;
let root: Table = LUA.globals().raw_get("Root")?;
render_widgets(root.call_method("render", area)?, buf);
let root = LUA.globals().get::<_, Table>("Root")?.call_method::<_, Table>("new", area)?;
render_widgets(root.call_method("render", ())?, buf);
Ok::<_, mlua::Error>(())
};
if let Err(e) = f() {
error!("Lua method `Root:render()` call failed:\n{e}");
error!("Failed to render the `Root` component:\n{e}");
}
components::Preview::new(self.cx).render(area, buf);

View File

@ -1,4 +1,6 @@
Current = {}
Current = {
_name = "Current",
}
function Current:new(area, tab)
return setmetatable({
@ -27,24 +29,18 @@ function Current:render()
return self:empty()
end
local items, markers = {}, {}
for i, f in ipairs(files) do
local items = {}
for _, f in ipairs(files) do
items[#items + 1] = ui.ListItem(File:children_render(f)):style(File:style(f))
-- Yanked/marked/selected files
local marker = File:marker(f)
if marker ~= 0 then
markers[#markers + 1] = { i, marker }
end
end
return ya.flat {
return {
ui.List(self._area, items),
Folder:linemode(self._area, files),
Folder:markers(self._area, markers),
}
end
-- Mouse events
function Current:click(event, up)
if up or event.is_middle then
return

View File

@ -1,4 +1,6 @@
Header = {}
Header = {
_name = "Header",
}
function Header:new(area, tab)
return setmetatable({

View File

@ -0,0 +1,23 @@
Marker = {
_name = "Marker",
}
function Marker:new(area, folder)
return setmetatable({
_area = area,
_folder = folder,
}, { __index = self })
end
function Marker:render()
return {
ui.Bar(self._area, ui.Bar.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
}
end
-- Mouse events
function Marker:click(event, up) end
function Marker:scroll(event, step) end
function Marker:touch(event, step) end

View File

@ -1,4 +1,6 @@
Parent = {}
Parent = {
_name = "Parent",
}
function Parent:new(area, tab)
return setmetatable({
@ -13,23 +15,17 @@ function Parent:render()
return {}
end
local items, markers = {}, {}
for i, f in ipairs(self._folder.window) do
local items = {}
for _, f in ipairs(self._folder.window) do
items[#items + 1] = ui.ListItem(File:children_render(f)):style(File:style(f))
-- Yanked/marked/selected files
local marker = File:marker(f)
if marker ~= 0 then
markers[#markers + 1] = { i, marker }
end
end
return ya.flat {
return {
ui.List(self._area, items),
Folder:markers(self._area, markers),
}
end
-- Mouse events
function Parent:click(event, up)
if up or not event.is_left then
return

View File

@ -1,4 +1,6 @@
Preview = {}
Preview = {
_name = "Preview",
}
function Preview:new(area, tab)
return setmetatable({
@ -10,6 +12,7 @@ end
function Preview:render() return {} end
-- Mouse events
function Preview:click(event, up)
if up or not event.is_left then
return

View File

@ -0,0 +1,26 @@
Rail = {
_name = "Rail",
}
function Rail:new(chunks, tab)
return setmetatable({
_chunks = chunks,
_tab = tab,
}, { __index = self }):build()
end
function Rail:build()
self._children = {
Marker:new(self._chunks[1], self._tab.parent),
Marker:new(self._chunks[2], self._tab.current),
}
return self
end
function Rail:render()
local children = {}
for _, child in ipairs(self._children) do
children = ya.list_merge(children, ya.render_with(child))
end
return children
end

View File

@ -1,8 +1,15 @@
Root = {
_name = "Root",
_drag_start = ui.Rect.default,
}
function Root:layout(area)
function Root:new(area)
return setmetatable({
_area = area,
}, { __index = self }):build()
end
function Root:layout()
return ui.Layout()
:direction(ui.Layout.VERTICAL)
:constraints({
@ -10,19 +17,29 @@ function Root:layout(area)
ui.Constraint.Fill(1),
ui.Constraint.Length(1),
})
:split(area)
:split(self._area)
end
function Root:render(area)
local c = self:layout(area)
function Root:build()
local chunks = self:layout()
return ya.flat {
ya.eval("Header:render", Header.render, Header:new(c[1], cx.active)) or {},
ya.eval("Tab:render", Tab.render, Tab:new(c[2], cx.active)) or {},
ya.eval("Status:render", Status.render, Status:new(c[3], cx.active)) or {},
self._children = {
Header:new(chunks[1], cx.active),
Tab:new(chunks[2], cx.active),
Status:new(chunks[3], cx.active),
}
return self
end
function Root:render()
local children = {}
for _, child in ipairs(self._children) do
children = ya.list_merge(children, ya.render_with(child))
end
return children
end
-- Mouse events
function Root:move(event) end
function Root:drag(event) end

View File

@ -2,6 +2,7 @@ Status = {
LEFT = 0,
RIGHT = 1,
_name = "Status",
_inc = 1000,
}

View File

@ -1,11 +1,37 @@
Manager = {} -- TODO: remove this after 0.3.0 release
Tab = {}
Tab = {
_name = "Tab",
}
function Tab:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
}, { __index = self })
}, { __index = self }):build()
end
function Tab:build()
local chunks = self:layout()
self._children = {
-- Rail
Rail:new(chunks, self._tab):build(),
-- Parent
Parent:new(chunks[1]:padding(ui.Padding.x(1)), self._tab),
-- Current
Current:new(chunks[2], self._tab),
-- Preview
Preview:new(chunks[3]:padding(ui.Padding.x(1)), self._tab),
}
return self
end
function Tab:render()
local children = {}
for _, child in ipairs(self._children) do
children = ya.list_merge(children, ya.render_with(child))
end
return children
end
function Tab:layout()
@ -18,20 +44,3 @@ function Tab:layout()
})
:split(self._area)
end
function Tab:render()
local chunks = self:layout()
return ya.flat {
-- Borders
ui.Bar(chunks[1], ui.Bar.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
ui.Bar(chunks[3], ui.Bar.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
-- Parent
Parent:new(chunks[1]:padding(ui.Padding.x(1)), self._tab):render(),
-- Current
Current:new(chunks[2], self._tab):render(),
-- Preview
Preview:new(chunks[3]:padding(ui.Padding.x(1)), self._tab):render(),
}
end

View File

@ -18,24 +18,14 @@ function M:peek()
})
end
local items, markers = {}, {}
for i, f in ipairs(folder.window) do
local items = {}
for _, f in ipairs(folder.window) do
items[#items + 1] = ui.ListItem(File:children_render(f)):style(File:style(f))
-- Yanked/marked/selected files
local marker = File:marker(f)
if marker ~= 0 then
markers[#markers + 1] = { i, marker }
end
end
ya.preview_widgets(
self,
ya.flat {
ui.List(self.area, items),
Folder:markers(self.area, markers),
}
)
ya.preview_widgets(self, {
ui.List(self.area, items),
})
end
function M:seek(units)

View File

@ -14,28 +14,21 @@ end
function ya.round(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end
function ya.flat(t)
local r, todo = {}, { t }
while #todo > 0 do
for _, v in ipairs(table.remove(todo)) do
if type(v) == "table" then
todo[#todo + 1] = v
else
r[#r + 1] = v
end
end
function ya.list_merge(a, b)
for _, v in ipairs(b) do
a[#a + 1] = v
end
return r
return a
end
function ya.eval(ctx, f, ...)
local ok, res = xpcall(f, debug.traceback, ...)
function ya.render_with(c)
local ok, res = xpcall(c.render, debug.traceback, c)
if ok then
return res
end
ya.raw_err(string.format("Failed to call `%s()`:\n%s", ctx, res))
return nil
ya.raw_err(string.format("Failed to `render()` the `%s` component:\n%s", c._name, res))
return {}
end
function ya.basename(str) return string.gsub(str, "(.*[/\\])(.*)", "%2") end

View File

@ -36,9 +36,11 @@ fn stage_1(lua: &'static Lua) -> Result<()> {
lua.load(include_str!("../preset/components/file.lua")).set_name("file.lua").exec()?;
lua.load(include_str!("../preset/components/folder.lua")).set_name("folder.lua").exec()?;
lua.load(include_str!("../preset/components/header.lua")).set_name("header.lua").exec()?;
lua.load(include_str!("../preset/components/marker.lua")).set_name("marker.lua").exec()?;
lua.load(include_str!("../preset/components/parent.lua")).set_name("parent.lua").exec()?;
lua.load(include_str!("../preset/components/preview.lua")).set_name("preview.lua").exec()?;
lua.load(include_str!("../preset/components/progress.lua")).set_name("progress.lua").exec()?;
lua.load(include_str!("../preset/components/rail.lua")).set_name("rail.lua").exec()?;
lua.load(include_str!("../preset/components/root.lua")).set_name("root.lua").exec()?;
lua.load(include_str!("../preset/components/status.lua")).set_name("status.lua").exec()?;
lua.load(include_str!("../preset/components/tab.lua")).set_name("tab.lua").exec()?;