#1172 add renderer.icons.webdev_colors default true (#1175)

This commit is contained in:
Alexander Courtis 2022-04-18 23:45:14 +10:00 committed by GitHub
parent cff5a106b2
commit cdbc210d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 26 deletions

View File

@ -151,6 +151,9 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
none = " ",
},
},
icons = {
webdev_colors = true,
},
},
hijack_directories = {
enable = true,

View File

@ -120,6 +120,9 @@ function.
none = " ",
},
},
icons = {
webdev_colors = true,
},
},
hijack_directories = {
enable = true,
@ -433,6 +436,12 @@ Here is a list of the options available in the setup call:
type: `table`
default: `{ corner = "└ ", edge = "│ ", none = " ", }`
- |renderer.icons|: configuration options for icons
- |renderer.icons.webdev_colors|: use the webdev icon colors, otherwise `NvimTreeFileIcon`.
type: `boolean`
default: `true`
*nvim-tree.filters*
|filters|: filtering options

View File

@ -345,6 +345,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
none = " ",
},
},
icons = {
webdev_colors = true,
},
},
hijack_directories = {
enable = true,

View File

@ -9,12 +9,15 @@ local core = require "nvim-tree.core"
local api = vim.api
local M = {}
local lines = {}
local hl = {}
local index = 0
local namespace_id = api.nvim_create_namespace "NvimTreeHighlights"
local icon_state = _icons.get_config()
local web_devicons = icon_state.has_devicons and require "nvim-web-devicons" or nil
local should_hl_opened_files = (vim.g.nvim_tree_highlight_opened_files or 0) ~= 0
@ -63,13 +66,21 @@ end
local get_file_icon = function()
return ""
end
if icon_state.show_file_icon then
if icon_state.has_devicons then
local web_devicons = require "nvim-web-devicons"
get_file_icon = function(fname, extension, line, depth)
local get_file_icon_default = function(_, _, line, depth)
local hl_group = "NvimTreeFileIcon"
local icon = icon_state.icons.default
if #icon > 0 then
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
end
return #icon > 0 and icon .. icon_padding or ""
end
local get_file_icon_webdev = function(fname, extension, line, depth)
local icon, hl_group = web_devicons.get_icon(fname, extension)
if not M.config.icons.webdev_colors then
hl_group = "NvimTreeFileIcon"
end
if icon and hl_group ~= "DevIconDefault" then
if hl_group then
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
@ -79,18 +90,15 @@ if icon_state.show_file_icon then
-- If there are more extensions to the file, try to grab the icon for them recursively
return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth)
else
return #icon_state.icons.default > 0 and icon_state.icons.default .. icon_padding or ""
end
return get_file_icon_default(fname, extension, line, depth)
end
end
if icon_state.show_file_icon then
if web_devicons then
get_file_icon = get_file_icon_webdev
else
get_file_icon = function(_, _, line, depth)
local hl_group = "NvimTreeFileIcon"
local icon = icon_state.icons.default
if #icon > 0 then
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
end
return #icon > 0 and icon .. icon_padding or ""
end
get_file_icon = get_file_icon_default
end
end
@ -224,8 +232,6 @@ local function update_draw_data(tree, depth, markers)
end
end
local M = {}
local function compute_header()
if view.is_root_folder_visible(core.get_cwd()) then
local root_folder_modifier = vim.g.nvim_tree_root_folder_modifier or ":~"
@ -292,6 +298,7 @@ end
function M.setup(opts)
M.config = {
indent_markers = opts.renderer.indent_markers,
icons = opts.renderer.icons,
}
require("nvim-tree.renderer.padding").setup(opts)