11local devicons_ok , devicons = pcall (require , " nvim-web-devicons" )
22local log = require (" leetcode.logger" )
33local config = require (" leetcode.config" )
4+ local default = require (" leetcode.theme.default" )
45
56--- @class lc.Theme
6- local theme = {}
7+ local Theme = {}
78
89--- @type table<string , string[]>
910local dynamic_hls = {}
1011
12+ -- by default tags use `normal` theme
1113local highlights = {
1214 strong = " bold" ,
1315 b = " bold" ,
@@ -40,7 +42,7 @@ local highlights = {
4042 -- div = "",
4143}
4244
43- function theme .load_devicons ()
45+ function Theme .load_devicons ()
4446 --- @param l lc.language
4547 vim .tbl_map (function (l )
4648 local icon , color = devicons .get_icon_color (l .ft )
@@ -56,16 +58,16 @@ function theme.load_devicons()
5658 end , config .langs )
5759end
5860
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 )
6163
62- for key , t in pairs (defaults ) do
64+ for key , t in pairs (config . theme ) do
6365 key = " leetcode_" .. key
6466 vim .api .nvim_set_hl (0 , key , t )
6567 end
6668
6769 if devicons_ok then
68- theme .load_devicons ()
70+ Theme .load_devicons ()
6971 end
7072
7173 --- @param lang lc.language
@@ -77,17 +79,17 @@ function theme.load()
7779 return lang
7880 end , config .langs )
7981
80- theme .load_dynamic (defaults )
82+ Theme .load_dynamic ()
8183end
8284
83- function theme .load_dynamic (defaults )
85+ function Theme .load_dynamic ()
8486 for name , tags in pairs (dynamic_hls ) do
85- theme .create_dynamic (name , tags , defaults )
87+ Theme .create_dynamic (name , tags )
8688 end
8789end
8890
8991--- @param tags string[]
90- function theme .get_dynamic (tags )
92+ function Theme .get_dynamic (tags )
9193 if vim .tbl_isempty (tags ) then
9294 return " leetcode_normal"
9395 end
@@ -97,26 +99,25 @@ function theme.get_dynamic(tags)
9799 return name
98100 end
99101
100- return theme .create_dynamic (name , tags )
102+ return Theme .create_dynamic (name , tags )
101103end
102104
103105--- @param name string
104106--- @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
108109
109- local tbl = defaults [" normal" ]
110+ local tbl = theme [" normal" ]
110111 for _ , tag in ipairs (tags ) do
111112 local hl = highlights [tag ]
112113 if hl then
113- tbl = vim .tbl_extend (" force" , tbl , defaults [hl ])
114+ tbl = vim .tbl_extend (" force" , tbl , theme [hl ])
114115 end
115116 end
116117
117118 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
120121 end
121122 end
122123
@@ -128,14 +129,14 @@ function theme.create_dynamic(name, tags, defaults)
128129 end
129130end
130131
131- function theme .setup ()
132+ function Theme .setup ()
132133 vim .api .nvim_create_autocmd (" ColorScheme" , {
133134 group = vim .api .nvim_create_augroup (" lc.colorscheme_sync" , {}),
134135 desc = " Colorscheme Synchronizer" ,
135- callback = theme .load ,
136+ callback = Theme .load ,
136137 })
137138
138- theme .load ()
139+ Theme .load ()
139140end
140141
141- return theme
142+ return Theme
0 commit comments