From c552a4f4f5bdf575bb868bf97018296bd51d921f Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Sat, 1 Aug 2020 12:51:56 +0200 Subject: [PATCH 1/3] refacto display and add LuaTreeFolderDirty group --- lua/lib/colors.lua | 3 ++- lua/lib/renderer.lua | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lua/lib/colors.lua b/lua/lib/colors.lua index 53d1c72b..85e0cc43 100644 --- a/lua/lib/colors.lua +++ b/lua/lib/colors.lua @@ -104,7 +104,8 @@ local function get_links() EndOfBuffer = 'EndOfBuffer', CursorLine = 'CursorLine', VertSplit = 'VertSplit', - CursorColumn = 'CursorColumn' + CursorColumn = 'CursorColumn', + FolderDirty = 'LuaTreeFolderName' } end diff --git a/lua/lib/renderer.lua b/lua/lib/renderer.lua index 3aa3e33e..6d92f359 100644 --- a/lua/lib/renderer.lua +++ b/lua/lib/renderer.lua @@ -11,8 +11,8 @@ local namespace_id = api.nvim_create_namespace('LuaTreeHighlights') local icon_state = config.get_icon_state() local get_folder_icon = function() return "" end -local set_folder_hl = function(line, depth, git_icon_len) - table.insert(hl, {'LuaTreeFolderName', line, depth+git_icon_len, -1}) +local set_folder_hl = function(line, depth, git_icon_len, hl_group) + table.insert(hl, {hl_group, line, depth+git_icon_len, -1}) end if icon_state.show_folder_icon then @@ -23,8 +23,8 @@ if icon_state.show_folder_icon then return icon_state.icons.folder_icons.default .. " " end end - set_folder_hl = function(line, depth, icon_len, name_len) - table.insert(hl, {'LuaTreeFolderName', line, depth+icon_len, depth+icon_len+name_len}) + set_folder_hl = function(line, depth, icon_len, name_len, hl_group) + table.insert(hl, {hl_group, line, depth+icon_len, depth+icon_len+name_len}) table.insert(hl, {'LuaTreeFolderIcon', line, depth, depth+icon_len}) end end @@ -140,14 +140,21 @@ local function update_draw_data(tree, depth, markers) end if node.entries then local icon = get_folder_icon(node.open) - local git_icon = get_git_icons(node, index, offset+#node.name, #icon+1) - set_folder_hl(index, offset, #icon, #node.name) + local git_icon = get_git_icons(node, index, offset, #icon+1) + local git_display + if git_icon and #git_icon ~= 0 then + git_display = " "..git_icon + set_folder_hl(index, offset, #icon+#git_display, #node.name, 'LuaTreeFolderDirty') + else + git_display = "" + set_folder_hl(index, offset, #icon, #node.name, 'LuaTreeFolderName') + end index = index + 1 if node.open then - table.insert(lines, padding..icon..node.name.." "..git_icon) + table.insert(lines, padding..icon..git_display..node.name) update_draw_data(node, depth + 2, markers) else - table.insert(lines, padding..icon..node.name.." "..git_icon) + table.insert(lines, padding..icon..git_display..node.name) end elseif node.link_to then table.insert(hl, { 'LuaTreeSymlink', index, offset, -1 }) From a25ac38db1e023cca0969aa0f0f0f418e5d58073 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Sun, 2 Aug 2020 11:34:43 +0200 Subject: [PATCH 2/3] add file highlight for git attributes and remove the space before the git icon --- README.md | 3 ++- doc/nvim-tree-lua.txt | 18 ++++++++++++- doc/tags | 3 +++ lua/lib/colors.lua | 6 ++++- lua/lib/populate.lua | 2 +- lua/lib/renderer.lua | 63 +++++++++++++++++++++++++++++++++++-------- 6 files changed, 80 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 989541d1..c543b3a5 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ let g:lua_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer let g:lua_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open +let g:lua_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons). let g:lua_tree_show_icons = { \ 'git': 1, \ 'folders': 0, @@ -130,7 +131,7 @@ The Netrw vim plugin is disabled, hence features like `gx` don't work accross yo - Syntax highlighting ([exa](https://github.com/ogham/exa) like) - Change directory with `.` - Add / Rename / delete files -- Git integration +- Git integration (icons and file highlight) - Indent markers - Mouse support - It's fast diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 70188361..a6f47ee4 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -100,7 +100,13 @@ when no icon is found for a file. \ 'untracked': "★" \ } \ } -< + +|g:lua_tree_git_hl| *g:lua_tree_git_hl* + +You can enable file highlight for git attributes by setting this property. +This can be used with or without the icons. + + |g:lua_tree_follow| *g:lua_tree_follow* Can be `0` or `1`. When `1`, will update the cursor to update to the correct @@ -231,6 +237,7 @@ LuaTreeImageFile LuaTreeMarkdownFile LuaTreeIndentMarker +<<<<<<< HEAD LuaTreeLicenseIcon LuaTreeYamlIcon LuaTreeTomlIcon @@ -262,5 +269,14 @@ CursorLine VertSplit CursorColumn +There are also links for file highlight with git properties +These all link to there Git equivalent + +LuaTreeFileDirty +LuaTreeFileStaged +LuaTreeFileMerge +LuaTreeFileNew +LuaTreeFileRenamed + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/doc/tags b/doc/tags index 4c8b1c24..e33d2b37 100644 --- a/doc/tags +++ b/doc/tags @@ -1,3 +1,4 @@ +:LuaTreeClipboard nvim-tree-lua.txt /*:LuaTreeClipboard* :LuaTreeClose nvim-tree-lua.txt /*:LuaTreeClose* :LuaTreeFindFile nvim-tree-lua.txt /*:LuaTreeFindFile* :LuaTreeOpen nvim-tree-lua.txt /*:LuaTreeOpen* @@ -6,7 +7,9 @@ g:lua_tree_auto_close nvim-tree-lua.txt /*g:lua_tree_auto_close* g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open* g:lua_tree_bindings nvim-tree-lua.txt /*g:lua_tree_bindings* +g:lua_tree_disable_keybindings nvim-tree-lua.txt /*g:lua_tree_disable_keybindings* g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow* +g:lua_tree_git_hl nvim-tree-lua.txt /*g:lua_tree_git_hl* g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons* g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore* g:lua_tree_indent_markers nvim-tree-lua.txt /*g:lua_tree_indent_markers* diff --git a/lua/lib/colors.lua b/lua/lib/colors.lua index 85e0cc43..597114d5 100644 --- a/lua/lib/colors.lua +++ b/lua/lib/colors.lua @@ -105,7 +105,11 @@ local function get_links() CursorLine = 'CursorLine', VertSplit = 'VertSplit', CursorColumn = 'CursorColumn', - FolderDirty = 'LuaTreeFolderName' + FileDirty = 'LuaTreeGitDirty', + FileNew = 'LuaTreeGitNew', + FileRenamed = 'LuaTreeGitRenamed', + FileMerge = 'LuaTreeGitMerge', + FileStaged = 'LuaTreeGitStaged', } end diff --git a/lua/lib/populate.lua b/lua/lib/populate.lua index 20c4904d..480096c7 100644 --- a/lua/lib/populate.lua +++ b/lua/lib/populate.lua @@ -196,7 +196,7 @@ function M.populate(entries, cwd) table.insert(entries, file) end - if not icon_config.show_git_icon then + if not icon_config.show_git_icon and vim.g.lua_tree_git_hl ~= 1 then return end diff --git a/lua/lib/renderer.lua b/lua/lib/renderer.lua index 6d92f359..670f84f8 100644 --- a/lua/lib/renderer.lua +++ b/lua/lib/renderer.lua @@ -49,6 +49,41 @@ if icon_state.show_file_icon then end local get_git_icons = function() return "" end +local get_git_hl = function() return end + +if vim.g.lua_tree_git_hl == 1 then + local git_hl = { + ["M "] = { { hl = "LuaTreeFileStaged" } }, + [" M"] = { { hl = "LuaTreeFileDirty" } }, + ["MM"] = { + { hl = "LuaTreeFileStaged" }, + { hl = "LuaTreeFileDirty" } + }, + ["A "] = { + { hl = "LuaTreeFileStaged" }, + { hl = "LuaTreeFileNew" } + }, + ["AM"] = { + { hl = "LuaTreeFileStaged" }, + { hl = "LuaTreeFileNew" }, + { hl = "LuaTreeFileDirty" } + }, + ["??"] = { { hl = "LuaTreeFileNew" } }, + ["R "] = { { hl = "LuaTreeFileRenamed" } }, + ["UU"] = { { hl = "LuaTreeFileMerge" } }, + dirty = { { hl = "LuaTreeFileDirty" } }, + } + get_git_hl = function(node) + local git_status = node.git_status + if not git_status then return end + + local icons = git_hl[git_status] + -- TODO: how would we determine hl color when multiple git status are active ? + return icons[1].hl + -- return icons[#icons].hl + end +end + if icon_state.show_git_icon then local git_icon_state = { ["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" } }, @@ -138,26 +173,27 @@ local function update_draw_data(tree, depth, markers) if depth > 0 then table.insert(hl, { 'LuaTreeIndentMarker', index, 0, offset }) end + + local git_hl = get_git_hl(node) + if node.entries then local icon = get_folder_icon(node.open) - local git_icon = get_git_icons(node, index, offset, #icon+1) - local git_display - if git_icon and #git_icon ~= 0 then - git_display = " "..git_icon - set_folder_hl(index, offset, #icon+#git_display, #node.name, 'LuaTreeFolderDirty') - else - git_display = "" - set_folder_hl(index, offset, #icon, #node.name, 'LuaTreeFolderName') + local git_icon = get_git_icons(node, index, offset, #icon+1) or "" + -- INFO: this is mandatory in order to keep gui attributes (bold/italics) + set_folder_hl(index, offset, #icon, #node.name+#git_icon, 'LuaTreeFolderName') + if git_hl then + set_folder_hl(index, offset, #icon, #node.name+#git_icon, git_hl) end index = index + 1 if node.open then - table.insert(lines, padding..icon..git_display..node.name) + table.insert(lines, padding..icon..git_icon..node.name) update_draw_data(node, depth + 2, markers) else - table.insert(lines, padding..icon..git_display..node.name) + table.insert(lines, padding..icon..git_icon..node.name) end elseif node.link_to then - table.insert(hl, { 'LuaTreeSymlink', index, offset, -1 }) + local link_hl = git_hl or 'LuaTreeSymlink' + table.insert(hl, { link_hl, index, offset, -1 }) table.insert(lines, padding..node.name.." ➛ "..node.link_to) index = index + 1 @@ -173,11 +209,16 @@ local function update_draw_data(tree, depth, markers) git_icons = get_git_icons(node, index, offset, #icon) end table.insert(lines, padding..icon..git_icons..node.name) + if node.executable then table.insert(hl, {'LuaTreeExecFile', index, offset+#icon+#git_icons, -1 }) elseif picture[node.extension] then table.insert(hl, {'LuaTreeImageFile', index, offset+#icon+#git_icons, -1 }) end + + if git_hl then + table.insert(hl, {git_hl, index, offset+#icon+#git_icons, -1 }) + end index = index + 1 end end From b72f0bfffd19681bff5f9708a5f6c122aa726d2d Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Mon, 3 Aug 2020 10:53:40 +0200 Subject: [PATCH 3/3] change folder icons, folder colors --- README.md | 6 +++--- doc/nvim-tree-lua.txt | 9 ++++++--- lua/lib/colors.lua | 4 ++-- lua/lib/config.lua | 6 +++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c543b3a5..e92791cc 100644 --- a/README.md +++ b/README.md @@ -73,13 +73,13 @@ let g:lua_tree_icons = { \ 'git': { \ 'unstaged': "✗", \ 'staged': "✓", - \ 'unmerged': "═", + \ 'unmerged': "", \ 'renamed': "➜", \ 'untracked': "★" \ }, \ 'folder': { - \ 'default': "", - \ 'open': "" + \ 'default': "", + \ 'open': "" \ } \ } diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index a6f47ee4..f0f4416e 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -95,10 +95,14 @@ when no icon is found for a file. \ 'git': { \ 'unstaged': "✗", \ 'staged': "✓", - \ 'unmerged': "═", + \ 'unmerged': "", \ 'renamed': "➜", \ 'untracked': "★" - \ } + \ }, + \ 'folder': { + \ 'default': "", + \ 'open': "" + \ } \ } |g:lua_tree_git_hl| *g:lua_tree_git_hl* @@ -237,7 +241,6 @@ LuaTreeImageFile LuaTreeMarkdownFile LuaTreeIndentMarker -<<<<<<< HEAD LuaTreeLicenseIcon LuaTreeYamlIcon LuaTreeTomlIcon diff --git a/lua/lib/colors.lua b/lua/lib/colors.lua index 597114d5..4295a541 100644 --- a/lua/lib/colors.lua +++ b/lua/lib/colors.lua @@ -29,9 +29,9 @@ local function get_hl_groups() local colors = get_colors() return { - IndentMarker = { fg = '#90a4ae' }, + IndentMarker = { fg = '#8094b4' }, Symlink = { gui = 'bold', fg = colors.cyan }, - FolderIcon = { fg = '#90a4ae' }, + FolderIcon = { fg = '#8094b4' }, ExecFile = { gui = 'bold', fg = colors.green }, SpecialFile = { gui = 'bold,underline', fg = colors.yellow }, diff --git a/lua/lib/config.lua b/lua/lib/config.lua index 1a48ab41..6284f95a 100644 --- a/lua/lib/config.lua +++ b/lua/lib/config.lua @@ -7,13 +7,13 @@ function M.get_icon_state() git_icons = { unstaged = "✗", staged = "✓", - unmerged = "═", + unmerged = "", renamed = "➜", untracked = "★" }, folder_icons = { - default = "", - open = "" + default = "", + open = "" } }