Skip to content

Commit

Permalink
Merge pull request nvim-tree#9 from kyazdani42/fix-add-ft-and-colors
Browse files Browse the repository at this point in the history
Add colorscheme update and add filetype to buffer.
  • Loading branch information
kyazdani42 committed May 17, 2020
2 parents 252ae3c + 27d8f33 commit 3adb8fb
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 51 deletions.
75 changes: 42 additions & 33 deletions lua/lib/colors.lua
@@ -1,40 +1,46 @@
local api = vim.api
local colors = require 'lib/config'.colors
local get_colors = require 'lib/config'.get_colors

local colors = get_colors()

local M = {}

local HIGHLIGHTS = {
Symlink = { gui = 'bold', fg = colors.cyan },
FolderName = { gui = 'bold', fg = colors.blue },
FolderIcon = { fg = '#90a4ae' },

ExecFile = { gui = 'bold', fg = colors.green },
SpecialFile = { gui = 'bold,underline', fg = colors.yellow },
ImageFile = { gui = 'bold', fg = colors.purple },
MarkdownFile = { fg = colors.purple },
LicenseIcon = { fg = colors.yellow },
YamlIcon = { fg = colors.yellow },
TomlIcon = { fg = colors.yellow },
GitignoreIcon = { fg = colors.yellow },
JsonIcon = { fg = colors.yellow },

LuaIcon = { fg = '#42a5f5' },
PythonIcon = { fg = colors.green },
ShellIcon = { fg = colors.green },
JavascriptIcon = { fg = colors.yellow },
CIcon = { fg = colors.blue },
ReactIcon = { fg = colors.cyan },
HtmlIcon = { fg = colors.orange },
RustIcon = { fg = colors.orange },
VimIcon = { fg = colors.green },
TypescriptIcon = { fg = colors.blue },

GitDirty = { fg = colors.dark_red },
GitStaged = { fg = colors.green },
GitMerge = { fg = colors.orange },
GitRenamed = { fg = colors.purple },
GitNew = { fg = colors.yellow }
}
local function create_hl()
return {
Symlink = { gui = 'bold', fg = colors.cyan },
FolderName = { gui = 'bold', fg = colors.blue },
FolderIcon = { fg = '#90a4ae' },

ExecFile = { gui = 'bold', fg = colors.green },
SpecialFile = { gui = 'bold,underline', fg = colors.yellow },
ImageFile = { gui = 'bold', fg = colors.purple },
MarkdownFile = { fg = colors.purple },
LicenseIcon = { fg = colors.yellow },
YamlIcon = { fg = colors.yellow },
TomlIcon = { fg = colors.yellow },
GitignoreIcon = { fg = colors.yellow },
JsonIcon = { fg = colors.yellow },

LuaIcon = { fg = '#42a5f5' },
PythonIcon = { fg = colors.green },
ShellIcon = { fg = colors.green },
JavascriptIcon = { fg = colors.yellow },
CIcon = { fg = colors.blue },
ReactIcon = { fg = colors.cyan },
HtmlIcon = { fg = colors.orange },
RustIcon = { fg = colors.orange },
VimIcon = { fg = colors.green },
TypescriptIcon = { fg = colors.blue },

GitDirty = { fg = colors.dark_red },
GitStaged = { fg = colors.green },
GitMerge = { fg = colors.orange },
GitRenamed = { fg = colors.purple },
GitNew = { fg = colors.yellow }
}
end

local HIGHLIGHTS = create_hl()

local LINKS = {
Normal = 'Normal',
Expand All @@ -45,6 +51,9 @@ local LINKS = {
}

function M.init_colors()
colors = get_colors()
print(vim.inspect(colors))
HIGHLIGHTS = create_hl()
for k, d in pairs(HIGHLIGHTS) do
local gui = d.gui or 'NONE'
api.nvim_command('hi def LuaTree'..k..' gui='..gui..' guifg='..d.fg)
Expand Down
32 changes: 22 additions & 10 deletions lua/lib/config.lua
Expand Up @@ -10,6 +10,16 @@ local function get(var, fallback)
end
end

local function get_color_from_hl(hl_name, fallback)
local id = api.nvim_get_hl_id_by_name(hl_name)
if not id then return fallback end

local hl = api.nvim_get_hl_by_id(id, true)
if not hl or not hl.foreground then return fallback end

return hl.foreground
end

local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1

local show_icons = get('lua_tree_show_icons', { git = 1, folders = 1, files = 1 })
Expand All @@ -18,16 +28,18 @@ M.SHOW_FILE_ICON = HAS_DEV_ICONS and show_icons.files == 1
M.SHOW_FOLDER_ICON = show_icons.folders == 1
M.SHOW_GIT_ICON = show_icons.git == 1

M.colors = {
red = get('terminal_color_1', 'Red'),
green = get('terminal_color_2', 'Green'),
yellow = get('terminal_color_3', 'Yellow'),
blue = get('terminal_color_4', 'Blue'),
purple = get('terminal_color_5', 'Purple'),
cyan = get('terminal_color_6', 'Cyan'),
orange = get('terminal_color_11', 'Orange'),
dark_red = get('terminal_color_9', 'DarkRed'),
}
function M.get_colors()
return {
red = get('terminal_color_1', get_color_from_hl('Keyword', 'Red')),
green = get('terminal_color_2', get_color_from_hl('Character', 'Green')),
yellow = get('terminal_color_3', get_color_from_hl('PreProc', 'Yellow')),
blue = get('terminal_color_4', get_color_from_hl('Include', 'Blue')),
purple = get('terminal_color_5', get_color_from_hl('Define', 'Purple')),
cyan = get('terminal_color_6', get_color_from_hl('Conditional', 'Cyan')),
orange = get('terminal_color_11', get_color_from_hl('Number', 'Orange')),
dark_red = get('terminal_color_9', get_color_from_hl('Keyword', 'DarkRed')),
}
end

local keybindings = get('lua_tree_bindings', {});

Expand Down
1 change: 1 addition & 0 deletions lua/lib/winutils.lua
Expand Up @@ -66,6 +66,7 @@ function M.open()

local buf = api.nvim_create_buf(false, true)
api.nvim_buf_set_name(buf, M.BUF_NAME)
api.nvim_buf_set_option(buf, 'filetype', M.BUF_NAME)

for opt, val in pairs(options) do
api.nvim_buf_set_option(buf, opt, val)
Expand Down
8 changes: 7 additions & 1 deletion lua/tree.lua
Expand Up @@ -30,7 +30,8 @@ local git = require 'lib/git'
local refresh_git = git.refresh_git
local force_refresh_git = git.force_refresh_git

require 'lib/colors'.init_colors()
local colors = require 'lib/colors'
colors.init_colors()

local M = {}

Expand Down Expand Up @@ -183,4 +184,9 @@ function M.find()

end

function M.reset_highlight()
colors.init_colors()
update_view()
end

return M
18 changes: 11 additions & 7 deletions plugin/tree.vim
Expand Up @@ -8,19 +8,23 @@ let g:loaded_netrwPlugin = 1

hi def link LuaTreePopup Normal

au BufWritePost * lua require'tree'.refresh()
augroup LuaTree
au BufWritePost * lua require'tree'.refresh()

if get(g:, 'lua_tree_auto_close') != 0
if get(g:, 'lua_tree_auto_close') != 0
au BufEnter * lua require'tree'.check_windows_and_close()
endif
endif

if get(g:, 'lua_tree_auto_open') != 0
if get(g:, 'lua_tree_auto_open') != 0
au VimEnter * lua require'tree'.check_buffer_and_open()
endif
endif

if get(g:, 'lua_tree_follow') != 0
if get(g:, 'lua_tree_follow') != 0
au BufEnter * :LuaTreeFindFile
endif
endif

au ColorScheme * lua require'tree'.reset_highlight()
augroup end

" TODO: WinEnter is not the right autocommand for this task,
" but we do not have LayoutChange or WinMove kind of option atm,
Expand Down

0 comments on commit 3adb8fb

Please sign in to comment.