some config adjustments and add colors.lua

This commit is contained in:
kiyan42 2020-10-24 20:31:35 +02:00
parent 7fe7cc4ee1
commit 9870903a2c
5 changed files with 102 additions and 29 deletions

View File

@ -56,12 +56,12 @@ local function get_links()
CursorLine = 'CursorLine',
VertSplit = 'VertSplit',
CursorColumn = 'CursorColumn',
FileDirty = 'LuaTreeGitDirty',
FileNew = 'LuaTreeGitNew',
FileRenamed = 'LuaTreeGitRenamed',
FileMerge = 'LuaTreeGitMerge',
FileStaged = 'LuaTreeGitStaged',
FileDeleted = 'LuaTreeGitDeleted',
FileDirty = 'GitDirty',
FileNew = 'GitNew',
FileRenamed = 'GitRenamed',
FileMerge = 'GitMerge',
FileStaged = 'GitStaged',
FileDeleted = 'GitDeleted',
}
end

View File

@ -4,7 +4,6 @@ local M = {}
M.config = {
name = "NvimTree",
filetype = "NvimTree"
}
local function is_open()
@ -31,7 +30,7 @@ function M.open()
else
bufnr = a.nvim_create_buf(false, true)
a.nvim_buf_set_name(bufnr, M.config.name)
vim.bo[bufnr].filetype = M.config.filetype
vim.bo[bufnr].filetype = M.config.name
vim.bo[bufnr].modifiable = false
vim.bo[bufnr].swapfile = false
end
@ -64,10 +63,10 @@ function M.render(lines, highlights)
a.nvim_buf_clear_namespace(bufnr, ns_id)
for _, hl in ipairs(highlights) do
a.nvim_buf_set_extmark(bufnr, ns_id, hl.line, hl.col, {
end_line = hl.line,
end_col = hl.end_col,
hl_group = hl.group
})
end_line = hl.line,
end_col = hl.end_col,
hl_group = hl.group
})
end
vim.bo[bufnr].modifiable = false

84
lua/nvim-tree/colors.lua Normal file
View File

@ -0,0 +1,84 @@
local a = vim.api
local function get_color_from_hl(hl_name, fallback)
local id = a.nvim_get_hl_id_by_name(hl_name)
if not id then return fallback end
local hl = a.nvim_get_hl_by_id(id, true)
if not hl or not hl.foreground then return fallback end
return hl.foreground
end
local function get_colors()
return {
red = vim.g.terminal_color_1 or get_color_from_hl('Keyword', '#a02030'),
green = vim.g.terminal_color_2 or get_color_from_hl('Character', '#20a033'),
yellow = vim.g.terminal_color_3 or get_color_from_hl('PreProc', '#aca040'),
blue = vim.g.terminal_color_4 or get_color_from_hl('Include', '#4030d0'),
purple = vim.g.terminal_color_5 or get_color_from_hl('Define', '#8040d0'),
cyan = vim.g.terminal_color_6 or get_color_from_hl('Conditional', '#74dfdb'),
dark_red = vim.g.terminal_color_9 or get_color_from_hl('Keyword', '#701920'),
orange = vim.g.terminal_color_11 or get_color_from_hl('Number', '#cc8c22'),
}
end
local function get_hl_groups()
local colors = get_colors()
return {
IndentMarker = { fg = '#8094b4' },
Symlink = { gui = 'bold', fg = colors.cyan },
FolderIcon = { fg = '#8094b4' },
RootFolder = { fg = colors.purple },
ExecFile = { gui = 'bold', fg = colors.green },
SpecialFile = { gui = 'bold,underline', fg = colors.yellow },
ImageFile = { gui = 'bold', fg = colors.purple },
GitDirty = { fg = colors.dark_red },
GitDeleted = { fg = colors.dark_red },
GitStaged = { fg = colors.green },
GitMerge = { fg = colors.orange },
GitRenamed = { fg = colors.purple },
GitNew = { fg = colors.yellow }
}
end
local function get_links()
return {
FolderName = 'Directory',
Normal = 'Normal',
EndOfBuffer = 'EndOfBuffer',
CursorLine = 'CursorLine',
VertSplit = 'VertSplit',
CursorColumn = 'CursorColumn',
FileDirty = 'GitDirty',
FileNew = 'GitNew',
FileRenamed = 'GitRenamed',
FileMerge = 'GitMerge',
FileStaged = 'GitStaged',
FileDeleted = 'GitDeleted',
}
end
return {
setup = function(opts)
if opts and opts.web_devicons.show == true then
require'nvim-web-devicons'.setup()
end
local higlight_groups = get_hl_groups()
for k, d in pairs(higlight_groups) do
local gui = d.gui or 'NONE'
vim.cmd('hi def NvimTree'..k..' gui='..gui..' guifg='..d.fg)
end
local links = get_links()
for k, d in pairs(links) do
vim.cmd('hi def link NvimTree'..k..' '..d)
end
vim.cmd "au! Colorscheme * lua require'nvim-tree.colors'.setup()"
end
}

View File

@ -34,12 +34,10 @@ M.config = {
opened = ""
}
},
others = {
symlink_icon = "",
web_devicons = {
show = true,
icons = {
default = "",
symlink = ""
}
default = true, -- true || false || replacement str
},
keybindings = {
["<CR>"] = ":lua require'nvim-tree'.open_file()<CR>",
@ -63,16 +61,12 @@ M.config = {
function M.setup(opts)
M.config = vim.tbl_deep_extend("keep", opts or {}, M.config)
require'nvim-tree.git'.configure(M.config.git)
require'nvim-tree.buffers.tree'.configure {
keybindings = M.config.keybindings,
width = M.config.width,
side = M.config.side,
auto_close = M.config.auto_close
}
require'nvim-tree.git'.configure(M.config)
require'nvim-tree.colors'.configure(M.config)
require'nvim-tree.buffers.tree'.configure(M.config)
if M.config.auto_open then
require'nvim-tree.buffers.tree'.open()
require'nvim-tree'.open()
end
end

View File

@ -11,10 +11,6 @@ hi def link LuaTreePopup Normal
augroup LuaTree
au BufWritePost * lua require'tree'.refresh()
au BufEnter * lua require'tree'.buf_enter()
if get(g:, 'lua_tree_auto_close') == 1
au WinClosed * lua require'tree'.on_leave()
endif
au ColorScheme * lua require'tree'.reset_highlight()
au User FugitiveChanged lua require'tree'.refresh()
if get(g:, 'lua_tree_tab_open') == 1
au TabEnter * lua require'tree'.tab_change()