fix: when dev icons absent ()

* 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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 12 deletions

@ -23,9 +23,7 @@ M.check = function()
end
-- Optional dependencies
local has_devicons = Utils.has("nvim-web-devicons")
local has_mini_icons = Utils.has("mini.icons") or Utils.has("mini.nvim")
if has_devicons or has_mini_icons then
if Utils.icons_enabled() then
H.ok("Found icons plugin (nvim-web-devicons or mini.icons)")
else
H.warn("No icons plugin found (nvim-web-devicons or mini.icons). Icons will not be displayed")

@ -412,8 +412,8 @@ local function get_searching_hint()
end
local thinking_spinner_chars = {
"🤯",
"🙄",
Utils.icon("🤯", "?"),
Utils.icon("🙄", "¿"),
}
local thinking_spinner_index = 1
@ -452,8 +452,10 @@ local function generate_display_content(replacement)
return string.format(" > %s", line)
end)
:totable()
local result_lines =
vim.list_extend(vim.list_slice(lines, 1, replacement.last_search_tag_start_line), { "🤔 Thought content:" })
local result_lines = vim.list_extend(
vim.list_slice(lines, 1, replacement.last_search_tag_start_line),
{ Utils.icon("🤔 ") .. "Thought content:" }
)
result_lines = vim.list_extend(result_lines, formatted_thinking_content_lines)
result_lines = vim.list_extend(result_lines, vim.list_slice(lines, last_think_tag_end_line + 1))
return table.concat(result_lines, "\n")
@ -860,7 +862,7 @@ function Sidebar:render_result()
then
return
end
local header_text = "󰭻 Avante"
local header_text = Utils.icon("󰭻 ") .. "Avante"
self:render_header(
self.result_container.winid,
self.result_container.bufnr,
@ -882,13 +884,15 @@ function Sidebar:render_input(ask)
end
local header_text = string.format(
"󱜸 %s (" .. Config.mappings.sidebar.switch_windows .. ": switch focus)",
"%s%s (" .. Config.mappings.sidebar.switch_windows .. ": switch focus)",
Utils.icon("󱜸 "),
ask and "Ask" or "Chat with"
)
if self.code.selection ~= nil then
header_text = string.format(
"󱜸 %s (%d:%d) (<Tab>: switch focus)",
"%s%s (%d:%d) (<Tab>: switch focus)",
Utils.icon("󱜸 "),
ask and "Ask" or "Chat with",
self.code.selection.range.start.lnum,
self.code.selection.range.finish.lnum
@ -921,7 +925,8 @@ function Sidebar:render_selected_code()
selected_code_lines_count = #selected_code_lines
end
local header_text = " Selected Code"
local header_text = Utils.icon("")
.. "Selected Code"
.. (
selected_code_lines_count > selected_code_max_lines_count
and " (Show only the first " .. tostring(selected_code_max_lines_count) .. " lines)"
@ -2329,7 +2334,7 @@ function Sidebar:create_selected_files_container()
self:render_header(
self.selected_files_container.winid,
selected_files_buf,
"Selected Files",
Utils.icon("") .. "Selected Files",
Highlights.SUBTITLE,
Highlights.REVERSED_SUBTITLE
)

@ -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