summaryrefslogtreecommitdiff
path: root/common/modules/matugen/templates/matugen-neovim.nix
diff options
context:
space:
mode:
Diffstat (limited to 'common/modules/matugen/templates/matugen-neovim.nix')
-rw-r--r--common/modules/matugen/templates/matugen-neovim.nix74
1 files changed, 74 insertions, 0 deletions
diff --git a/common/modules/matugen/templates/matugen-neovim.nix b/common/modules/matugen/templates/matugen-neovim.nix
new file mode 100644
index 0000000..9a1b558
--- /dev/null
+++ b/common/modules/matugen/templates/matugen-neovim.nix
@@ -0,0 +1,74 @@
+{
+ config,
+ lib,
+ ...
+}:
+{
+ xdg.configFile = {
+ "matugen/templates/neovim.lua" = {
+ text = ''
+ local present, base46 = pcall(require, "base46")
+ if not present or not base46._DMS_SUPPORT then
+ vim.notify(
+ "base46 plugin not found or incorrect, make sure to install AvengeMedia/base46",
+ vim.log.levels.ERROR,
+ { title = "matugen integration" }
+ )
+ return
+ end
+
+ local settings = {
+ matugenTemplateNeovimSetBackground = true
+ }
+
+ vim.o.background = "{{mode}}"
+
+ local current_file_path = debug.getinfo(1, "S").source:sub(2)
+ local theme_base = nil
+ if vim.o.background == "dark" then
+ theme_base = "aquarium"
+ else
+ theme_base = "flex-light"
+ end
+ local harmony = 0.5
+ local theme_name = "matugen"
+
+ if not _G._matugen_theme_watcher then
+ local uv = vim.uv or vim.loop
+ _G._matugen_theme_watcher = { uv.new_fs_event(), reload_timer = uv.new_timer() }
+
+ local debounce_time = 100 -- ms
+ local function handler()
+ _G._matugen_theme_watcher.reload_timer:stop()
+ _G._matugen_theme_watcher.reload_timer:start(
+ debounce_time,
+ 0,
+ vim.schedule_wrap(function()
+ base46.theme_tables[theme_name] = nil
+ if vim.g.colors_name == theme_name then
+ vim.cmd.colorscheme(theme_name)
+ end
+ _G._matugen_theme_watcher[1]:stop()
+ _G._matugen_theme_watcher[1]:start(current_file_path, {}, handler)
+ end)
+ )
+ end
+ _G._matugen_theme_watcher[1]:start(current_file_path, {}, handler)
+ end
+
+ if not base46.theme_tables[theme_name] or base46.theme_tables[theme_name].type ~= vim.o.background then
+ local builtin = vim.deepcopy(assert(base46.get_builtin_theme(theme_base)))
+ local harmonized = base46.theme_harmonize(builtin, "{{colors.primary.default.hex}}", harmony)
+ if settings.matugenTemplateNeovimSetBackground ~= false then
+ harmonized = base46.theme_set_bg(harmonized, "{{colors.background.default.hex}}")
+ end
+
+ base46.theme_tables[theme_name] = harmonized
+ end
+
+ base46.load(theme_name)
+ vim.g.colors_name = theme_name
+ '';
+ };
+ };
+}