init: fmt

This commit is contained in:
notohh 2024-01-22 08:34:29 -05:00
parent 6efe8282ce
commit 635457948c
Signed by: notohh
GPG key ID: BD47506D475EE86D

View file

@ -1,45 +1,37 @@
function Manager:render(area)
self.area = area
local chunks = ui.Layout()
:direction(ui.Layout.HORIZONTAL)
:constraints({
local chunks = ui.Layout():direction(ui.Layout.HORIZONTAL):constraints({
ui.Constraint.Ratio(MANAGER.ratio.parent, MANAGER.ratio.all),
ui.Constraint.Ratio(MANAGER.ratio.current, MANAGER.ratio.all),
ui.Constraint.Ratio(MANAGER.ratio.preview, MANAGER.ratio.all),
})
:split(area)
ui.Constraint.Ratio(MANAGER.ratio.preview, MANAGER.ratio.all)
}):split(area)
local bar = function(c, x, y)
return ui.Bar(
ui.Rect { x = math.max(0, x), y = math.max(0, y), w = math.min(1, area.w), h = math.min(1, area.h) },
ui.Bar.TOP
):symbol(c)
return ui.Bar(ui.Rect {
x = math.max(0, x),
y = math.max(0, y),
w = math.min(1, area.w),
h = math.min(1, area.h)
}, ui.Bar.TOP):symbol(c)
end
return ya.flat {
-- Borders
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].bottom - 1),
bar("", chunks[2].right, chunks[2].y),
bar("", chunks[2].right, chunks[1].bottom - 1),
-- Parent
Parent:render(chunks[1]:padding(ui.Padding.xy(1))),
-- Current
Current:render(chunks[2]:padding(ui.Padding.y(1))),
-- Preview
Preview:render(chunks[3]:padding(ui.Padding.xy(1))),
bar("", chunks[2].right, chunks[1].bottom - 1), -- Parent
Parent:render(chunks[1]:padding(ui.Padding.xy(1))), -- Current
Current:render(chunks[2]:padding(ui.Padding.y(1))), -- Preview
Preview:render(chunks[3]:padding(ui.Padding.xy(1)))
}
end
Status = {
area = ui.Rect.default,
}
Status = {area = ui.Rect.default}
function Status.style()
if cx.active.mode.is_select then
@ -53,52 +45,41 @@ end
function Status:mode()
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()
return ui.Line {
ui.Span(THEME.status.separator_open):fg(style.bg),
ui.Span(" " .. mode .. " "):style(style),
ui.Span(" " .. mode .. " "):style(style)
}
end
function Status:size()
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()
return ui.Line {
ui.Span(" " .. ya.readable_size(h:size() or h.cha.length) .. " "):fg(style.bg):bg(THEME.status.separator_style.bg),
ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg),
ui.Span(" " .. ya.readable_size(h:size() or h.cha.length) .. " "):fg(
style.bg):bg(THEME.status.separator_style.bg),
ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg)
}
end
function Status:name()
local h = cx.active.current.hovered
if h == nil then
return ui.Span("")
end
if h == nil then return ui.Span("") end
local linked = ""
if h.link_to ~= nil then
linked = " -> " .. tostring(h.link_to)
end
if h.link_to ~= nil then linked = " -> " .. tostring(h.link_to) end
return ui.Span(" " .. h.name .. linked)
end
function Status:permissions()
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()
if perm == nil then
return ui.Line {}
end
if perm == nil then return ui.Line {} end
local spans = {}
for i = 1, #perm do
@ -134,8 +115,9 @@ function Status:percentage()
local style = self.style()
return ui.Line {
ui.Span(" " .. THEME.status.separator_open):fg(THEME.status.separator_style.fg),
ui.Span(percent):fg(style.bg):bg(THEME.status.separator_style.bg),
ui.Span(" " .. THEME.status.separator_open):fg(THEME.status
.separator_style.fg),
ui.Span(percent):fg(style.bg):bg(THEME.status.separator_style.bg)
}
end
@ -146,32 +128,32 @@ function Status:position()
local style = self.style()
return ui.Line {
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
function Status:render(area)
self.area = area
local left = ui.Line { self:mode(), self:size(), self:name() }
local right = ui.Line { self:owner(), self:permissions(), self:percentage(), self:position() }
local left = ui.Line {self:mode(), self:size(), self:name()}
local right = ui.Line {
self:owner(), self:permissions(), self:percentage(), self:position()
}
return {
ui.Paragraph(area, { left }),
ui.Paragraph(area, { right }):align(ui.Paragraph.RIGHT),
table.unpack(Progress:render(area, right:width())),
ui.Paragraph(area, {left}),
ui.Paragraph(area, {right}):align(ui.Paragraph.RIGHT),
table.unpack(Progress:render(area, right:width()))
}
end
function Status:owner()
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 {
ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"),
ui.Span(":"),
ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"),
ui.Span(" "),
ui.Span(" ")
}
end