2023-12-26 14:48:33 +03:00
|
|
|
Header = {
|
|
|
|
area = ui.Rect.default,
|
|
|
|
}
|
2023-10-11 19:09:10 +03:00
|
|
|
|
2024-03-08 12:54:29 +03:00
|
|
|
function Header:cwd(max)
|
2024-06-22 14:01:51 +03:00
|
|
|
local s = ya.readable_path(tostring(cx.active.current.cwd)) .. self:flags()
|
|
|
|
return ui.Span(ya.truncate(s, { max = max, rtl = true })):style(THEME.manager.cwd)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Header:flags()
|
2023-10-11 19:09:10 +03:00
|
|
|
local cwd = cx.active.current.cwd
|
2024-06-22 14:01:51 +03:00
|
|
|
local filter = cx.active.current.files.filter
|
2023-10-11 19:09:10 +03:00
|
|
|
|
2024-06-22 14:01:51 +03:00
|
|
|
local s = cwd.is_search and string.format(" (search: %s", cwd:frag()) or ""
|
|
|
|
if not filter then
|
|
|
|
return s == "" and s or s .. ")"
|
|
|
|
elseif s == "" then
|
|
|
|
return string.format(" (filter: %s)", tostring(filter))
|
|
|
|
else
|
|
|
|
return string.format("%s, filter: %s)", s, tostring(filter))
|
|
|
|
end
|
2023-10-11 19:09:10 +03:00
|
|
|
end
|
|
|
|
|
2024-02-17 14:03:26 +03:00
|
|
|
function Header:count()
|
2024-02-15 17:54:57 +03:00
|
|
|
local yanked = #cx.yanked
|
|
|
|
|
|
|
|
local count, style
|
|
|
|
if yanked == 0 then
|
|
|
|
count = #cx.active.selected
|
|
|
|
style = THEME.manager.count_selected
|
|
|
|
elseif cx.yanked.is_cut then
|
|
|
|
count = yanked
|
|
|
|
style = THEME.manager.count_cut
|
|
|
|
else
|
|
|
|
count = yanked
|
|
|
|
style = THEME.manager.count_copied
|
|
|
|
end
|
|
|
|
|
|
|
|
if count == 0 then
|
|
|
|
return ui.Line {}
|
|
|
|
end
|
|
|
|
|
|
|
|
return ui.Line {
|
|
|
|
ui.Span(string.format(" %d ", count)):style(style),
|
|
|
|
ui.Span(" "),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-10-11 19:09:10 +03:00
|
|
|
function Header:tabs()
|
2024-02-15 17:54:57 +03:00
|
|
|
local tabs = #cx.tabs
|
|
|
|
if tabs == 1 then
|
|
|
|
return ui.Line {}
|
|
|
|
end
|
|
|
|
|
2023-10-11 19:09:10 +03:00
|
|
|
local spans = {}
|
2024-02-15 17:54:57 +03:00
|
|
|
for i = 1, tabs do
|
2023-10-11 19:09:10 +03:00
|
|
|
local text = i
|
2023-10-13 13:49:24 +03:00
|
|
|
if THEME.manager.tab_width > 2 then
|
2024-03-08 12:54:29 +03:00
|
|
|
text = ya.truncate(text .. " " .. cx.tabs[i]:name(), { max = THEME.manager.tab_width })
|
2023-10-11 19:09:10 +03:00
|
|
|
end
|
2024-02-24 22:41:00 +03:00
|
|
|
if i == cx.tabs.idx then
|
2023-10-13 13:49:24 +03:00
|
|
|
spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_active)
|
2023-10-11 19:09:10 +03:00
|
|
|
else
|
2023-10-13 13:49:24 +03:00
|
|
|
spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_inactive)
|
2023-10-11 19:09:10 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return ui.Line(spans)
|
|
|
|
end
|
|
|
|
|
2024-01-27 19:30:41 +03:00
|
|
|
function Header:render(area)
|
2024-03-08 12:54:29 +03:00
|
|
|
self.area = area
|
2023-10-11 19:09:10 +03:00
|
|
|
|
2024-02-17 14:03:26 +03:00
|
|
|
local right = ui.Line { self:count(), self:tabs() }
|
2024-03-08 12:54:29 +03:00
|
|
|
local left = ui.Line { self:cwd(math.max(0, area.w - right:width())) }
|
2023-10-11 19:09:10 +03:00
|
|
|
return {
|
2024-03-08 12:54:29 +03:00
|
|
|
ui.Paragraph(area, { left }),
|
|
|
|
ui.Paragraph(area, { right }):align(ui.Paragraph.RIGHT),
|
2023-10-11 19:09:10 +03:00
|
|
|
}
|
|
|
|
end
|
2024-06-03 09:31:55 +03:00
|
|
|
|
|
|
|
function Header:click(event, up) end
|
|
|
|
|
|
|
|
function Header:scroll(event, step) end
|
|
|
|
|
|
|
|
function Header:touch(event, step) end
|