1
1
local api = vim .api
2
- local get_colors = require ' lib/config' .get_colors
3
2
4
- local colors = get_colors ()
3
+ local function get_color_from_hl (hl_name , fallback )
4
+ local id = vim .api .nvim_get_hl_id_by_name (hl_name )
5
+ if not id then return fallback end
5
6
6
- local M = {}
7
+ local hl = vim .api .nvim_get_hl_by_id (id , true )
8
+ if not hl or not hl .foreground then return fallback end
9
+
10
+ return hl .foreground
11
+ end
12
+
13
+ local function get_colors ()
14
+ return {
15
+ red = vim .g .terminal_color_1 or get_color_from_hl (' Keyword' , ' Red' ),
16
+ green = vim .g .terminal_color_2 or get_color_from_hl (' Character' , ' Green' ),
17
+ yellow = vim .g .terminal_color_3 or get_color_from_hl (' PreProc' , ' Yellow' ),
18
+ blue = vim .g .terminal_color_4 or get_color_from_hl (' Include' , ' Blue' ),
19
+ purple = vim .g .terminal_color_5 or get_color_from_hl (' Define' , ' Purple' ),
20
+ cyan = vim .g .terminal_color_6 or get_color_from_hl (' Conditional' , ' Cyan' ),
21
+ dark_red = vim .g .terminal_color_9 or get_color_from_hl (' Keyword' , ' DarkRed' ),
22
+ orange = vim .g .terminal_color_11 or get_color_from_hl (' Number' , ' Orange' ),
23
+ }
24
+ end
25
+
26
+ local function get_hl_groups ()
27
+ local colors = get_colors ()
7
28
8
- local function create_hl ()
9
29
return {
10
30
Symlink = { gui = ' bold' , fg = colors .cyan },
11
31
FolderName = { gui = ' bold' , fg = colors .blue },
@@ -22,6 +42,7 @@ local function create_hl()
22
42
JsonIcon = { fg = colors .yellow },
23
43
24
44
LuaIcon = { fg = ' #42a5f5' },
45
+ GoIcon = { fg = ' #7Fd5EA' },
25
46
PythonIcon = { fg = colors .green },
26
47
ShellIcon = { fg = colors .green },
27
48
JavascriptIcon = { fg = colors .yellow },
@@ -40,25 +61,52 @@ local function create_hl()
40
61
}
41
62
end
42
63
43
- local HIGHLIGHTS = create_hl ()
64
+ local function get_links ()
65
+ return {
66
+ Normal = ' Normal' ,
67
+ EndOfBuffer = ' EndOfBuffer' ,
68
+ CursorLine = ' CursorLine' ,
69
+ VertSplit = ' VertSplit' ,
70
+ CursorColumn = ' CursorColumn'
71
+ }
72
+ end
73
+
74
+ local M = {}
44
75
45
- local LINKS = {
46
- Normal = ' Normal' ,
47
- EndOfBuffer = ' EndOfBuffer' ,
48
- CursorLine = ' CursorLine' ,
49
- VertSplit = ' VertSplit' ,
50
- CursorColumn = ' CursorColumn'
76
+ M .ft_to_hl_group = {
77
+ [' ^LICENSE$' ] = ' LicenseIcon' ;
78
+ [' ^%.?vimrc$' ] = ' VimIcon' ;
79
+ [' %.vim$' ] = ' VimIcon' ;
80
+ [' %.c$' ] = ' CIcon' ;
81
+ [' %.cpp$' ] = ' CIcon' ;
82
+ [' %.cxx$' ] = ' CIcon' ;
83
+ [' %.h$' ] = ' CIcon' ;
84
+ [' %.hpp$' ] = ' CIcon' ;
85
+ [' %.py$' ] = ' PythonIcon' ;
86
+ [' %.lua$' ] = ' LuaIcon' ;
87
+ [' %.rs$' ] = ' RustIcon' ;
88
+ [' %.[cz]?sh$' ] = ' ShellIcon' ;
89
+ [' %.md$' ] = ' MarkdownIcon' ;
90
+ [' %.json$' ] = ' JsonIcon' ;
91
+ [' %.toml$' ] = ' TomlIcon' ;
92
+ [' %.go$' ] = ' GoIcon' ;
93
+ [' %.yml$' ] = ' YamlIcon' ;
94
+ [' %.gitignore$' ] = ' GitignoreIcon' ;
95
+ [' %.js$' ] = ' JavascriptIcon' ;
96
+ [' %.ts$' ] = ' TypescriptIcon' ;
97
+ [' %.[tj]sx$' ] = ' ReactIcon' ;
98
+ [' %.html?$' ] = ' HtmlIcon' ;
51
99
}
52
100
53
- function M .init_colors ()
54
- colors = get_colors ()
55
- HIGHLIGHTS = create_hl ()
56
- for k , d in pairs (HIGHLIGHTS ) do
101
+ function M .setup ()
102
+ local higlight_groups = get_hl_groups ()
103
+ for k , d in pairs (higlight_groups ) do
57
104
local gui = d .gui or ' NONE'
58
105
api .nvim_command (' hi def LuaTree' .. k .. ' gui=' .. gui .. ' guifg=' .. d .fg )
59
106
end
60
107
61
- for k , d in pairs (LINKS ) do
108
+ local links = get_links ()
109
+ for k , d in pairs (links ) do
62
110
api .nvim_command (' hi def link LuaTree' .. k .. ' ' .. d )
63
111
end
64
112
end
0 commit comments