|
1 |
| ----@class DevIcon |
2 |
| ----@field icon string |
3 |
| ----@field color string |
4 |
| ----@field cterm_color string |
5 |
| ----@field name string |
| 1 | +---@alias devicons_get_icon fun(name: string, ext: string?, opts: table?): string?, string? |
| 2 | +---@alias devicons_setup fun(opts: table?) |
6 | 3 |
|
7 |
| ----@class DevIcons |
8 |
| ----@field get_icon fun(name: string, ext: string?): string?, string? |
9 |
| ----@field get_default_icon fun(): DevIcon |
| 4 | +---@class DevIcons? |
| 5 | +---@field setup devicons_setup |
| 6 | +---@field get_icon devicons_get_icon |
| 7 | +local devicons |
10 | 8 |
|
11 |
| -local M = { |
12 |
| - ---@type DevIcons? |
13 |
| - devicons = nil, |
14 |
| -} |
| 9 | +local M = {} |
15 | 10 |
|
16 | 11 | ---Wrapper around nvim-web-devicons, nils if devicons not available
|
17 |
| ----@param name string |
18 |
| ----@return string? icon |
19 |
| ----@return string? hl_group |
20 |
| -function M.get_icon(name) |
21 |
| - if M.devicons then |
22 |
| - return M.devicons.get_icon(name, nil) |
| 12 | +---@type devicons_get_icon |
| 13 | +function M.get_icon(name, ext, opts) |
| 14 | + if devicons then |
| 15 | + return devicons.get_icon(name, ext, opts) |
23 | 16 | else
|
24 | 17 | return nil, nil
|
25 | 18 | end
|
26 | 19 | end
|
27 | 20 |
|
28 |
| ----Wrapper around nvim-web-devicons, nil if devicons not available |
29 |
| ----@return DevIcon? |
30 |
| -function M.get_default_icon() |
31 |
| - if M.devicons then |
32 |
| - return M.devicons.get_default_icon() |
33 |
| - else |
34 |
| - return nil |
35 |
| - end |
36 |
| -end |
37 |
| - |
38 | 21 | ---Attempt to use nvim-web-devicons if present and enabled for file or folder
|
39 | 22 | ---@param opts table
|
40 | 23 | function M.setup(opts)
|
41 | 24 | if opts.renderer.icons.show.file or opts.renderer.icons.show.folder then
|
42 |
| - local devicons_ok, devicons = pcall(require, "nvim-web-devicons") |
43 |
| - if devicons_ok then |
44 |
| - M.devicons = devicons |
| 25 | + local ok, di = pcall(require, "nvim-web-devicons") |
| 26 | + if ok then |
| 27 | + devicons = di |
45 | 28 |
|
46 | 29 | -- does nothing if already called i.e. don't clobber previous user setup
|
47 |
| - M.devicons.setup() |
| 30 | + devicons.setup() |
48 | 31 | end
|
49 | 32 | end
|
50 | 33 | end
|
|
0 commit comments