yazi/yazi-plugin/preset/components/current.lua

67 lines
1.3 KiB
Lua
Raw Normal View History

Current = {
_id = "current",
}
function Current:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
_folder = tab.current,
}, { __index = self })
end
function Current:empty()
local line
if self._folder.files.filter then
line = ui.Line("No filter results")
else
2024-08-09 06:38:47 +03:00
line = ui.Line(self._folder.stage.is_loading and "Loading..." or "No items")
end
return {
ui.Paragraph(self._area, { line }):align(ui.Paragraph.CENTER),
}
end
function Current:render()
local files = self._folder.window
if #files == 0 then
return self:empty()
end
local entities, linemodes = {}, {}
for _, f in ipairs(files) do
linemodes[#linemodes + 1] = Linemode:new(f):render()
local entity = Entity:new(f)
entities[#entities + 1] = ui.ListItem(entity:render()):style(entity:style())
end
return {
ui.List(self._area, entities),
ui.Paragraph(self._area, linemodes):align(ui.Paragraph.RIGHT),
}
end
2024-06-03 09:31:55 +03:00
-- Mouse events
2024-06-03 09:31:55 +03:00
function Current:click(event, up)
if up or event.is_middle then
2024-06-03 09:31:55 +03:00
return
end
local f = self._folder
local y = event.y - self._area.y + 1
if y > #f.window or not f.hovered then
return
end
ya.manager_emit("arrow", { y + f.offset - f.hovered.idx })
if event.is_right then
2024-07-01 18:58:03 +03:00
ya.manager_emit("open", {})
2024-06-03 09:31:55 +03:00
end
end
function Current:scroll(event, step) ya.manager_emit("arrow", { step }) end
function Current:touch(event, step) end