Add colorscheme update and add filetype to buffer.

This commit is contained in:
kiyan42 2020-05-17 18:21:03 +02:00
parent 52d1d7e401
commit 020db73532
5 changed files with 80 additions and 48 deletions

View File

@ -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' },
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 },
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 },
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 }
}
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',
@ -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)

View File

@ -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 })
@ -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', {});

View File

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

View File

@ -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 = {}
@ -183,4 +184,9 @@ function M.find()
end
function M.reset_highlight()
colors.init_colors()
update_view()
end
return M

View File

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