Skip to content

Commit a08ba52

Browse files
authored
Add ability to use strings when making dynamic themes (#1353)
1 parent 070cd91 commit a08ba52

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lua/lualine.lua

+14-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,20 @@ local function setup_theme()
246246
-- use the provided theme as-is
247247
return config.options.theme
248248
elseif type(theme_name) == 'function' then
249-
-- call function and use returned (dynamic) theme as-is
250-
return config.options.theme()
249+
-- call function and use returned (dyanmic) theme, either as-is or as a string
250+
local ok, dynamic_theme = pcall(theme_name)
251+
if ok and (type(dynamic_theme) == 'string') then
252+
local ok_string, theme = pcall(modules.loader.load_theme, dynamic_theme)
253+
if ok_string and theme then
254+
return theme
255+
end
256+
elseif ok and (type(dynamic_theme) == 'table') then
257+
return dynamic_theme
258+
else
259+
local error_message = 'Invalid theme type returned from function: ' .. type(dynamic_theme)
260+
notify_theme_error(error_message)
261+
return dynamic_theme
262+
end
251263
end
252264
if theme_name ~= 'auto' then
253265
notify_theme_error(theme_name)

0 commit comments

Comments
 (0)