Merge pull request #9 from kyazdani42/fix-add-ft-and-colors
Add colorscheme update and add filetype to buffer.
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
local api = vim.api
|
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 M = {}
|
||||||
|
|
||||||
local HIGHLIGHTS = {
|
local function create_hl()
|
||||||
|
return {
|
||||||
Symlink = { gui = 'bold', fg = colors.cyan },
|
Symlink = { gui = 'bold', fg = colors.cyan },
|
||||||
FolderName = { gui = 'bold', fg = colors.blue },
|
FolderName = { gui = 'bold', fg = colors.blue },
|
||||||
FolderIcon = { fg = '#90a4ae' },
|
FolderIcon = { fg = '#90a4ae' },
|
||||||
@@ -34,7 +37,10 @@ local HIGHLIGHTS = {
|
|||||||
GitMerge = { fg = colors.orange },
|
GitMerge = { fg = colors.orange },
|
||||||
GitRenamed = { fg = colors.purple },
|
GitRenamed = { fg = colors.purple },
|
||||||
GitNew = { fg = colors.yellow }
|
GitNew = { fg = colors.yellow }
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local HIGHLIGHTS = create_hl()
|
||||||
|
|
||||||
local LINKS = {
|
local LINKS = {
|
||||||
Normal = 'Normal',
|
Normal = 'Normal',
|
||||||
@@ -45,6 +51,9 @@ local LINKS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function M.init_colors()
|
function M.init_colors()
|
||||||
|
colors = get_colors()
|
||||||
|
print(vim.inspect(colors))
|
||||||
|
HIGHLIGHTS = create_hl()
|
||||||
for k, d in pairs(HIGHLIGHTS) do
|
for k, d in pairs(HIGHLIGHTS) do
|
||||||
local gui = d.gui or 'NONE'
|
local gui = d.gui or 'NONE'
|
||||||
api.nvim_command('hi def LuaTree'..k..' gui='..gui..' guifg='..d.fg)
|
api.nvim_command('hi def LuaTree'..k..' gui='..gui..' guifg='..d.fg)
|
||||||
|
|||||||
@@ -10,6 +10,16 @@ local function get(var, fallback)
|
|||||||
end
|
end
|
||||||
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 HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
|
||||||
|
|
||||||
local show_icons = get('lua_tree_show_icons', { git = 1, folders = 1, files = 1 })
|
local show_icons = get('lua_tree_show_icons', { git = 1, folders = 1, files = 1 })
|
||||||
@@ -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_FOLDER_ICON = show_icons.folders == 1
|
||||||
M.SHOW_GIT_ICON = show_icons.git == 1
|
M.SHOW_GIT_ICON = show_icons.git == 1
|
||||||
|
|
||||||
M.colors = {
|
function M.get_colors()
|
||||||
red = get('terminal_color_1', 'Red'),
|
return {
|
||||||
green = get('terminal_color_2', 'Green'),
|
red = get('terminal_color_1', get_color_from_hl('Keyword', 'Red')),
|
||||||
yellow = get('terminal_color_3', 'Yellow'),
|
green = get('terminal_color_2', get_color_from_hl('Character', 'Green')),
|
||||||
blue = get('terminal_color_4', 'Blue'),
|
yellow = get('terminal_color_3', get_color_from_hl('PreProc', 'Yellow')),
|
||||||
purple = get('terminal_color_5', 'Purple'),
|
blue = get('terminal_color_4', get_color_from_hl('Include', 'Blue')),
|
||||||
cyan = get('terminal_color_6', 'Cyan'),
|
purple = get('terminal_color_5', get_color_from_hl('Define', 'Purple')),
|
||||||
orange = get('terminal_color_11', 'Orange'),
|
cyan = get('terminal_color_6', get_color_from_hl('Conditional', 'Cyan')),
|
||||||
dark_red = get('terminal_color_9', 'DarkRed'),
|
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', {});
|
local keybindings = get('lua_tree_bindings', {});
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ function M.open()
|
|||||||
|
|
||||||
local buf = api.nvim_create_buf(false, true)
|
local buf = api.nvim_create_buf(false, true)
|
||||||
api.nvim_buf_set_name(buf, M.BUF_NAME)
|
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
|
for opt, val in pairs(options) do
|
||||||
api.nvim_buf_set_option(buf, opt, val)
|
api.nvim_buf_set_option(buf, opt, val)
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ local git = require 'lib/git'
|
|||||||
local refresh_git = git.refresh_git
|
local refresh_git = git.refresh_git
|
||||||
local force_refresh_git = git.force_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 = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -183,4 +184,9 @@ function M.find()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.reset_highlight()
|
||||||
|
colors.init_colors()
|
||||||
|
update_view()
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -8,19 +8,23 @@ let g:loaded_netrwPlugin = 1
|
|||||||
|
|
||||||
hi def link LuaTreePopup Normal
|
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()
|
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()
|
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
|
au BufEnter * :LuaTreeFindFile
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
au ColorScheme * lua require'tree'.reset_highlight()
|
||||||
|
augroup end
|
||||||
|
|
||||||
" TODO: WinEnter is not the right autocommand for this task,
|
" TODO: WinEnter is not the right autocommand for this task,
|
||||||
" but we do not have LayoutChange or WinMove kind of option atm,
|
" but we do not have LayoutChange or WinMove kind of option atm,
|
||||||
|
|||||||
Reference in New Issue
Block a user