Skip to content

Commit a336221

Browse files
committed
refactoring to use config options from lua module
1 parent 0b4c9d8 commit a336221

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ nnoremap <leader>n :LuaTreeFindFile<CR>
6666
- Tree creation should be async
6767
- refactor all `system` call to `libuv` functions, with better error management
6868
- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open
69-
- make config module to make it easier to add/modify user options
7069

7170
### Features
7271
- sneak like cd command to find a file/directory

lua/lib/colors.lua

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
local cmd = vim.api.nvim_command
2-
3-
local function get(var, fallback)
4-
if vim.api.nvim_call_function('exists', { var }) == 1 then
5-
return vim.api.nvim_get_var(var)
6-
else
7-
return fallback
8-
end
9-
end
1+
local colors = require 'lib/config'.colors
102

11-
local colors = {
12-
red = get('terminal_color_1', 'Red'),
13-
green = get('terminal_color_2', 'Green'),
14-
yellow = get('terminal_color_3', 'Yellow'),
15-
blue = get('terminal_color_4', 'Blue'),
16-
purple = get('terminal_color_5', 'Purple'),
17-
cyan = get('terminal_color_6', 'Cyan'),
18-
orange = get('terminal_color_11', 'Orange'),
19-
dark_red = get('terminal_color_9', 'DarkRed'),
20-
}
3+
local cmd = vim.api.nvim_command
214

225
local HIGHLIGHTS = {
236
Symlink = { gui = 'bold', fg = colors.cyan },

lua/lib/config.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
local api = vim.api
2+
3+
local function get(var, fallback)
4+
if vim.api.nvim_call_function('exists', { var }) == 1 then
5+
return vim.api.nvim_get_var(var)
6+
else
7+
return fallback
8+
end
9+
end
10+
11+
local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
12+
13+
local SHOW_FOLDER_ICON = get('lua_tree_show_folders', 1) == 1
14+
15+
local SHOW_GIT_ICON = get('lua_tree_show_git_icons', 1) == 1
16+
17+
local colors = {
18+
red = get('terminal_color_1', 'Red'),
19+
green = get('terminal_color_2', 'Green'),
20+
yellow = get('terminal_color_3', 'Yellow'),
21+
blue = get('terminal_color_4', 'Blue'),
22+
purple = get('terminal_color_5', 'Purple'),
23+
cyan = get('terminal_color_6', 'Cyan'),
24+
orange = get('terminal_color_11', 'Orange'),
25+
dark_red = get('terminal_color_9', 'DarkRed'),
26+
}
27+
return {
28+
SHOW_FOLDER_ICON = SHOW_FOLDER_ICON,
29+
HAS_DEV_ICONS = HAS_DEV_ICONS,
30+
SHOW_GIT_ICON = SHOW_GIT_ICON,
31+
colors = colors
32+
}
33+

lua/lib/format.lua

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
local api = vim.api
2-
3-
local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
1+
local config = require 'lib/config'
42

5-
local function get(var, fallback)
6-
if api.nvim_call_function('exists', { 'g:'..var }) == 1 then
7-
return api.nvim_get_var(var)
8-
else
9-
return fallback
10-
end
11-
end
12-
13-
local SHOW_FOLDER_ICON = get('lua_tree_show_folders', 1) == 1
3+
local api = vim.api
144

155
local function get_padding(depth)
166
local str = ""
@@ -24,7 +14,7 @@ local function get_padding(depth)
2414
end
2515

2616
local function default_icons(_, isdir, open)
27-
if isdir == true and SHOW_FOLDER_ICON then
17+
if isdir == true and config.SHOW_FOLDER_ICON then
2818
if open == true then return "" end
2919
return ""
3020
end
@@ -69,7 +59,7 @@ local function dev_icons(pathname, isdir, open)
6959
end
7060

7161
local function get_icon_func_gen()
72-
if HAS_DEV_ICONS then
62+
if config.HAS_DEV_ICONS then
7363
return dev_icons
7464
else
7565
return default_icons
@@ -132,7 +122,7 @@ local function highlight_line(buffer)
132122
highlight('LuaTreeFolderName', line, 0, -1)
133123

134124
elseif node.dir == true then
135-
if SHOW_FOLDER_ICON then
125+
if config.SHOW_FOLDER_ICON then
136126
text_start = text_start + 4
137127
highlight('LuaTreeFolderIcon', line, 0, text_start)
138128
end
@@ -150,7 +140,7 @@ local function highlight_line(buffer)
150140
elseif is_pic(node.path .. node.name) then
151141
highlight('LuaTreeImageFile', line, text_start + gitlen, -1)
152142

153-
elseif HAS_DEV_ICONS then
143+
elseif config.HAS_DEV_ICONS then
154144
for k, v in pairs(HIGHLIGHT_GROUPS) do
155145
if string.match(node.name, k) ~= nil then
156146
text_start = text_start + 4

lua/lib/git.lua

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local config = require 'lib/config'
2+
13
local function system(v) return vim.api.nvim_call_function('system', { v }) end
24
local function systemlist(v) return vim.api.nvim_call_function('systemlist', { v }) end
35

@@ -51,18 +53,8 @@ local unmerged = create_git_checker('^[U ][U ]')
5153
local renamed = create_git_checker('^R')
5254
local untracked = create_git_checker('^%?%?')
5355

54-
local function get(var, fallback)
55-
if vim.api.nvim_call_function('exists', { 'g:'..var }) == 1 then
56-
return vim.api.nvim_get_var(var)
57-
else
58-
return fallback
59-
end
60-
end
61-
62-
local SHOW_GIT_ICON = get('lua_tree_show_git_icons', 1) == 1
63-
6456
local function get_git_attr(path, is_dir)
65-
if IS_GIT_REPO == false or not SHOW_GIT_ICON then return '' end
57+
if IS_GIT_REPO == false or not config.SHOW_GIT_ICON then return '' end
6658
if is_dir then
6759
if is_folder_dirty(path) == true then return '' end
6860
else

0 commit comments

Comments
 (0)