Merge pull request #68 from kyazdani42/refacto/git-status-display

refacto display and add LuaTreeFolderDirty group
This commit is contained in:
Kiyan Yazdani 2020-08-03 12:15:59 +02:00 committed by GitHub
commit 194e73f519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 23 deletions

View File

@ -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,
@ -72,13 +73,13 @@ let g:lua_tree_icons = {
\ 'git': {
\ 'unstaged': "✗",
\ 'staged': "✓",
\ 'unmerged': "",
\ 'unmerged': "",
\ 'renamed': "➜",
\ 'untracked': "★"
\ },
\ 'folder': {
\ 'default': "",
\ 'open': ""
\ 'default': "",
\ 'open': ""
\ }
\ }
@ -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

View File

@ -95,12 +95,22 @@ 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*
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
@ -262,5 +272,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:

View File

@ -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*

View File

@ -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 },
@ -104,7 +104,12 @@ local function get_links()
EndOfBuffer = 'EndOfBuffer',
CursorLine = 'CursorLine',
VertSplit = 'VertSplit',
CursorColumn = 'CursorColumn'
CursorColumn = 'CursorColumn',
FileDirty = 'LuaTreeGitDirty',
FileNew = 'LuaTreeGitNew',
FileRenamed = 'LuaTreeGitRenamed',
FileMerge = 'LuaTreeGitMerge',
FileStaged = 'LuaTreeGitStaged',
}
end

View File

@ -7,13 +7,13 @@ function M.get_icon_state()
git_icons = {
unstaged = "",
staged = "",
unmerged = "",
unmerged = "",
renamed = "",
untracked = ""
},
folder_icons = {
default = "",
open = ""
default = "",
open = ""
}
}

View File

@ -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

View File

@ -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
@ -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,19 +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+#node.name, #icon+1)
set_folder_hl(index, offset, #icon, #node.name)
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..node.name.." "..git_icon)
table.insert(lines, padding..icon..git_icon..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_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
@ -166,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