From 43106c233e017242ce9a6abfa05ed30d701926a7 Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Sun, 20 Apr 2025 11:17:03 +0700 Subject: [PATCH] Add support for mini.icons as a file icons provider --- README.md | 2 +- doc/diffview_defaults.txt | 2 +- lua/diffview/health.lua | 4 ++++ lua/diffview/hl.lua | 16 ++++++++++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9298e1f5..bccee4a6 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ for any git rev. - Git ≥ 2.31.0 (for Git support) - Mercurial ≥ 5.4.0 (for Mercurial support) - Neovim ≥ 0.7.0 (with LuaJIT) -- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) (optional) For file icons +- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) or [mini.icons](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-icons.md) (optional) for file icons ## Installation diff --git a/doc/diffview_defaults.txt b/doc/diffview_defaults.txt index 1ff1f7db..0b60b064 100644 --- a/doc/diffview_defaults.txt +++ b/doc/diffview_defaults.txt @@ -7,7 +7,7 @@ DEFAULT CONFIG *diffview.defaults* enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl| git_cmd = { "git" }, -- The git executable followed by default args. hg_cmd = { "hg" }, -- The hg executable followed by default args. - use_icons = true, -- Requires nvim-web-devicons + use_icons = true, -- Requires nvim-web-devicons or mini.icons show_help_hints = true, -- Show hints for how to open the help panel watch_index = true, -- Update views and index buffers when the git index changes. icons = { -- Only applies when use_icons is true. diff --git a/lua/diffview/health.lua b/lua/diffview/health.lua index 9c67c42b..3583c5c1 100644 --- a/lua/diffview/health.lua +++ b/lua/diffview/health.lua @@ -19,6 +19,10 @@ M.plugin_deps = { name = "nvim-web-devicons", optional = true, }, + { + name = "mini.icons", + optional = true, + }, } ---@param cmd string|string[] diff --git a/lua/diffview/hl.lua b/lua/diffview/hl.lua index 693dd358..970fe775 100644 --- a/lua/diffview/hl.lua +++ b/lua/diffview/hl.lua @@ -4,7 +4,7 @@ local config = lazy.require("diffview.config") ---@module "diffview.config" local utils = lazy.require("diffview.utils") ---@module "diffview.utils" local api = vim.api -local web_devicons +local web_devicons, mini_icons local icon_cache = {} local M = {} @@ -349,14 +349,19 @@ end function M.get_file_icon(name, ext, render_data, line_idx, offset) if not config.get_config().use_icons then return "" end - if not web_devicons then + if not (web_devicons or mini_icons) then local ok ok, web_devicons = pcall(require, "nvim-web-devicons") + if not ok then + ok, mini_icons = pcall(require, "mini.icons") + web_devicons = nil + end + if not ok then config.get_config().use_icons = false utils.warn( - "nvim-web-devicons is required to use file icons! " + "nvim-web-devicons or mini.icons is required to use file icons! " .. "Set `use_icons = false` in your config to stop seeing this message." ) @@ -369,9 +374,12 @@ function M.get_file_icon(name, ext, render_data, line_idx, offset) if icon_cache[icon_key] then icon, hl = unpack(icon_cache[icon_key]) - else + elseif web_devicons then icon, hl = web_devicons.get_icon(name, ext, { default = true }) icon_cache[icon_key] = { icon, hl } + else + icon, hl = mini_icons.get("file", name) + icon_cache[icon_key] = { icon, hl } end if icon then