2024-07-12 13:32:01 +03:00
|
|
|
Linemode = {
|
|
|
|
_inc = 1000,
|
2024-07-15 09:59:24 +03:00
|
|
|
_children = {
|
|
|
|
{ "solo", id = 1, order = 1000 },
|
|
|
|
},
|
2024-07-12 13:32:01 +03:00
|
|
|
}
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end
|
|
|
|
|
|
|
|
function Linemode:solo()
|
2024-07-12 13:32:01 +03:00
|
|
|
local mode = cx.active.conf.linemode
|
|
|
|
if mode == "none" or mode == "solo" then
|
|
|
|
return ui.Line("")
|
|
|
|
end
|
|
|
|
|
|
|
|
if not self[mode] then
|
|
|
|
return ui.Line(" " .. mode .. " ")
|
|
|
|
end
|
|
|
|
|
|
|
|
return ui.Line {
|
|
|
|
ui.Span(" "),
|
2024-07-15 09:59:24 +03:00
|
|
|
self[mode](self),
|
2024-07-12 13:32:01 +03:00
|
|
|
ui.Span(" "),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
function Linemode:size()
|
|
|
|
local size = self._file:size()
|
2024-07-12 13:32:01 +03:00
|
|
|
return ui.Line(size and ya.readable_size(size) or "")
|
|
|
|
end
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
function Linemode:ctime()
|
|
|
|
local time = (self._file.cha.created or 0) // 1
|
2024-07-14 10:02:07 +03:00
|
|
|
if time == 0 then
|
|
|
|
return ui.Line("")
|
|
|
|
elseif os.date("%Y", time) == os.date("%Y") then
|
|
|
|
return ui.Line(os.date("%m/%d %H:%M", time))
|
|
|
|
else
|
|
|
|
return ui.Line(os.date("%m/%d %Y", time))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
function Linemode:mtime()
|
|
|
|
local time = (self._file.cha.modified or 0) // 1
|
2024-07-14 10:02:07 +03:00
|
|
|
if time == 0 then
|
|
|
|
return ui.Line("")
|
|
|
|
elseif os.date("%Y", time) == os.date("%Y") then
|
|
|
|
return ui.Line(os.date("%m/%d %H:%M", time))
|
|
|
|
else
|
|
|
|
return ui.Line(os.date("%m/%d %Y", time))
|
|
|
|
end
|
2024-07-12 13:32:01 +03:00
|
|
|
end
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
function Linemode:permissions() return ui.Line(self._file.cha:permissions() or "") end
|
2024-07-12 13:32:01 +03:00
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
function Linemode:owner()
|
|
|
|
local user = self._file.cha.uid and ya.user_name(self._file.cha.uid) or self._file.cha.uid
|
|
|
|
local group = self._file.cha.gid and ya.group_name(self._file.cha.gid) or self._file.cha.gid
|
2024-07-14 09:42:42 +03:00
|
|
|
return ui.Line(string.format("%s:%s", user or "-", group or "-"))
|
2024-07-12 13:32:01 +03:00
|
|
|
end
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
function Linemode:render()
|
2024-07-12 13:32:01 +03:00
|
|
|
local lines = {}
|
2024-07-15 09:59:24 +03:00
|
|
|
for _, c in ipairs(self._children) do
|
|
|
|
lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self)
|
2024-07-12 13:32:01 +03:00
|
|
|
end
|
2024-07-15 09:59:24 +03:00
|
|
|
return ui.Line(lines)
|
2024-07-12 13:32:01 +03:00
|
|
|
end
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
-- Children
|
2024-07-12 13:32:01 +03:00
|
|
|
function Linemode:children_add(fn, order)
|
|
|
|
self._inc = self._inc + 1
|
|
|
|
self._children[#self._children + 1] = { fn, id = self._inc, order = order }
|
|
|
|
table.sort(self._children, function(a, b) return a.order < b.order end)
|
|
|
|
return self._inc
|
|
|
|
end
|
|
|
|
|
|
|
|
function Linemode:children_remove(id)
|
|
|
|
for i, child in ipairs(self._children) do
|
|
|
|
if child.id == id then
|
|
|
|
table.remove(self._children, i)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|