yazi/yazi-plugin/preset/components/current.lua
2025-05-14 02:03:54 +08:00

68 lines
1.4 KiB
Lua

Current = {
_id = "current",
}
function Current:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
_folder = tab.current,
}, { __index = self })
end
function Current:empty()
local s
if self._folder.files.filter then
s = "No filter results"
else
local done, err = self._folder.stage()
s = not done and "Loading..." or not err and "No items" or string.format("Error: %s", err)
end
return {
ui.Line(s):area(self._area):align(ui.Line.CENTER),
}
end
function Current:reflow() return { self } end
function Current:redraw()
local files = self._folder.window
if #files == 0 then
return self:empty()
end
local left, right = {}, {}
for _, f in ipairs(files) do
left[#left + 1] = Entity:new(f):redraw()
right[#right + 1] = Linemode:new(f):redraw()
left[#left]:truncate { max = math.max(0, self._area.w - right[#right]:width()) }
end
return {
ui.List(left):area(self._area),
ui.Text(right):area(self._area):align(ui.Text.RIGHT),
}
end
-- Mouse events
function Current:click(event, up)
if up or event.is_middle then
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.emit("arrow", { y + f.offset - f.hovered.idx })
if event.is_right then
ya.emit("open", {})
end
end
function Current:scroll(event, step) ya.emit("arrow", { step }) end
function Current:touch(event, step) end