mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: add counter component to the header for displaying currently yanked/selected items (#646)
This commit is contained in:
parent
52d91c0e42
commit
b82587e2c9
3 changed files with 43 additions and 3 deletions
|
|
@ -24,10 +24,15 @@ marker_marked = { fg = "lightyellow", bg = "lightyellow" }
|
|||
marker_selected = { fg = "lightblue", bg = "lightblue" }
|
||||
|
||||
# Tab
|
||||
tab_active = { fg = "black", bg = "lightblue" }
|
||||
tab_active = { fg = "black", bg = "white" }
|
||||
tab_inactive = { fg = "white", bg = "darkgray" }
|
||||
tab_width = 1
|
||||
|
||||
# Count
|
||||
count_copied = { fg = "black", bg = "lightgreen" }
|
||||
count_cut = { fg = "black", bg = "lightred" }
|
||||
count_selected = { fg = "black", bg = "lightblue" }
|
||||
|
||||
# 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,
|
||||
|
|
|
|||
|
|
@ -14,9 +14,39 @@ function Header:cwd()
|
|||
return span:style(THEME.manager.cwd)
|
||||
end
|
||||
|
||||
function Header:counter()
|
||||
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
|
||||
|
||||
function Header:tabs()
|
||||
local tabs = #cx.tabs
|
||||
if tabs == 1 then
|
||||
return ui.Line {}
|
||||
end
|
||||
|
||||
local spans = {}
|
||||
for i = 1, #cx.tabs do
|
||||
for i = 1, tabs do
|
||||
local text = i
|
||||
if THEME.manager.tab_width > 2 then
|
||||
text = ya.truncate(text .. " " .. cx.tabs[i]:name(), THEME.manager.tab_width)
|
||||
|
|
@ -43,7 +73,7 @@ function Header:render(area)
|
|||
local chunks = self:layout(area)
|
||||
|
||||
local left = ui.Line { self:cwd() }
|
||||
local right = ui.Line { self:tabs() }
|
||||
local right = ui.Line { self:counter(), 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