Skip to content

Commit cdbc210

Browse files
authored
#1172 add renderer.icons.webdev_colors default true (#1175)
1 parent cff5a10 commit cdbc210

File tree

4 files changed

+48
-26
lines changed

4 files changed

+48
-26
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
151151
none = " ",
152152
},
153153
},
154+
icons = {
155+
webdev_colors = true,
156+
},
154157
},
155158
hijack_directories = {
156159
enable = true,

doc/nvim-tree-lua.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ function.
120120
none = " ",
121121
},
122122
},
123+
icons = {
124+
webdev_colors = true,
125+
},
123126
},
124127
hijack_directories = {
125128
enable = true,
@@ -433,6 +436,12 @@ Here is a list of the options available in the setup call:
433436
type: `table`
434437
default: `{ corner = "└ ", edge = "│ ", none = " ", }`
435438

439+
- |renderer.icons|: configuration options for icons
440+
441+
- |renderer.icons.webdev_colors|: use the webdev icon colors, otherwise `NvimTreeFileIcon`.
442+
type: `boolean`
443+
default: `true`
444+
436445
*nvim-tree.filters*
437446
|filters|: filtering options
438447

lua/nvim-tree.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
345345
none = " ",
346346
},
347347
},
348+
icons = {
349+
webdev_colors = true,
350+
},
348351
},
349352
hijack_directories = {
350353
enable = true,

lua/nvim-tree/renderer/init.lua

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ local core = require "nvim-tree.core"
99

1010
local api = vim.api
1111

12+
local M = {}
13+
1214
local lines = {}
1315
local hl = {}
1416
local index = 0
1517
local namespace_id = api.nvim_create_namespace "NvimTreeHighlights"
1618

1719
local icon_state = _icons.get_config()
20+
local web_devicons = icon_state.has_devicons and require "nvim-web-devicons" or nil
1821

1922
local should_hl_opened_files = (vim.g.nvim_tree_highlight_opened_files or 0) ~= 0
2023

@@ -63,34 +66,39 @@ end
6366
local get_file_icon = function()
6467
return ""
6568
end
66-
if icon_state.show_file_icon then
67-
if icon_state.has_devicons then
68-
local web_devicons = require "nvim-web-devicons"
6969

70-
get_file_icon = function(fname, extension, line, depth)
71-
local icon, hl_group = web_devicons.get_icon(fname, extension)
70+
local get_file_icon_default = function(_, _, line, depth)
71+
local hl_group = "NvimTreeFileIcon"
72+
local icon = icon_state.icons.default
73+
if #icon > 0 then
74+
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
75+
end
76+
return #icon > 0 and icon .. icon_padding or ""
77+
end
7278

73-
if icon and hl_group ~= "DevIconDefault" then
74-
if hl_group then
75-
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
76-
end
77-
return icon .. icon_padding
78-
elseif string.match(extension, "%.(.*)") then
79-
-- If there are more extensions to the file, try to grab the icon for them recursively
80-
return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth)
81-
else
82-
return #icon_state.icons.default > 0 and icon_state.icons.default .. icon_padding or ""
83-
end
79+
local get_file_icon_webdev = function(fname, extension, line, depth)
80+
local icon, hl_group = web_devicons.get_icon(fname, extension)
81+
if not M.config.icons.webdev_colors then
82+
hl_group = "NvimTreeFileIcon"
83+
end
84+
if icon and hl_group ~= "DevIconDefault" then
85+
if hl_group then
86+
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
8487
end
88+
return icon .. icon_padding
89+
elseif string.match(extension, "%.(.*)") then
90+
-- If there are more extensions to the file, try to grab the icon for them recursively
91+
return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth)
8592
else
86-
get_file_icon = function(_, _, line, depth)
87-
local hl_group = "NvimTreeFileIcon"
88-
local icon = icon_state.icons.default
89-
if #icon > 0 then
90-
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
91-
end
92-
return #icon > 0 and icon .. icon_padding or ""
93-
end
93+
return get_file_icon_default(fname, extension, line, depth)
94+
end
95+
end
96+
97+
if icon_state.show_file_icon then
98+
if web_devicons then
99+
get_file_icon = get_file_icon_webdev
100+
else
101+
get_file_icon = get_file_icon_default
94102
end
95103
end
96104

@@ -224,8 +232,6 @@ local function update_draw_data(tree, depth, markers)
224232
end
225233
end
226234

227-
local M = {}
228-
229235
local function compute_header()
230236
if view.is_root_folder_visible(core.get_cwd()) then
231237
local root_folder_modifier = vim.g.nvim_tree_root_folder_modifier or ":~"
@@ -292,6 +298,7 @@ end
292298
function M.setup(opts)
293299
M.config = {
294300
indent_markers = opts.renderer.indent_markers,
301+
icons = opts.renderer.icons,
295302
}
296303

297304
require("nvim-tree.renderer.padding").setup(opts)

0 commit comments

Comments
 (0)