From b82587e2c94f565387b2df3599db7edb1d65d99a Mon Sep 17 00:00:00 2001 From: Rolv Apneseth Date: Thu, 15 Feb 2024 14:54:57 +0000 Subject: [PATCH] feat: add counter component to the header for displaying currently yanked/selected items (#646) --- yazi-config/preset/theme.toml | 7 ++++- yazi-config/src/theme/theme.rs | 5 ++++ yazi-plugin/preset/components/header.lua | 34 ++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/yazi-config/preset/theme.toml b/yazi-config/preset/theme.toml index 76231e03..cb33b9e7 100644 --- a/yazi-config/preset/theme.toml +++ b/yazi-config/preset/theme.toml @@ -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" } diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index 4deeaa99..66d6e479 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..1cfc1d17 100644 --- a/yazi-plugin/preset/components/header.lua +++ b/yazi-plugin/preset/components/header.lua @@ -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),