From b59e4e5a0222a7126b498c8b4e58d274006af384 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 15 Feb 2024 22:37:07 +0800 Subject: [PATCH] Move app data accessing to the if-else block --- yazi-config/preset/theme.toml | 6 ++--- yazi-plugin/preset/components/header.lua | 33 +++++++++++++----------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/yazi-config/preset/theme.toml b/yazi-config/preset/theme.toml index 41bda4ae..3673f83a 100644 --- a/yazi-config/preset/theme.toml +++ b/yazi-config/preset/theme.toml @@ -29,9 +29,9 @@ 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" } +count_copied = { fg = "black", bg = "lightgreen" } +count_cut = { fg = "black", bg = "lightred" } +count_selected = { fg = "black", bg = "lightblue" } # Border border_symbol = "│" diff --git a/yazi-plugin/preset/components/header.lua b/yazi-plugin/preset/components/header.lua index 5a62b5f5..1cfc1d17 100644 --- a/yazi-plugin/preset/components/header.lua +++ b/yazi-plugin/preset/components/header.lua @@ -15,35 +15,38 @@ function Header:cwd() end function Header:counter() - local selected = #cx.active.selected local yanked = #cx.yanked - local count - local style - if cx.yanked.is_cut then + 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 - elseif yanked > 0 then + else count = yanked 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(" "), - }) + 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)