mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add counter for currently selected/cut/copied files to the header
This commit is contained in:
parent
52d91c0e42
commit
2393376204
3 changed files with 54 additions and 3 deletions
|
|
@ -28,6 +28,11 @@ tab_active = { fg = "black", bg = "lightblue" }
|
|||
tab_inactive = { fg = "white", bg = "darkgray" }
|
||||
tab_width = 1
|
||||
|
||||
# Selected counter
|
||||
count_selected = { fg = "white", bg = "green" }
|
||||
count_copied = { fg = "white", bg = "yellow" }
|
||||
count_cut = { fg = "white", bg = "red" }
|
||||
|
||||
# Border
|
||||
border_symbol = "│"
|
||||
border_style = { fg = "gray" }
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ pub struct Manager {
|
|||
#[validate(range(min = 1, message = "Must be greater than 0"))]
|
||||
tab_width: u8,
|
||||
|
||||
// Selected counter
|
||||
count_selected: Style,
|
||||
count_copied: Style,
|
||||
count_cut: Style,
|
||||
|
||||
// Border
|
||||
pub border_symbol: String,
|
||||
pub border_style: Style,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,48 @@ function Header:cwd()
|
|||
else
|
||||
span = ui.Span(string.format("%s (search: %s)", ya.readable_path(tostring(cwd)), cwd:frag()))
|
||||
end
|
||||
return span:style(THEME.manager.cwd)
|
||||
return span:style(THEME.manager.mode_normal)
|
||||
end
|
||||
|
||||
function Header:selected_count()
|
||||
local selected = 0
|
||||
local copied = 0
|
||||
local cut = 0
|
||||
|
||||
for _, f in ipairs(Folder:by_kind(Folder.CURRENT).window) do
|
||||
if f:is_selected() then
|
||||
selected = selected + 1
|
||||
end
|
||||
|
||||
local is_yanked = f:is_yanked()
|
||||
if is_yanked == 1 then
|
||||
copied = copied + 1
|
||||
elseif is_yanked == 2 then
|
||||
cut = cut + 1
|
||||
end
|
||||
end
|
||||
|
||||
local count
|
||||
local style
|
||||
if cut > 0 then
|
||||
count = cut
|
||||
style = THEME.manager.count_cut
|
||||
elseif copied > 0 then
|
||||
count = copied
|
||||
style = THEME.manager.count_copied
|
||||
else
|
||||
count = selected
|
||||
style = THEME.manager.count_selected
|
||||
end
|
||||
|
||||
if count == 0 then
|
||||
return ui.Line({})
|
||||
else
|
||||
return ui.Line({
|
||||
ui.Span(string.format(" %s ", count)):style(style),
|
||||
ui.Span(" "),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function Header:tabs()
|
||||
|
|
@ -42,8 +83,8 @@ end
|
|||
function Header:render(area)
|
||||
local chunks = self:layout(area)
|
||||
|
||||
local left = ui.Line { self:cwd() }
|
||||
local right = ui.Line { self:tabs() }
|
||||
local left = ui.Line({ self:cwd() })
|
||||
local right = ui.Line({ self:selected_count(), self:tabs() })
|
||||
return {
|
||||
ui.Paragraph(chunks[1], { left }),
|
||||
ui.Paragraph(chunks[2], { right }):align(ui.Paragraph.RIGHT),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue