yazi: more lua config
All checks were successful
flake check / check (push) Successful in 5m28s
fmt check / check (push) Successful in 55s
All checks were successful
flake check / check (push) Successful in 5m28s
fmt check / check (push) Successful in 55s
This commit is contained in:
parent
fb4e8e7aa3
commit
a63e99c84e
2 changed files with 137 additions and 1 deletions
|
@ -12,7 +12,7 @@
|
|||
enableNushellIntegration = true;
|
||||
settings = {
|
||||
manager = {
|
||||
ratio = [1 3 2];
|
||||
ratio = [1 3 3];
|
||||
sort_by = "natural";
|
||||
sort_reverse = false;
|
||||
sort_dir_first = true;
|
||||
|
|
|
@ -36,3 +36,139 @@ function Manager:render(area)
|
|||
Preview:render(chunks[3]:padding(ui.Padding.xy(1))),
|
||||
}
|
||||
end
|
||||
|
||||
Status = {
|
||||
area = ui.Rect.default,
|
||||
}
|
||||
|
||||
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 {
|
||||
ui.Span(THEME.status.separator_open):fg(style.bg),
|
||||
ui.Span(" " .. mode .. " "):style(style),
|
||||
}
|
||||
end
|
||||
|
||||
function Status:size()
|
||||
local h = cx.active.current.hovered
|
||||
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),
|
||||
}
|
||||
end
|
||||
|
||||
function Status:name()
|
||||
local h = cx.active.current.hovered
|
||||
if h == nil then
|
||||
return ui.Span("")
|
||||
end
|
||||
|
||||
return ui.Span(" " .. h.name)
|
||||
end
|
||||
|
||||
function Status:permissions()
|
||||
local h = cx.active.current.hovered
|
||||
if h == nil then
|
||||
return ui.Line {}
|
||||
end
|
||||
|
||||
local perm = h.cha:permissions()
|
||||
if perm == nil then
|
||||
return ui.Line {}
|
||||
end
|
||||
|
||||
local spans = {}
|
||||
for i = 1, #perm do
|
||||
local c = perm:sub(i, i)
|
||||
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 {
|
||||
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
|
||||
|
||||
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),
|
||||
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() }
|
||||
return {
|
||||
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
|
||||
|
||||
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(" "),
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue