2023-12-26 14:48:33 +03:00
|
|
|
Status = {
|
|
|
|
area = ui.Rect.default,
|
|
|
|
}
|
2023-10-11 19:09:10 +03:00
|
|
|
|
|
|
|
function Status.style()
|
|
|
|
if cx.active.mode.is_select then
|
|
|
|
return THEME.status.mode_select
|
|
|
|
elseif cx.active.mode.is_unset then
|
|
|
|
return THEME.status.mode_unset
|
|
|
|
else
|
|
|
|
return THEME.status.mode_normal
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Status:mode()
|
|
|
|
local mode = tostring(cx.active.mode):upper()
|
|
|
|
if mode == "UNSET" then
|
|
|
|
mode = "UN-SET"
|
|
|
|
end
|
|
|
|
|
|
|
|
local style = self.style()
|
|
|
|
return ui.Line {
|
2023-10-13 13:49:24 +03:00
|
|
|
ui.Span(THEME.status.separator_open):fg(style.bg),
|
2023-10-11 19:09:10 +03:00
|
|
|
ui.Span(" " .. mode .. " "):style(style),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Status:size()
|
|
|
|
local h = cx.active.current.hovered
|
2024-02-15 15:20:28 +03:00
|
|
|
if not h then
|
2024-01-02 20:32:29 +03:00
|
|
|
return ui.Line {}
|
2023-10-11 19:09:10 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local style = self.style()
|
|
|
|
return ui.Line {
|
2023-12-26 14:48:33 +03:00
|
|
|
ui.Span(" " .. ya.readable_size(h:size() or h.cha.length) .. " "):fg(style.bg):bg(THEME.status.separator_style.bg),
|
2023-10-13 13:49:24 +03:00
|
|
|
ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg),
|
2023-10-11 19:09:10 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Status:name()
|
|
|
|
local h = cx.active.current.hovered
|
2024-02-15 15:20:28 +03:00
|
|
|
if not h then
|
2023-10-11 19:09:10 +03:00
|
|
|
return ui.Span("")
|
|
|
|
end
|
|
|
|
|
|
|
|
return ui.Span(" " .. h.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Status:permissions()
|
|
|
|
local h = cx.active.current.hovered
|
2024-02-15 15:20:28 +03:00
|
|
|
if not h then
|
2024-01-02 20:32:29 +03:00
|
|
|
return ui.Line {}
|
2023-10-21 00:42:13 +03:00
|
|
|
end
|
|
|
|
|
2023-12-26 14:48:33 +03:00
|
|
|
local perm = h.cha:permissions()
|
2024-02-15 15:20:28 +03:00
|
|
|
if not perm then
|
2024-01-02 20:32:29 +03:00
|
|
|
return ui.Line {}
|
2023-10-11 19:09:10 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local spans = {}
|
2023-10-21 00:42:13 +03:00
|
|
|
for i = 1, #perm do
|
|
|
|
local c = perm:sub(i, i)
|
2023-10-11 19:09:10 +03:00
|
|
|
local style = THEME.status.permissions_t
|
|
|
|
if c == "-" then
|
|
|
|
style = THEME.status.permissions_s
|
|
|
|
elseif c == "r" then
|
|
|
|
style = THEME.status.permissions_r
|
|
|
|
elseif c == "w" then
|
|
|
|
style = THEME.status.permissions_w
|
|
|
|
elseif c == "x" or c == "s" or c == "S" or c == "t" or c == "T" then
|
|
|
|
style = THEME.status.permissions_x
|
|
|
|
end
|
|
|
|
spans[i] = ui.Span(c):style(style)
|
|
|
|
end
|
|
|
|
return ui.Line(spans)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Status:percentage()
|
|
|
|
local percent = 0
|
|
|
|
local cursor = cx.active.current.cursor
|
|
|
|
local length = #cx.active.current.files
|
|
|
|
if cursor ~= 0 and length ~= 0 then
|
|
|
|
percent = math.floor((cursor + 1) * 100 / length)
|
|
|
|
end
|
|
|
|
|
|
|
|
if percent == 0 then
|
|
|
|
percent = " Top "
|
|
|
|
else
|
|
|
|
percent = string.format(" %3d%% ", percent)
|
|
|
|
end
|
|
|
|
|
|
|
|
local style = self.style()
|
|
|
|
return ui.Line {
|
2023-10-13 13:49:24 +03:00
|
|
|
ui.Span(" " .. THEME.status.separator_open):fg(THEME.status.separator_style.fg),
|
|
|
|
ui.Span(percent):fg(style.bg):bg(THEME.status.separator_style.bg),
|
2023-10-11 19:09:10 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Status:position()
|
|
|
|
local cursor = cx.active.current.cursor
|
|
|
|
local length = #cx.active.current.files
|
|
|
|
|
|
|
|
local style = self.style()
|
|
|
|
return ui.Line {
|
|
|
|
ui.Span(string.format(" %2d/%-2d ", cursor + 1, length)):style(style),
|
2023-10-13 13:49:24 +03:00
|
|
|
ui.Span(THEME.status.separator_close):fg(style.bg),
|
2023-10-11 19:09:10 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Status:render(area)
|
2023-12-26 14:48:33 +03:00
|
|
|
self.area = area
|
|
|
|
|
2023-10-11 19:09:10 +03:00
|
|
|
local left = ui.Line { self:mode(), self:size(), self:name() }
|
|
|
|
local right = ui.Line { self:permissions(), self:percentage(), self:position() }
|
|
|
|
return {
|
2023-10-21 00:42:13 +03:00
|
|
|
ui.Paragraph(area, { left }),
|
2023-12-30 18:41:41 +03:00
|
|
|
ui.Paragraph(area, { right }):align(ui.Paragraph.RIGHT),
|
2024-01-15 13:30:50 +03:00
|
|
|
table.unpack(Progress:render(area, right:width())),
|
2023-10-11 19:09:10 +03:00
|
|
|
}
|
|
|
|
end
|