Skip to content

Commit 55ad095

Browse files
authored
Merge pull request #9 from kyazdani42/fix-add-ft-and-colors
Add colorscheme update and add filetype to buffer.
2 parents 52d1d7e + 020db73 commit 55ad095

File tree

5 files changed

+83
-51
lines changed

5 files changed

+83
-51
lines changed

lua/lib/colors.lua

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
11
local api = vim.api
2-
local colors = require 'lib/config'.colors
2+
local get_colors = require 'lib/config'.get_colors
3+
4+
local colors = get_colors()
35

46
local M = {}
57

6-
local HIGHLIGHTS = {
7-
Symlink = { gui = 'bold', fg = colors.cyan },
8-
FolderName = { gui = 'bold', fg = colors.blue },
9-
FolderIcon = { fg = '#90a4ae' },
10-
11-
ExecFile = { gui = 'bold', fg = colors.green },
12-
SpecialFile = { gui = 'bold,underline', fg = colors.yellow },
13-
ImageFile = { gui = 'bold', fg = colors.purple },
14-
MarkdownFile = { fg = colors.purple },
15-
LicenseIcon = { fg = colors.yellow },
16-
YamlIcon = { fg = colors.yellow },
17-
TomlIcon = { fg = colors.yellow },
18-
GitignoreIcon = { fg = colors.yellow },
19-
JsonIcon = { fg = colors.yellow },
20-
21-
LuaIcon = { fg = '#42a5f5' },
22-
PythonIcon = { fg = colors.green },
23-
ShellIcon = { fg = colors.green },
24-
JavascriptIcon = { fg = colors.yellow },
25-
CIcon = { fg = colors.blue },
26-
ReactIcon = { fg = colors.cyan },
27-
HtmlIcon = { fg = colors.orange },
28-
RustIcon = { fg = colors.orange },
29-
VimIcon = { fg = colors.green },
30-
TypescriptIcon = { fg = colors.blue },
31-
32-
GitDirty = { fg = colors.dark_red },
33-
GitStaged = { fg = colors.green },
34-
GitMerge = { fg = colors.orange },
35-
GitRenamed = { fg = colors.purple },
36-
GitNew = { fg = colors.yellow }
37-
}
8+
local function create_hl()
9+
return {
10+
Symlink = { gui = 'bold', fg = colors.cyan },
11+
FolderName = { gui = 'bold', fg = colors.blue },
12+
FolderIcon = { fg = '#90a4ae' },
13+
14+
ExecFile = { gui = 'bold', fg = colors.green },
15+
SpecialFile = { gui = 'bold,underline', fg = colors.yellow },
16+
ImageFile = { gui = 'bold', fg = colors.purple },
17+
MarkdownFile = { fg = colors.purple },
18+
LicenseIcon = { fg = colors.yellow },
19+
YamlIcon = { fg = colors.yellow },
20+
TomlIcon = { fg = colors.yellow },
21+
GitignoreIcon = { fg = colors.yellow },
22+
JsonIcon = { fg = colors.yellow },
23+
24+
LuaIcon = { fg = '#42a5f5' },
25+
PythonIcon = { fg = colors.green },
26+
ShellIcon = { fg = colors.green },
27+
JavascriptIcon = { fg = colors.yellow },
28+
CIcon = { fg = colors.blue },
29+
ReactIcon = { fg = colors.cyan },
30+
HtmlIcon = { fg = colors.orange },
31+
RustIcon = { fg = colors.orange },
32+
VimIcon = { fg = colors.green },
33+
TypescriptIcon = { fg = colors.blue },
34+
35+
GitDirty = { fg = colors.dark_red },
36+
GitStaged = { fg = colors.green },
37+
GitMerge = { fg = colors.orange },
38+
GitRenamed = { fg = colors.purple },
39+
GitNew = { fg = colors.yellow }
40+
}
41+
end
42+
43+
local HIGHLIGHTS = create_hl()
3844

3945
local LINKS = {
4046
Normal = 'Normal',
@@ -45,6 +51,9 @@ local LINKS = {
4551
}
4652

4753
function M.init_colors()
54+
colors = get_colors()
55+
print(vim.inspect(colors))
56+
HIGHLIGHTS = create_hl()
4857
for k, d in pairs(HIGHLIGHTS) do
4958
local gui = d.gui or 'NONE'
5059
api.nvim_command('hi def LuaTree'..k..' gui='..gui..' guifg='..d.fg)

lua/lib/config.lua

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ local function get(var, fallback)
1010
end
1111
end
1212

13+
local function get_color_from_hl(hl_name, fallback)
14+
local id = api.nvim_get_hl_id_by_name(hl_name)
15+
if not id then return fallback end
16+
17+
local hl = api.nvim_get_hl_by_id(id, true)
18+
if not hl or not hl.foreground then return fallback end
19+
20+
return hl.foreground
21+
end
22+
1323
local HAS_DEV_ICONS = api.nvim_call_function('exists', { "*WebDevIconsGetFileTypeSymbol" }) == 1
1424

1525
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
1828
M.SHOW_FOLDER_ICON = show_icons.folders == 1
1929
M.SHOW_GIT_ICON = show_icons.git == 1
2030

21-
M.colors = {
22-
red = get('terminal_color_1', 'Red'),
23-
green = get('terminal_color_2', 'Green'),
24-
yellow = get('terminal_color_3', 'Yellow'),
25-
blue = get('terminal_color_4', 'Blue'),
26-
purple = get('terminal_color_5', 'Purple'),
27-
cyan = get('terminal_color_6', 'Cyan'),
28-
orange = get('terminal_color_11', 'Orange'),
29-
dark_red = get('terminal_color_9', 'DarkRed'),
30-
}
31+
function M.get_colors()
32+
return {
33+
red = get('terminal_color_1', get_color_from_hl('Keyword', 'Red')),
34+
green = get('terminal_color_2', get_color_from_hl('Character', 'Green')),
35+
yellow = get('terminal_color_3', get_color_from_hl('PreProc', 'Yellow')),
36+
blue = get('terminal_color_4', get_color_from_hl('Include', 'Blue')),
37+
purple = get('terminal_color_5', get_color_from_hl('Define', 'Purple')),
38+
cyan = get('terminal_color_6', get_color_from_hl('Conditional', 'Cyan')),
39+
orange = get('terminal_color_11', get_color_from_hl('Number', 'Orange')),
40+
dark_red = get('terminal_color_9', get_color_from_hl('Keyword', 'DarkRed')),
41+
}
42+
end
3143

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

lua/lib/winutils.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function M.open()
6666

6767
local buf = api.nvim_create_buf(false, true)
6868
api.nvim_buf_set_name(buf, M.BUF_NAME)
69+
api.nvim_buf_set_option(buf, 'filetype', M.BUF_NAME)
6970

7071
for opt, val in pairs(options) do
7172
api.nvim_buf_set_option(buf, opt, val)

lua/tree.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ local git = require 'lib/git'
3030
local refresh_git = git.refresh_git
3131
local force_refresh_git = git.force_refresh_git
3232

33-
require 'lib/colors'.init_colors()
33+
local colors = require 'lib/colors'
34+
colors.init_colors()
3435

3536
local M = {}
3637

@@ -183,4 +184,9 @@ function M.find()
183184

184185
end
185186

187+
function M.reset_highlight()
188+
colors.init_colors()
189+
update_view()
190+
end
191+
186192
return M

plugin/tree.vim

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ let g:loaded_netrwPlugin = 1
88

99
hi def link LuaTreePopup Normal
1010

11-
au BufWritePost * lua require'tree'.refresh()
11+
augroup LuaTree
12+
au BufWritePost * lua require'tree'.refresh()
1213

13-
if get(g:, 'lua_tree_auto_close') != 0
14+
if get(g:, 'lua_tree_auto_close') != 0
1415
au BufEnter * lua require'tree'.check_windows_and_close()
15-
endif
16+
endif
1617

17-
if get(g:, 'lua_tree_auto_open') != 0
18+
if get(g:, 'lua_tree_auto_open') != 0
1819
au VimEnter * lua require'tree'.check_buffer_and_open()
19-
endif
20+
endif
2021

21-
if get(g:, 'lua_tree_follow') != 0
22+
if get(g:, 'lua_tree_follow') != 0
2223
au BufEnter * :LuaTreeFindFile
23-
endif
24+
endif
25+
26+
au ColorScheme * lua require'tree'.reset_highlight()
27+
augroup end
2428

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

0 commit comments

Comments
 (0)