Skip to content

Commit 0e3e040

Browse files
committed
feat(status): add support for mini.icons
1 parent 787af7c commit 0e3e040

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

lua/astroui/status/hl.lua

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,22 @@ function M.mode_bg() return config.modes[vim.fn.mode()][2] end
3838
---@return table # the highlight group for the current filetype foreground
3939
-- @usage local heirline_component = { provider = require("astroui.status").provider.fileicon(), hl = require("astroui.status").hl.filetype_color },
4040
function M.filetype_color(self)
41-
local devicons_avail, devicons = pcall(require, "nvim-web-devicons")
42-
if not devicons_avail then return {} end
43-
local _, color = devicons.get_icon_color(
44-
vim.fn.fnamemodify(vim.api.nvim_buf_get_name(self and self.bufnr or 0), ":t"),
45-
nil,
46-
{ default = true }
47-
)
41+
local color
42+
local bufnr = self and self.bufnr or 0
43+
local bufname = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t")
44+
45+
local mini_icons_avail, mini_icons = pcall(require, "mini.icons")
46+
if mini_icons_avail then -- mini.icons
47+
local _, hl = mini_icons.get("file", bufname)
48+
color = require("astroui").get_hlgroup(hl).fg
49+
if type(color) == "number" then color = string.format("#%06x", color) end
50+
else -- nvim-web-devicons
51+
local devicons_avail, devicons = pcall(require, "nvim-web-devicons")
52+
if devicons_avail then
53+
_, color = devicons.get_icon_color(bufname, nil, { default = true })
54+
end
55+
end
56+
4857
return { fg = color }
4958
end
5059

lua/astroui/status/provider.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,25 @@ end
422422
-- @see astroui.status.utils.stylize
423423
function M.file_icon(opts)
424424
return function(self)
425-
local devicons_avail, devicons = pcall(require, "nvim-web-devicons")
426-
if not devicons_avail then return "" end
425+
local ft_icon
427426
local bufnr = self and self.bufnr or 0
428-
local ft_icon, _ = devicons.get_icon(vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t"))
429-
if not ft_icon then
430-
ft_icon, _ = devicons.get_icon_by_filetype(vim.bo[bufnr].filetype, { default = true })
427+
local bufname = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t")
428+
429+
local mini_icons_avail, mini_icons = pcall(require, "mini.icons")
430+
if mini_icons_avail then -- mini.icons
431+
ft_icon, _ = mini_icons.get("file", bufname)
432+
end
433+
434+
if not ft_icon then -- nvim-web-devicons
435+
local devicons_avail, devicons = pcall(require, "nvim-web-devicons")
436+
if devicons_avail then
437+
ft_icon, _ = devicons.get_icon(bufname)
438+
if not ft_icon then
439+
ft_icon, _ = devicons.get_icon_by_filetype(vim.bo[bufnr].filetype, { default = true })
440+
end
441+
end
431442
end
443+
432444
return status_utils.stylize(ft_icon, opts)
433445
end
434446
end

0 commit comments

Comments
 (0)