@@ -2,12 +2,12 @@ local config = require("cyberdream.config")
2
2
local util = require (" cyberdream.util" )
3
3
4
4
local M = {}
5
- local cache_file = vim .fn .stdpath (" cache" ) .. " /cyberdream_cache.json"
5
+ local theme_cache_file = vim .fn .stdpath (" cache" ) .. " /cyberdream_cache.json"
6
6
7
7
--- build a cache file for a configured cyberdream theme
8
8
--- @param theme table
9
9
M .build = function (theme )
10
- local cache = io.open (cache_file , " w" )
10
+ local cache = io.open (theme_cache_file , " w" )
11
11
if not cache then
12
12
util .notify (" Failed to open cache file" , " error" )
13
13
return
@@ -20,15 +20,15 @@ M.build = function(theme)
20
20
end
21
21
end
22
22
23
- theme .fillchars = config .options .hide_fillchars
24
23
theme .terminal_colors = # terminal_colors > 0 and terminal_colors or nil
24
+ theme .config = config .options
25
25
26
26
cache :write (vim .json .encode (theme ))
27
- util .notify (" Cache file written to " .. cache_file )
27
+ util .notify (" Cache file written to " .. theme_cache_file )
28
28
end
29
29
30
30
M .load_options = function (theme )
31
- if theme .fillchars then
31
+ if theme .config . hide_fillchars then
32
32
vim .opt .fillchars :append ({
33
33
horiz = " " ,
34
34
horizup = " " ,
54
54
55
55
--- load a cache file for a configured cyberdream theme
56
56
M .load = function ()
57
- local cache = io.open (cache_file , " r" )
57
+ local cache = io.open (theme_cache_file , " r" )
58
58
if not cache then
59
59
M .build (require (" cyberdream.theme" ).setup ())
60
60
local notify = vim .defer_fn (function ()
@@ -69,12 +69,22 @@ M.load = function()
69
69
vim .api .nvim_set_hl (0 , group , opts )
70
70
end
71
71
72
+ -- check if config has changed
73
+ if not vim .deep_equal (theme .config , config .options ) then
74
+ M .build (require (" cyberdream.theme" ).setup ())
75
+ local notify = vim .defer_fn (function ()
76
+ util .notify (" Building cache...\n A restart may be required for changes to take effect." )
77
+ M .load ()
78
+ end , 1000 )
79
+ return notify
80
+ end
81
+
72
82
M .load_options (theme )
73
83
vim .g .colors_name = " cyberdream"
74
84
end
75
85
76
86
M .clear = function ()
77
- os.remove (cache_file )
87
+ os.remove (theme_cache_file )
78
88
util .notify (" Cache file removed" )
79
89
end
80
90
0 commit comments