From c9178d4ab343aa03bedb607a7255f5ecc3d38098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Mon, 23 Oct 2023 12:36:54 +0800 Subject: [PATCH] feat: add a new `Folder:icon()` API to make it easier for users to extend icons (#301) --- yazi-plugin/preset/components/folder.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/yazi-plugin/preset/components/folder.lua b/yazi-plugin/preset/components/folder.lua index 8b13c5cf..4ee28af0 100644 --- a/yazi-plugin/preset/components/folder.lua +++ b/yazi-plugin/preset/components/folder.lua @@ -14,6 +14,8 @@ function Folder:by_kind(kind) end end +function Folder:icon(file) return ui.Span(" " .. file:icon() .. " ") end + function Folder:highlighted_name(file) -- Complete prefix when searching across directories local prefix = file:prefix() or "" @@ -115,7 +117,7 @@ function Folder:parent(area) local items = {} for _, f in ipairs(folder.window) do - local item = ui.ListItem(" " .. f:icon() .. " " .. f.name .. " ") + local item = ui.ListItem(ui.Line { self:icon(f), ui.Span(f.name) }) if f:is_hovered() then item = item:style(THEME.manager.hovered) else @@ -135,7 +137,7 @@ function Folder:current(area) local name = self:highlighted_name(f) -- Highlight hovered file - local item = ui.ListItem(ui.Line { ui.Span(" " .. f:icon() .. " "), table.unpack(name) }) + local item = ui.ListItem(ui.Line { self:icon(f), table.unpack(name) }) if f:is_hovered() then item = item:style(THEME.manager.hovered) else @@ -162,7 +164,7 @@ function Folder:preview(area) local items = {} for _, f in ipairs(folder.window) do - local item = ui.ListItem(" " .. f:icon() .. " " .. f.name .. " ") + local item = ui.ListItem(ui.Line { self:icon(f), ui.Span(f.name) }) if f:is_hovered() then item = item:style(THEME.manager.preview_hovered) else