diff --git a/yazi-config/preset/theme.toml b/yazi-config/preset/theme.toml index 76231e03..6e59cc40 100644 --- a/yazi-config/preset/theme.toml +++ b/yazi-config/preset/theme.toml @@ -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" } diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index 4deeaa99..0b46ff07 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -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, diff --git a/yazi-plugin/preset/components/header.lua b/yazi-plugin/preset/components/header.lua index 447936a1..d7c9de34 100644 --- a/yazi-plugin/preset/components/header.lua +++ b/yazi-plugin/preset/components/header.lua @@ -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),