@@ -11,6 +11,7 @@ local M = {}
11
11
-- NOTE: When adding new icons, remember to add an entry to the `filetypes` table, if applicable.
12
12
local icons , icons_by_filename , icons_by_file_extension , icons_by_operating_system
13
13
local icons_by_desktop_environment , icons_by_window_manager
14
+ local user_icons
14
15
15
16
local filetypes = require " nvim-web-devicons.filetypes"
16
17
@@ -197,39 +198,11 @@ local function get_highlight_ctermfg(icon_data)
197
198
end
198
199
end
199
200
200
- local loaded = false
201
-
202
- function M .has_loaded ()
203
- return loaded
204
- end
205
-
206
- local if_nil = vim .F .if_nil
207
- function M .setup (opts )
208
- if loaded then
201
+ local function apply_user_icons ()
202
+ if type (user_icons ) ~= " table" then
209
203
return
210
204
end
211
205
212
- loaded = true
213
-
214
- local user_icons = opts or {}
215
-
216
- if user_icons .default then
217
- global_opts .default = true
218
- end
219
-
220
- if user_icons .strict then
221
- global_opts .strict = true
222
- end
223
-
224
- global_opts .color_icons = if_nil (user_icons .color_icons , global_opts .color_icons )
225
-
226
- if user_icons .variant == " light" or user_icons .variant == " dark" then
227
- global_opts .variant = user_icons .variant
228
-
229
- -- Reload the icons after setting variant option
230
- refresh_icons ()
231
- end
232
-
233
206
if user_icons .override and user_icons .override .default_icon then
234
207
default_icon = user_icons .override .default_icon
235
208
end
@@ -283,6 +256,42 @@ function M.setup(opts)
283
256
end
284
257
285
258
icons [1 ] = default_icon
259
+ end
260
+
261
+ local loaded = false
262
+
263
+ function M .has_loaded ()
264
+ return loaded
265
+ end
266
+
267
+ local if_nil = vim .F .if_nil
268
+ function M .setup (opts )
269
+ if loaded then
270
+ return
271
+ end
272
+
273
+ loaded = true
274
+
275
+ user_icons = opts or {}
276
+
277
+ if user_icons .default then
278
+ global_opts .default = true
279
+ end
280
+
281
+ if user_icons .strict then
282
+ global_opts .strict = true
283
+ end
284
+
285
+ global_opts .color_icons = if_nil (user_icons .color_icons , global_opts .color_icons )
286
+
287
+ if user_icons .variant == " light" or user_icons .variant == " dark" then
288
+ global_opts .variant = user_icons .variant
289
+
290
+ -- Reload the icons after setting variant option
291
+ refresh_icons ()
292
+ end
293
+
294
+ apply_user_icons ()
286
295
287
296
M .set_up_highlights ()
288
297
@@ -419,14 +428,14 @@ function M.get_icon_cterm_color_by_filetype(ft, opts)
419
428
return M .get_icon_cterm_color (name or " " , nil , opts )
420
429
end
421
430
422
- function M .set_icon (user_icons )
423
- icons = vim .tbl_extend (" force" , icons , user_icons or {})
424
- global_opts .override = vim .tbl_extend (" force" , global_opts .override , user_icons or {})
431
+ function M .set_icon (user_icons_opts )
432
+ icons = vim .tbl_extend (" force" , icons , user_icons_opts or {})
433
+ global_opts .override = vim .tbl_extend (" force" , global_opts .override , user_icons_opts or {})
425
434
if not global_opts .color_icons then
426
435
return
427
436
end
428
437
429
- for _ , icon_data in pairs (user_icons ) do
438
+ for _ , icon_data in pairs (user_icons_opts ) do
430
439
set_up_highlight (icon_data )
431
440
end
432
441
end
@@ -447,6 +456,7 @@ refresh_icons()
447
456
448
457
function M .refresh ()
449
458
refresh_icons ()
459
+ apply_user_icons ()
450
460
M .set_up_highlights (true )
451
461
end
452
462
0 commit comments