Skip to content

feat(#2369): Add webdev_colors_folder option #2375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,16 @@ applying configuration.
},
},
icons = {
webdev_colors = true,
web_devicons = {
file = {
enable = true,
color = true,
},
folder = {
enable = false,
color = true,
},
},
git_placement = "before",
modified_placement = "after",
padding = " ",
Expand Down Expand Up @@ -970,9 +979,32 @@ UI rendering setup
*nvim-tree.renderer.icons*
Configuration options for icons.

*nvim-tree.renderer.icons.webdev_colors*
Use the webdev icon colors, otherwise `NvimTreeFileIcon`.
Type: `boolean`, Default: `true`
*nvim-tree.renderer.icons.web_devicons*
Configure optional plugin `"nvim-tree/nvim-web-devicons"`

*nvim-tree.renderer.icons.web_devicons.file*
File icons.

*nvim-tree.renderer.icons.web_devicons.file.enable*
Show icons on files.
Overrides |nvim-tree.renderer.icons.glyphs.default|
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.web_devicons.file.color*
Use icon colors for files.
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.web_devicons.folder*
Folder icons.

*nvim-tree.renderer.icons.web_devicons.folder.enable*
Show icons on folders.
Overrides |nvim-tree.renderer.icons.glyphs.folder|
Type: `boolean`, Default: `false`

*nvim-tree.renderer.icons.web_devicons.folder.color*
Use icon colors for folders.
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.git_placement*
Place where the git icons will be rendered.
Expand All @@ -999,7 +1031,7 @@ UI rendering setup
Configuration options for showing icon types.

*nvim-tree.renderer.icons.show.file*
Show an icon before the file name. `nvim-web-devicons` will be used if available.
Show an icon before the file name.
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.show.folder*
Expand Down Expand Up @@ -1027,7 +1059,8 @@ UI rendering setup
to appear in the signcolumn.

*nvim-tree.renderer.icons.glyphs.default*
Glyph for files. Will be overridden by `nvim-web-devicons` if available.
Glyph for files.
Overridden by |nvim-tree.renderer.icons.web_devicons| if available.
Type: `string`, Default: `""`

*nvim-tree.renderer.icons.glyphs.symlink*
Expand All @@ -1040,6 +1073,7 @@ UI rendering setup

*nvim-tree.renderer.icons.glyphs.folder*
Glyphs for directories.
Overridden by |nvim-tree.renderer.icons.web_devicons| if available.
Type: `table`, Default:
`{`
`arrow_closed = "",`
Expand Down
11 changes: 10 additions & 1 deletion lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,16 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
},
icons = {
webdev_colors = true,
web_devicons = {
file = {
enable = true,
color = true,
},
folder = {
enable = false,
color = true,
},
},
git_placement = "before",
modified_placement = "after",
padding = " ",
Expand Down
11 changes: 11 additions & 0 deletions lua/nvim-tree/legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ local function refactored(opts)

-- 2023/07/16
utils.move_missing_val(opts, "git", "ignore", opts, "filters", "git_ignored", true)

-- 2023/08/26
utils.move_missing_val(
opts,
"renderer.icons",
"webdev_colors",
opts,
"renderer.icons.web_devicons.file",
"color",
true
)
end

local function deprecated(opts)
Expand Down
5 changes: 2 additions & 3 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ end
---@return HighlightedString icon, HighlightedString name
function Builder:_build_folder(node)
local has_children = #node.nodes ~= 0 or node.has_children
local icon = icons.get_folder_icon(node.open, node.link_to ~= nil, has_children)
local icon, icon_hl = icons.get_folder_icon(node, has_children)
local foldername = get_folder_name(node) .. self.trailing_slash

local icon_hl
if #icon > 0 then
if #icon > 0 and icon_hl == nil then
if node.open then
icon_hl = "NvimTreeOpenedFolderIcon"
else
Expand Down
31 changes: 24 additions & 7 deletions lua/nvim-tree/renderer/components/icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ local function empty()
return ""
end

local function get_folder_icon(open, is_symlink, has_children)
local function get_folder_icon_default(node, has_children)
local is_symlink = node.links_to ~= nil
local n
if is_symlink and open then
if is_symlink and node.open then
n = M.config.glyphs.folder.symlink_open
elseif is_symlink then
n = M.config.glyphs.folder.symlink
elseif open then
elseif node.open then
if has_children then
n = M.config.glyphs.folder.open
else
Expand All @@ -28,7 +29,19 @@ local function get_folder_icon(open, is_symlink, has_children)
n = M.config.glyphs.folder.empty
end
end
return n
return n, nil
end

local function get_folder_icon_webdev(node, has_children)
local icon, hl_group = M.devicons.get_icon(node.name, node.extension)
if not M.config.web_devicons.folder.color then
hl_group = nil
end
if icon ~= nil then
return icon, hl_group
else
return get_folder_icon_default(node, has_children)
end
end

local function get_file_icon_default()
Expand All @@ -43,7 +56,7 @@ end

local function get_file_icon_webdev(fname, extension)
local icon, hl_group = M.devicons.get_icon(fname, extension)
if not M.config.webdev_colors then
if not M.config.web_devicons.file.color then
hl_group = "NvimTreeFileIcon"
end
if icon and hl_group ~= "DevIconDefault" then
Expand All @@ -58,7 +71,7 @@ end

local function config_file_icon()
if M.config.show.file then
if M.devicons then
if M.devicons and M.config.web_devicons.file.enable then
M.get_file_icon = get_file_icon_webdev
else
M.get_file_icon = get_file_icon_default
Expand All @@ -70,7 +83,11 @@ end

local function config_folder_icon()
if M.config.show.folder then
M.get_folder_icon = get_folder_icon
if M.devicons and M.config.web_devicons.folder.enable then
M.get_folder_icon = get_folder_icon_webdev
else
M.get_folder_icon = get_folder_icon_default
end
else
M.get_folder_icon = empty
end
Expand Down