treewide: refactor w/ deadnix && statix applied #27
1 changed files with 140 additions and 116 deletions
|
@ -1,159 +1,183 @@
|
||||||
function Manager:render(area)
|
function Manager:render(area)
|
||||||
self.area = area
|
self.area = area
|
||||||
|
|
||||||
local chunks = ui.Layout():direction(ui.Layout.HORIZONTAL):constraints({
|
local chunks = ui.Layout()
|
||||||
ui.Constraint.Ratio(MANAGER.ratio.parent, MANAGER.ratio.all),
|
:direction(ui.Layout.HORIZONTAL)
|
||||||
ui.Constraint.Ratio(MANAGER.ratio.current, MANAGER.ratio.all),
|
:constraints({
|
||||||
ui.Constraint.Ratio(MANAGER.ratio.preview, MANAGER.ratio.all)
|
ui.Constraint.Ratio(MANAGER.ratio.parent, MANAGER.ratio.all),
|
||||||
}):split(area)
|
ui.Constraint.Ratio(MANAGER.ratio.current, MANAGER.ratio.all),
|
||||||
|
ui.Constraint.Ratio(MANAGER.ratio.preview, MANAGER.ratio.all),
|
||||||
|
})
|
||||||
|
:split(area)
|
||||||
|
|
||||||
local bar = function(c, x, y)
|
local bar = function(c, x, y)
|
||||||
return ui.Bar(ui.Rect {
|
return ui.Bar(
|
||||||
x = math.max(0, x),
|
ui.Rect({
|
||||||
y = math.max(0, y),
|
x = math.max(0, x),
|
||||||
w = math.min(1, area.w),
|
y = math.max(0, y),
|
||||||
h = math.min(1, area.h)
|
w = math.min(1, area.w),
|
||||||
}, ui.Bar.TOP):symbol(c)
|
h = math.min(1, area.h),
|
||||||
end
|
}),
|
||||||
|
ui.Bar.TOP
|
||||||
|
):symbol(c)
|
||||||
|
end
|
||||||
|
|
||||||
return ya.flat {
|
return ya.flat({
|
||||||
-- Borders
|
-- Borders
|
||||||
ui.Border(area, ui.Border.ALL):type(ui.Border.ROUNDED),
|
ui.Border(area, ui.Border.ALL):type(ui.Border.ROUNDED),
|
||||||
ui.Bar(chunks[1], ui.Bar.RIGHT), ui.Bar(chunks[3], ui.Bar.LEFT),
|
ui.Bar(chunks[1], ui.Bar.RIGHT),
|
||||||
|
ui.Bar(chunks[3], ui.Bar.LEFT),
|
||||||
|
|
||||||
bar("┬", chunks[1].right - 1, chunks[1].y),
|
bar("┬", chunks[1].right - 1, chunks[1].y),
|
||||||
bar("┴", chunks[1].right - 1, chunks[1].bottom - 1),
|
bar("┴", chunks[1].right - 1, chunks[1].bottom - 1),
|
||||||
bar("┬", chunks[2].right, chunks[2].y),
|
bar("┬", chunks[2].right, chunks[2].y),
|
||||||
bar("┴", chunks[2].right, chunks[1].bottom - 1), -- Parent
|
bar("┴", chunks[2].right, chunks[1].bottom - 1), -- Parent
|
||||||
Parent:render(chunks[1]:padding(ui.Padding.xy(1))), -- Current
|
Parent:render(chunks[1]:padding(ui.Padding.xy(1))), -- Current
|
||||||
Current:render(chunks[2]:padding(ui.Padding.y(1))), -- Preview
|
Current:render(chunks[2]:padding(ui.Padding.y(1))), -- Preview
|
||||||
Preview:render(chunks[3]:padding(ui.Padding.xy(1)))
|
Preview:render(chunks[3]:padding(ui.Padding.xy(1))),
|
||||||
}
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
Status = {area = ui.Rect.default}
|
Status = { area = ui.Rect.default }
|
||||||
|
|
||||||
function Status.style()
|
function Status.style()
|
||||||
if cx.active.mode.is_select then
|
if cx.active.mode.is_select then
|
||||||
return THEME.status.mode_select
|
return THEME.status.mode_select
|
||||||
elseif cx.active.mode.is_unset then
|
elseif cx.active.mode.is_unset then
|
||||||
return THEME.status.mode_unset
|
return THEME.status.mode_unset
|
||||||
else
|
else
|
||||||
return THEME.status.mode_normal
|
return THEME.status.mode_normal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:mode()
|
function Status:mode()
|
||||||
local mode = tostring(cx.active.mode):upper()
|
local mode = tostring(cx.active.mode):upper()
|
||||||
if mode == "UNSET" then mode = "UN-SET" end
|
if mode == "UNSET" then
|
||||||
|
mode = "UN-SET"
|
||||||
|
end
|
||||||
|
|
||||||
local style = self.style()
|
local style = self.style()
|
||||||
return ui.Line {
|
return ui.Line({
|
||||||
ui.Span(THEME.status.separator_open):fg(style.bg),
|
ui.Span(THEME.status.separator_open):fg(style.bg),
|
||||||
ui.Span(" " .. mode .. " "):style(style)
|
ui.Span(" " .. mode .. " "):style(style),
|
||||||
}
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:size()
|
function Status:size()
|
||||||
local h = cx.active.current.hovered
|
local h = cx.active.current.hovered
|
||||||
if h == nil then return ui.Line {} end
|
if h == nil then
|
||||||
|
return ui.Line({})
|
||||||
|
end
|
||||||
|
|
||||||
local style = self.style()
|
local style = self.style()
|
||||||
return ui.Line {
|
return ui.Line({
|
||||||
ui.Span(" " .. ya.readable_size(h:size() or h.cha.length) .. " "):fg(
|
ui.Span(" " .. ya.readable_size(h:size() or h.cha.length) .. " ")
|
||||||
style.bg):bg(THEME.status.separator_style.bg),
|
:fg(style.bg)
|
||||||
ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg)
|
:bg(THEME.status.separator_style.bg),
|
||||||
}
|
ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg),
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:name()
|
function Status:name()
|
||||||
local h = cx.active.current.hovered
|
local h = cx.active.current.hovered
|
||||||
if h == nil then return ui.Span("") end
|
if h == nil then
|
||||||
local linked = ""
|
return ui.Span("")
|
||||||
if h.link_to ~= nil then linked = " -> " .. tostring(h.link_to) end
|
end
|
||||||
return ui.Span(" " .. h.name .. linked)
|
local linked = ""
|
||||||
|
if h.link_to ~= nil then
|
||||||
|
linked = " -> " .. tostring(h.link_to)
|
||||||
|
end
|
||||||
|
return ui.Span(" " .. h.name .. linked)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:permissions()
|
function Status:permissions()
|
||||||
local h = cx.active.current.hovered
|
local h = cx.active.current.hovered
|
||||||
if h == nil then return ui.Line {} end
|
if h == nil then
|
||||||
|
return ui.Line({})
|
||||||
|
end
|
||||||
|
|
||||||
local perm = h.cha:permissions()
|
local perm = h.cha:permissions()
|
||||||
if perm == nil then return ui.Line {} end
|
if perm == nil then
|
||||||
|
return ui.Line({})
|
||||||
|
end
|
||||||
|
|
||||||
local spans = {}
|
local spans = {}
|
||||||
for i = 1, #perm do
|
for i = 1, #perm do
|
||||||
local c = perm:sub(i, i)
|
local c = perm:sub(i, i)
|
||||||
local style = THEME.status.permissions_t
|
local style = THEME.status.permissions_t
|
||||||
if c == "-" then
|
if c == "-" then
|
||||||
style = THEME.status.permissions_s
|
style = THEME.status.permissions_s
|
||||||
elseif c == "r" then
|
elseif c == "r" then
|
||||||
style = THEME.status.permissions_r
|
style = THEME.status.permissions_r
|
||||||
elseif c == "w" then
|
elseif c == "w" then
|
||||||
style = THEME.status.permissions_w
|
style = THEME.status.permissions_w
|
||||||
elseif c == "x" or c == "s" or c == "S" or c == "t" or c == "T" then
|
elseif c == "x" or c == "s" or c == "S" or c == "t" or c == "T" then
|
||||||
style = THEME.status.permissions_x
|
style = THEME.status.permissions_x
|
||||||
end
|
end
|
||||||
spans[i] = ui.Span(c):style(style)
|
spans[i] = ui.Span(c):style(style)
|
||||||
end
|
end
|
||||||
return ui.Line(spans)
|
return ui.Line(spans)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:percentage()
|
function Status:percentage()
|
||||||
local percent = 0
|
local percent = 0
|
||||||
local cursor = cx.active.current.cursor
|
local cursor = cx.active.current.cursor
|
||||||
local length = #cx.active.current.files
|
local length = #cx.active.current.files
|
||||||
if cursor ~= 0 and length ~= 0 then
|
if cursor ~= 0 and length ~= 0 then
|
||||||
percent = math.floor((cursor + 1) * 100 / length)
|
percent = math.floor((cursor + 1) * 100 / length)
|
||||||
end
|
end
|
||||||
|
|
||||||
if percent == 0 then
|
if percent == 0 then
|
||||||
percent = " Top "
|
percent = " Top "
|
||||||
else
|
else
|
||||||
percent = string.format(" %3d%% ", percent)
|
percent = string.format(" %3d%% ", percent)
|
||||||
end
|
end
|
||||||
|
|
||||||
local style = self.style()
|
local style = self.style()
|
||||||
return ui.Line {
|
return ui.Line({
|
||||||
ui.Span(" " .. THEME.status.separator_open):fg(THEME.status
|
ui.Span(" " .. THEME.status.separator_open):fg(THEME.status.separator_style.fg),
|
||||||
.separator_style.fg),
|
ui.Span(percent):fg(style.bg):bg(THEME.status.separator_style.bg),
|
||||||
ui.Span(percent):fg(style.bg):bg(THEME.status.separator_style.bg)
|
})
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:position()
|
function Status:position()
|
||||||
local cursor = cx.active.current.cursor
|
local cursor = cx.active.current.cursor
|
||||||
local length = #cx.active.current.files
|
local length = #cx.active.current.files
|
||||||
|
|
||||||
local style = self.style()
|
local style = self.style()
|
||||||
return ui.Line {
|
return ui.Line({
|
||||||
ui.Span(string.format(" %2d/%-2d ", cursor + 1, length)):style(style),
|
ui.Span(string.format(" %2d/%-2d ", cursor + 1, length)):style(style),
|
||||||
ui.Span(THEME.status.separator_close):fg(style.bg)
|
ui.Span(THEME.status.separator_close):fg(style.bg),
|
||||||
}
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:render(area)
|
function Status:render(area)
|
||||||
self.area = area
|
self.area = area
|
||||||
|
|
||||||
local left = ui.Line {self:mode(), self:size(), self:name()}
|
local left = ui.Line({ self:mode(), self:size(), self:name() })
|
||||||
local right = ui.Line {
|
local right = ui.Line({
|
||||||
self:owner(), self:permissions(), self:percentage(), self:position()
|
self:owner(),
|
||||||
}
|
self:permissions(),
|
||||||
return {
|
self:percentage(),
|
||||||
ui.Paragraph(area, {left}),
|
self:position(),
|
||||||
ui.Paragraph(area, {right}):align(ui.Paragraph.RIGHT),
|
})
|
||||||
table.unpack(Progress:render(area, right:width()))
|
return {
|
||||||
}
|
ui.Paragraph(area, { left }),
|
||||||
|
ui.Paragraph(area, { right }):align(ui.Paragraph.RIGHT),
|
||||||
|
table.unpack(Progress:render(area, right:width())),
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Status:owner()
|
function Status:owner()
|
||||||
local h = cx.active.current.hovered
|
local h = cx.active.current.hovered
|
||||||
if h == nil or ya.target_family() ~= "unix" then return ui.Line {} end
|
if h == nil or ya.target_family() ~= "unix" then
|
||||||
|
return ui.Line({})
|
||||||
|
end
|
||||||
|
|
||||||
return ui.Line {
|
return ui.Line({
|
||||||
ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"),
|
ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"),
|
||||||
ui.Span(":"),
|
ui.Span(":"),
|
||||||
ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"),
|
ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"),
|
||||||
ui.Span(" ")
|
ui.Span(" "),
|
||||||
}
|
})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue