Move app data accessing to the if-else block

This commit is contained in:
sxyazi 2024-02-15 22:37:07 +08:00
parent e2a5211015
commit b59e4e5a02
No known key found for this signature in database
2 changed files with 21 additions and 18 deletions

View file

@ -29,9 +29,9 @@ tab_inactive = { fg = "white", bg = "darkgray" }
tab_width = 1 tab_width = 1
# Selected counter # Selected counter
count_selected = { fg = "white", bg = "green" } count_copied = { fg = "black", bg = "lightgreen" }
count_copied = { fg = "white", bg = "yellow" } count_cut = { fg = "black", bg = "lightred" }
count_cut = { fg = "white", bg = "red" } count_selected = { fg = "black", bg = "lightblue" }
# Border # Border
border_symbol = "│" border_symbol = "│"

View file

@ -15,35 +15,38 @@ function Header:cwd()
end end
function Header:counter() function Header:counter()
local selected = #cx.active.selected
local yanked = #cx.yanked local yanked = #cx.yanked
local count local count, style
local style if yanked == 0 then
if cx.yanked.is_cut then count = #cx.active.selected
style = THEME.manager.count_selected
elseif cx.yanked.is_cut then
count = yanked count = yanked
style = THEME.manager.count_cut style = THEME.manager.count_cut
elseif yanked > 0 then else
count = yanked count = yanked
style = THEME.manager.count_copied style = THEME.manager.count_copied
else
count = selected
style = THEME.manager.count_selected
end end
if count == 0 then if count == 0 then
return ui.Line({}) return ui.Line {}
else
return ui.Line({
ui.Span(string.format(" %s ", count)):style(style),
ui.Span(" "),
})
end end
return ui.Line {
ui.Span(string.format(" %d ", count)):style(style),
ui.Span(" "),
}
end end
function Header:tabs() function Header:tabs()
local tabs = #cx.tabs
if tabs == 1 then
return ui.Line {}
end
local spans = {} local spans = {}
for i = 1, #cx.tabs do for i = 1, tabs do
local text = i local text = i
if THEME.manager.tab_width > 2 then if THEME.manager.tab_width > 2 then
text = ya.truncate(text .. " " .. cx.tabs[i]:name(), THEME.manager.tab_width) text = ya.truncate(text .. " " .. cx.tabs[i]:name(), THEME.manager.tab_width)