88--- @class astrotheme.lib.util
99local M = {}
1010
11+ M .live_reloading = false
12+
1113--- Reload a given theme
1214--- @param opts AstroThemeOpts
1315--- @param theme string
6163--- @param module string
6264--- @return AstroThemeHighlights ?
6365function M .get_module_highlights (colors , opts , module )
64- if opts . dev then package.loaded [module ] = nil end
66+ if M . live_reloading then package.loaded [module ] = nil end
6567 local file_avail , file = pcall (require , module )
6668 if type (file ) == " function" then file = file (colors , opts .style ) end
6769 if file_avail then
105107--- @return AstroThemePalette
106108function M .set_palettes (opts )
107109 local palette_name = " astrotheme.palettes." .. opts .palette
108- if opts . dev then package.loaded [palette_name ] = nil end
110+ if M . live_reloading then package.loaded [palette_name ] = nil end
109111 local palette = require (palette_name )
110112 palette = vim .tbl_deep_extend (" force" , palette , opts .palettes .global )
111113 palette = vim .tbl_deep_extend (" force" , palette , opts .palettes [opts .palette ])
@@ -123,24 +125,22 @@ function M.set_highlights(highlights)
123125end
124126
125127--- Enable live reloading of AstroTheme for development
126- --- @param opts AstroThemeOpts
127- function M .live_reloading (opts )
128- if opts .dev then
129- vim .api .nvim_create_augroup (" AstroTheme" , { clear = true })
130- vim .api .nvim_create_autocmd (" BufWritePost" , {
131- -- buffer = 0,
132- pattern = " *.lua" ,
133- group = " AstroTheme" ,
134- callback = function ()
135- local theme = vim .g .colors_name
136- if string.match (theme , " astro" ) then
137- local command = " :colorscheme " .. theme
138- vim .api .nvim_feedkeys (command , " t" , true )
139- vim .api .nvim_input " <CR>"
140- end
141- end ,
142- })
143- end
128+ function M .live_reload ()
129+ vim .api .nvim_create_autocmd (" BufWritePost" , {
130+ pattern = " */lua/astrotheme/**.lua" ,
131+ group = vim .api .nvim_create_augroup (" AstroThemeDev" , { clear = true }),
132+ callback = function ()
133+ local theme = vim .g .colors_name
134+ if string.match (theme , " astro" ) then vim .cmd .colorscheme (theme ) end
135+ end ,
136+ })
137+ M .live_reloading = true
138+ end
139+
140+ --- Disable live reloading of AstroTheme
141+ function M .live_reload_stop ()
142+ vim .api .nvim_del_augroup_by_name " AstroThemeDev"
143+ M .live_reloading = false
144144end
145145
146146--- Set terminal colors based on the currently loaded colors
0 commit comments