Skip to content

Commit

Permalink
Add ability to use strings when making dynamic themes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshw1013 committed Dec 29, 2024
1 parent 2a5bae9 commit 160d9f9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lua/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,20 @@ local function setup_theme()
-- use the provided theme as-is
return config.options.theme
elseif type(theme_name) == 'function' then
-- call function and use returned (dynamic) theme as-is
return config.options.theme()
-- call function and use returned (dyanmic) theme, either as-is or as a string
local ok, dynamic_theme = pcall(theme_name)
if ok and (type(dynamic_theme) == 'string') then
local ok_string, theme = pcall(modules.loader.load_theme, dynamic_theme)
if ok_string and theme then
return theme
end
elseif ok and (type(dynamic_theme) == 'table') then
return dynamic_theme
else
local error_message = 'Invalid theme type returned from function: ' .. type(dynamic_theme)
notify_theme_error(error_message)
return dynamic_theme
end
end
if theme_name ~= 'auto' then
notify_theme_error(theme_name)
Expand Down

0 comments on commit 160d9f9

Please sign in to comment.