refactoring to use config options from lua module

This commit is contained in:
kiyan42 2020-03-04 14:58:37 +01:00
parent 0b4c9d8143
commit a33622179d
5 changed files with 44 additions and 47 deletions

View File

@ -66,7 +66,6 @@ nnoremap <leader>n :LuaTreeFindFile<CR>
- Tree creation should be async
- refactor all `system` call to `libuv` functions, with better error management
- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open
- make config module to make it easier to add/modify user options
### Features
- sneak like cd command to find a file/directory

View File

@ -1,24 +1,7 @@
local colors = require 'lib/config'.colors
local cmd = vim.api.nvim_command
local function get(var, fallback)
if vim.api.nvim_call_function('exists', { var }) == 1 then
return vim.api.nvim_get_var(var)
else
return fallback
end
end
local 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'),
}
local HIGHLIGHTS = {
Symlink = { gui = 'bold', fg = colors.cyan },
FolderName = { gui = 'bold', fg = colors.blue },

33
lua/lib/config.lua Normal file
View File

@ -0,0 +1,33 @@
local api = vim.api
local function get(var, fallback)
if vim.api.nvim_call_function('exists', { var }) == 1 then
return vim.api.nvim_get_var(var)
else
return fallback
end
end
local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
local SHOW_FOLDER_ICON = get('lua_tree_show_folders', 1) == 1
local SHOW_GIT_ICON = get('lua_tree_show_git_icons', 1) == 1
local 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'),
}
return {
SHOW_FOLDER_ICON = SHOW_FOLDER_ICON,
HAS_DEV_ICONS = HAS_DEV_ICONS,
SHOW_GIT_ICON = SHOW_GIT_ICON,
colors = colors
}

View File

@ -1,17 +1,7 @@
local config = require 'lib/config'
local api = vim.api
local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
local function get(var, fallback)
if api.nvim_call_function('exists', { 'g:'..var }) == 1 then
return api.nvim_get_var(var)
else
return fallback
end
end
local SHOW_FOLDER_ICON = get('lua_tree_show_folders', 1) == 1
local function get_padding(depth)
local str = ""
@ -24,7 +14,7 @@ local function get_padding(depth)
end
local function default_icons(_, isdir, open)
if isdir == true and SHOW_FOLDER_ICON then
if isdir == true and config.SHOW_FOLDER_ICON then
if open == true then return "" end
return ""
end
@ -69,7 +59,7 @@ local function dev_icons(pathname, isdir, open)
end
local function get_icon_func_gen()
if HAS_DEV_ICONS then
if config.HAS_DEV_ICONS then
return dev_icons
else
return default_icons
@ -132,7 +122,7 @@ local function highlight_line(buffer)
highlight('LuaTreeFolderName', line, 0, -1)
elseif node.dir == true then
if SHOW_FOLDER_ICON then
if config.SHOW_FOLDER_ICON then
text_start = text_start + 4
highlight('LuaTreeFolderIcon', line, 0, text_start)
end
@ -150,7 +140,7 @@ local function highlight_line(buffer)
elseif is_pic(node.path .. node.name) then
highlight('LuaTreeImageFile', line, text_start + gitlen, -1)
elseif HAS_DEV_ICONS then
elseif config.HAS_DEV_ICONS then
for k, v in pairs(HIGHLIGHT_GROUPS) do
if string.match(node.name, k) ~= nil then
text_start = text_start + 4

View File

@ -1,3 +1,5 @@
local config = require 'lib/config'
local function system(v) return vim.api.nvim_call_function('system', { v }) end
local function systemlist(v) return vim.api.nvim_call_function('systemlist', { v }) end
@ -51,18 +53,8 @@ local unmerged = create_git_checker('^[U ][U ]')
local renamed = create_git_checker('^R')
local untracked = create_git_checker('^%?%?')
local function get(var, fallback)
if vim.api.nvim_call_function('exists', { 'g:'..var }) == 1 then
return vim.api.nvim_get_var(var)
else
return fallback
end
end
local SHOW_GIT_ICON = get('lua_tree_show_git_icons', 1) == 1
local function get_git_attr(path, is_dir)
if IS_GIT_REPO == false or not SHOW_GIT_ICON then return '' end
if IS_GIT_REPO == false or not config.SHOW_GIT_ICON then return '' end
if is_dir then
if is_folder_dirty(path) == true then return '' end
else