1
1
local devicons_ok , devicons = pcall (require , " nvim-web-devicons" )
2
2
local log = require (" leetcode.logger" )
3
3
local config = require (" leetcode.config" )
4
+ local default = require (" leetcode.theme.default" )
4
5
5
6
--- @class lc.Theme
6
- local theme = {}
7
+ local Theme = {}
7
8
8
9
--- @type table<string , string[]>
9
10
local dynamic_hls = {}
10
11
12
+ -- by default tags use `normal` theme
11
13
local highlights = {
12
14
strong = " bold" ,
13
15
b = " bold" ,
@@ -40,7 +42,7 @@ local highlights = {
40
42
-- div = "",
41
43
}
42
44
43
- function theme .load_devicons ()
45
+ function Theme .load_devicons ()
44
46
--- @param l lc.language
45
47
vim .tbl_map (function (l )
46
48
local icon , color = devicons .get_icon_color (l .ft )
@@ -56,16 +58,16 @@ function theme.load_devicons()
56
58
end , config .langs )
57
59
end
58
60
59
- function theme .load ()
60
- local defaults = require ( " leetcode.theme.default " ) .get ()
61
+ function Theme .load ()
62
+ config . theme = vim . tbl_extend ( " force " , default .get (), config . user . theme )
61
63
62
- for key , t in pairs (defaults ) do
64
+ for key , t in pairs (config . theme ) do
63
65
key = " leetcode_" .. key
64
66
vim .api .nvim_set_hl (0 , key , t )
65
67
end
66
68
67
69
if devicons_ok then
68
- theme .load_devicons ()
70
+ Theme .load_devicons ()
69
71
end
70
72
71
73
--- @param lang lc.language
@@ -77,17 +79,17 @@ function theme.load()
77
79
return lang
78
80
end , config .langs )
79
81
80
- theme .load_dynamic (defaults )
82
+ Theme .load_dynamic ()
81
83
end
82
84
83
- function theme .load_dynamic (defaults )
85
+ function Theme .load_dynamic ()
84
86
for name , tags in pairs (dynamic_hls ) do
85
- theme .create_dynamic (name , tags , defaults )
87
+ Theme .create_dynamic (name , tags )
86
88
end
87
89
end
88
90
89
91
--- @param tags string[]
90
- function theme .get_dynamic (tags )
92
+ function Theme .get_dynamic (tags )
91
93
if vim .tbl_isempty (tags ) then
92
94
return " leetcode_normal"
93
95
end
@@ -97,26 +99,25 @@ function theme.get_dynamic(tags)
97
99
return name
98
100
end
99
101
100
- return theme .create_dynamic (name , tags )
102
+ return Theme .create_dynamic (name , tags )
101
103
end
102
104
103
105
--- @param name string
104
106
--- @param tags string[]
105
- --- @param defaults ? table
106
- function theme .create_dynamic (name , tags , defaults )
107
- defaults = defaults or require (" leetcode.theme.default" ).get ()
107
+ function Theme .create_dynamic (name , tags )
108
+ local theme = config .theme
108
109
109
- local tbl = defaults [" normal" ]
110
+ local tbl = theme [" normal" ]
110
111
for _ , tag in ipairs (tags ) do
111
112
local hl = highlights [tag ]
112
113
if hl then
113
- tbl = vim .tbl_extend (" force" , tbl , defaults [hl ])
114
+ tbl = vim .tbl_extend (" force" , tbl , theme [hl ])
114
115
end
115
116
end
116
117
117
118
if tbl .italic or tbl .bold then
118
- if tbl .fg == defaults [" normal" ].fg then
119
- tbl .fg = defaults [" " ].fg
119
+ if tbl .fg == theme [" normal" ].fg then
120
+ tbl .fg = theme [" " ].fg
120
121
end
121
122
end
122
123
@@ -128,14 +129,14 @@ function theme.create_dynamic(name, tags, defaults)
128
129
end
129
130
end
130
131
131
- function theme .setup ()
132
+ function Theme .setup ()
132
133
vim .api .nvim_create_autocmd (" ColorScheme" , {
133
134
group = vim .api .nvim_create_augroup (" lc.colorscheme_sync" , {}),
134
135
desc = " Colorscheme Synchronizer" ,
135
- callback = theme .load ,
136
+ callback = Theme .load ,
136
137
})
137
138
138
- theme .load ()
139
+ Theme .load ()
139
140
end
140
141
141
- return theme
142
+ return Theme
0 commit comments