@@ -132,6 +132,7 @@ function M.with_config(config)
132132
133133 local supports = vim .tbl_extend (" force" , {
134134 tinty = true ,
135+ live_reload = false ,
135136 tinted_shell = false ,
136137 }, config .supports or M .config .supports or {})
137138 local highlights = vim .tbl_extend (" force" , {
@@ -152,100 +153,11 @@ function M.with_config(config)
152153 }
153154end
154155
155- --- Creates a tinted colorscheme using the colors specified.
156- --
157- -- Builtin colorschemes can be found in the M.colorschemes table.
158- --
159- -- The default Vim highlight groups (including User[1-9]), highlight groups
160- -- pertaining to Neovim's builtin LSP, and highlight groups pertaining to
161- -- Treesitter will be defined.
162- --
163- -- It's worth noting that many colorschemes will specify language specific
164- -- highlight groups like rubyConstant or pythonInclude. However, I don't do
165- -- that here since these should instead be linked to an existing highlight
166- -- group.
167- --
168- -- @param colors (table) table with keys 'base00', 'base01', 'base02',
169- -- 'base03', 'base04', 'base05', 'base06', 'base07', 'base08', 'base09',
170- -- 'base0A', 'base0B', 'base0C', 'base0D', 'base0E', 'base0F'. Each key should
171- -- map to a valid 6 digit hex color. If a string is provided, the
172- -- corresponding table specifying the colorscheme will be used.
173- function M .setup (colors , config )
174- M .with_config (config or {})
175-
176- local current_colorscheme_name = vim .g .tinted_current_colorscheme ;
177-
178- if type (' colors' ) == ' table' or colors == ' ' or colors == nil then
179- colors = M .colorschemes [" tinted-nvim-default" ]
180- elseif type (' colors' ) == ' string' then
181- -- Return if the theme is being set to the same theme
182- if colors == current_colorscheme_name then
183- return
184- end
185-
186- local ok , colorscheme = pcall (function ()
187- vim .g .tinted_current_colorscheme = colors
188- return M .colorschemes [colors ]
189- end )
190-
191- if ok then
192- colors = colorscheme
193- else
194- vim .g .tinted_current_colorscheme = " tinted-nvim-default"
195- colors = M .colorschemes [" tinted-nvim-default" ]
196- end
197- end
198-
199- if M .config .supports .tinty == true then
200- local current_tinty_theme = vim .trim (get_tinty_theme ())
201-
202- -- If the Tinty theme is not null
203- if current_tinty_theme ~= nil and current_tinty_theme ~= ' ' then
204- -- Set to Tinty theme if new theme name is different to already set
205- if current_tinty_theme ~= current_colorscheme_name then
206- -- Safely get colorscheme object from Tinty theme name
207- local ok , colorscheme = pcall (function ()
208- return M .colorschemes [current_tinty_theme ]
209- end )
210-
211- if ok then
212- vim .g .tinted_current_colorscheme = current_tinty_theme
213- vim .o .termguicolors = true
214- vim .g .tinted_colorspace = 256
215- colors = colorscheme
216- else
217- vim .notify (
218- string.format (" Failed to load Tinty colorscheme '%s', falling back to default" , current_tinty_theme ),
219- vim .log .levels .WARN
220- )
221- end
222- -- Return if the theme is being set to the same theme
223- else
224- return
225- end
226- else
227- vim .notify (
228- string.format (" Failed to load Tinty colorscheme '%s', falling back to default" , current_tinty_theme ),
229- vim .log .levels .WARN
230- )
231- end
232- -- Only trust BASE16_THEME if not inside a TMUX pane due to how TMUX handles env vars
233- elseif M .config .tinted_shell == true and vim .env .TMUX == nil and vim .env .BASE16_THEME ~= nil then
234- -- Safely get colorscheme object from BASE16_THEME env var
235- local ok , colorscheme = pcall (function ()
236- return M .colorschemes [vim .env .BASE16_THEME ]
237- end )
238-
239- if ok then
240- vim .g .tinted_current_colorscheme = vim .env .BASE16_THEME
241- colors = colorscheme
242- end
243- end
244-
245- if vim .fn .exists (' syntax_on' ) then
246- vim .cmd (' syntax reset' )
247- end
156+ local function trigger_autocmd ()
157+ vim .cmd ([[ doautocmd User TintedColorsPost]] )
158+ end
248159
160+ local function set_colors (colors )
249161 M .colors = colors
250162
251163 local hi = M .highlight
@@ -808,6 +720,123 @@ function M.setup(colors, config)
808720 vim .g .tinted_gui15 = M .colors .base15
809721 vim .g .tinted_gui16 = M .colors .base16
810722 vim .g .tinted_gui17 = M .colors .base17
723+
724+ trigger_autocmd ()
725+ end
726+
727+ local function detect_colors_from_tinty ()
728+ local current_tinty_theme = vim .trim (get_tinty_theme ())
729+
730+ -- If the Tinty theme is not null
731+ if current_tinty_theme ~= nil and current_tinty_theme ~= ' ' then
732+ -- Set to Tinty theme if new theme name is different to already set
733+ if current_tinty_theme ~= current_colorscheme_name then
734+ -- Safely get colorscheme object from Tinty theme name
735+ local ok , colorscheme = pcall (function ()
736+ return M .colorschemes [current_tinty_theme ]
737+ end )
738+
739+ if ok then
740+ vim .g .tinted_current_colorscheme = current_tinty_theme
741+ vim .o .termguicolors = true
742+ vim .g .tinted_colorspace = 256
743+ return colorscheme
744+ else
745+ vim .notify (
746+ string.format (" Failed to load Tinty colorscheme '%s', falling back to default" , current_tinty_theme ),
747+ vim .log .levels .WARN
748+ )
749+ end
750+ -- Return if the theme is being set to the same theme
751+ else
752+ return
753+ end
754+ else
755+ vim .notify (
756+ string.format (" Failed to load Tinty colorscheme '%s', falling back to default" , current_tinty_theme ),
757+ vim .log .levels .WARN
758+ )
759+ end
760+ end
761+
762+ --- Creates a tinted colorscheme using the colors specified.
763+ --
764+ -- Builtin colorschemes can be found in the M.colorschemes table.
765+ --
766+ -- The default Vim highlight groups (including User[1-9]), highlight groups
767+ -- pertaining to Neovim's builtin LSP, and highlight groups pertaining to
768+ -- Treesitter will be defined.
769+ --
770+ -- It's worth noting that many colorschemes will specify language specific
771+ -- highlight groups like rubyConstant or pythonInclude. However, I don't do
772+ -- that here since these should instead be linked to an existing highlight
773+ -- group.
774+ --
775+ -- @param colors (table) table with keys 'base00', 'base01', 'base02',
776+ -- 'base03', 'base04', 'base05', 'base06', 'base07', 'base08', 'base09',
777+ -- 'base0A', 'base0B', 'base0C', 'base0D', 'base0E', 'base0F'. Each key should
778+ -- map to a valid 6 digit hex color. If a string is provided, the
779+ -- corresponding table specifying the colorscheme will be used.
780+ function M .setup (colors , config )
781+ M .with_config (config or {})
782+
783+ local current_colorscheme_name = vim .g .tinted_current_colorscheme ;
784+
785+ if type (' colors' ) == ' table' or colors == ' ' or colors == nil then
786+ colors = M .colorschemes [" tinted-nvim-default" ]
787+ elseif type (' colors' ) == ' string' then
788+ -- Return if the theme is being set to the same theme
789+ if colors == current_colorscheme_name then
790+ return
791+ end
792+
793+ local ok , colorscheme = pcall (function ()
794+ vim .g .tinted_current_colorscheme = colors
795+ return M .colorschemes [colors ]
796+ end )
797+
798+ if ok then
799+ colors = colorscheme
800+ else
801+ vim .g .tinted_current_colorscheme = " tinted-nvim-default"
802+ colors = M .colorschemes [" tinted-nvim-default" ]
803+ end
804+ end
805+
806+ -- Live-reload only supports reading current theme from Tinty.
807+ if M .config .supports .live_reload == true and M .config .supports .tinty == false then
808+ vim .notify (
809+ " Live-reload feature only works with Tinty integration." ,
810+ vim .log .levels .WARN
811+ )
812+ end
813+
814+ if M .config .supports .tinty == true then
815+ colors = detect_colors_from_tinty ()
816+ if M .config .supports .live_reload then
817+ require (" tinted-live-reload" ).setup_live_reload (function ()
818+ set_colors (detect_colors_from_tinty ())
819+ end )
820+ end
821+
822+ -- Only trust BASE16_THEME if not inside a TMUX pane due to how TMUX handles env vars
823+ elseif M .config .tinted_shell == true and vim .env .TMUX == nil and vim .env .BASE16_THEME ~= nil then
824+ -- Safely get colorscheme object from BASE16_THEME env var
825+ local ok , colorscheme = pcall (function ()
826+ return M .colorschemes [vim .env .BASE16_THEME ]
827+ end )
828+
829+ if ok then
830+ vim .g .tinted_current_colorscheme = vim .env .BASE16_THEME
831+ colors = colorscheme
832+ end
833+ end
834+
835+ if vim .fn .exists (' syntax_on' ) then
836+ vim .cmd (' syntax reset' )
837+ end
838+
839+ set_colors (colors )
811840end
812841
813842function M .available_colorschemes ()
0 commit comments