file devicon uses library to fall back
This commit is contained in:
parent
0acbc79909
commit
68183069e7
@ -74,16 +74,9 @@ function FileNode:highlighted_icon()
|
||||
|
||||
local str, hl
|
||||
|
||||
-- devicon if enabled and available
|
||||
-- devicon if enabled and available, fallback to default
|
||||
if self.explorer.opts.renderer.icons.web_devicons.file.enable then
|
||||
str, hl = icons.get_icon(self.name)
|
||||
if not str then
|
||||
local default_icon = icons.get_default_icon()
|
||||
if default_icon then
|
||||
str = default_icon.icon
|
||||
hl = "DevIcon" .. default_icon.name
|
||||
end
|
||||
end
|
||||
str, hl = icons.get_icon(self.name, nil, { default = true })
|
||||
if not self.explorer.opts.renderer.icons.web_devicons.file.color then
|
||||
hl = nil
|
||||
end
|
||||
|
||||
@ -1,50 +1,33 @@
|
||||
---@class DevIcon
|
||||
---@field icon string
|
||||
---@field color string
|
||||
---@field cterm_color string
|
||||
---@field name string
|
||||
---@alias devicons_get_icon fun(name: string, ext: string?, opts: table?): string?, string?
|
||||
---@alias devicons_setup fun(opts: table?)
|
||||
|
||||
---@class DevIcons
|
||||
---@field get_icon fun(name: string, ext: string?): string?, string?
|
||||
---@field get_default_icon fun(): DevIcon
|
||||
---@class DevIcons?
|
||||
---@field setup devicons_setup
|
||||
---@field get_icon devicons_get_icon
|
||||
local devicons
|
||||
|
||||
local M = {
|
||||
---@type DevIcons?
|
||||
devicons = nil,
|
||||
}
|
||||
local M = {}
|
||||
|
||||
---Wrapper around nvim-web-devicons, nils if devicons not available
|
||||
---@param name string
|
||||
---@return string? icon
|
||||
---@return string? hl_group
|
||||
function M.get_icon(name)
|
||||
if M.devicons then
|
||||
return M.devicons.get_icon(name, nil)
|
||||
---@type devicons_get_icon
|
||||
function M.get_icon(name, ext, opts)
|
||||
if devicons then
|
||||
return devicons.get_icon(name, ext, opts)
|
||||
else
|
||||
return nil, nil
|
||||
end
|
||||
end
|
||||
|
||||
---Wrapper around nvim-web-devicons, nil if devicons not available
|
||||
---@return DevIcon?
|
||||
function M.get_default_icon()
|
||||
if M.devicons then
|
||||
return M.devicons.get_default_icon()
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
---Attempt to use nvim-web-devicons if present and enabled for file or folder
|
||||
---@param opts table
|
||||
function M.setup(opts)
|
||||
if opts.renderer.icons.show.file or opts.renderer.icons.show.folder then
|
||||
local devicons_ok, devicons = pcall(require, "nvim-web-devicons")
|
||||
if devicons_ok then
|
||||
M.devicons = devicons
|
||||
local ok, di = pcall(require, "nvim-web-devicons")
|
||||
if ok then
|
||||
devicons = di
|
||||
|
||||
-- does nothing if already called i.e. don't clobber previous user setup
|
||||
M.devicons.setup()
|
||||
devicons.setup()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user