fix: when dev icons absent (#1214)

* Add helper function to check for dev icon availability

* Add function to display dev icon or nothing if icon plugins unavailable

* Fix existing use of icons

* Reformat with stylua
This commit is contained in:
Oliver Lorton
2025-02-10 17:43:01 +00:00
committed by GitHub
parent 6e18616c16
commit cc46386130
3 changed files with 33 additions and 12 deletions

View File

@@ -918,4 +918,22 @@ function M.read_file_from_buf_or_disk(file_path)
end
end
---Check if an icon plugin is installed
---@return boolean
M.icons_enabled = function() return M.has("nvim-web-devicons") or M.has("mini.icons") or M.has("mini.nvim") end
---Display an string with icon, if an icon plugin is available.
---Dev icons are an optional install for avante, this function prevents ugly chars
---being displayed by displaying fallback options or nothing at all.
---@param string_with_icon string
---@param utf8_fallback string|nil
---@return string
M.icon = function(string_with_icon, utf8_fallback)
if M.icons_enabled() then
return string_with_icon
else
return utf8_fallback or ""
end
end
return M