fix(icons): make devicons optional (#3616)

* fix(icons): make devicons optional

* code review suggestion

* fix: devicons_enable > devicons.enable
This commit is contained in:
LostNeophyte 2023-01-13 15:24:05 +01:00 committed by GitHub
parent 28acebe7dd
commit 3115088e92
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View file

@ -99,11 +99,18 @@ M.get_filename = function()
local f = require "lvim.utils.functions"
if not f.isempty(filename) then
local file_icon, hl_group = require("nvim-web-devicons").get_icon(filename, extension, { default = true })
local file_icon, hl_group
local devicons_ok, devicons = pcall(require, "nvim-web-devicons")
if lvim.use_icons and devicons_ok then
file_icon, hl_group = devicons.get_icon(filename, extension, { default = true })
if f.isempty(file_icon) then
file_icon = lvim.icons.kind.File
end
else
file_icon = ""
hl_group = "Normal"
end
local buf_ft = vim.bo.filetype

View file

@ -83,6 +83,10 @@ M.config = function()
end
function M.icon_setup()
if not lvim.builtin.lir.devicons.enable then
return
end
local function get_hl_by_name(name)
local ret = vim.api.nvim_get_hl_by_name(name.group, true)
return string.format("#%06x", ret[name.property])
@ -93,13 +97,16 @@ function M.icon_setup()
icon_hl = "#42A5F5"
end
require("nvim-web-devicons").set_icon {
local devicons_ok, devicons = pcall(require, "nvim-web-devicons")
if devicons_ok then
devicons.set_icon {
lir_folder_icon = {
icon = lvim.builtin.lir.icon,
color = icon_hl,
name = "LirFolderNode",
},
}
end
end
function M.setup()
@ -107,6 +114,11 @@ function M.setup()
if not status_ok then
return
end
if not lvim.use_icons then
lvim.builtin.lir.devicons.enable = false
end
lir.setup(lvim.builtin.lir)
if lvim.builtin.lir.on_config_done then