summaryrefslogtreecommitdiff
path: root/colors
diff options
context:
space:
mode:
authorbee <beebeeb5k@gmail.com>2026-05-05 22:37:10 +0530
committerbee <beebeeb5k@gmail.com>2026-05-05 22:37:10 +0530
commit9365a8e96827cbf7bc5adad6d29bcd05b4d761b2 (patch)
tree0998a5dcfc4517e4112a2c589e04ac0dbc1e011b /colors
parent0c50f17133b90c60735f1f51943f51f60372bdd3 (diff)
Migrate from nixcats to nix-wrapper-modules
Diffstat (limited to 'colors')
-rw-r--r--colors/bee_matugen.lua98
-rw-r--r--colors/matugen.lua78
2 files changed, 78 insertions, 98 deletions
diff --git a/colors/bee_matugen.lua b/colors/bee_matugen.lua
deleted file mode 100644
index 9d7f760..0000000
--- a/colors/bee_matugen.lua
+++ /dev/null
@@ -1,98 +0,0 @@
-local present, base46 = pcall(require, "base46")
-if not present then
- vim.notify("base46 plugin not found or incorrect.", vim.log.levels.ERROR, { title = "matugen integration" })
- return
-end
-
-local config_home = vim.env.XDG_CONFIG_HOME
-if config_home == nil or #config_home == 0 then
- config_home = vim.fs.joinpath(vim.env.HOME, ".config")
-end
-
-local settings_file_path = vim.fs.joinpath(config_home, "matugen", "neovim_matugen.json")
-
-local settings_file = io.open(settings_file_path, "r")
-if settings_file == nil then
- vim.notify(
- "Cannot read matugen settings file at '" .. settings_file_path .. "'. Did you run beesettings wall?",
- vim.log.levels.WARN,
- { title = "matugen integration" }
- )
- return
-end
-
-local content = settings_file:read("*a")
-settings_file:close()
-
-local ok, settings = pcall(vim.json.decode, content)
-if not ok or not settings then
- vim.notify("Failed to parse matugen JSON", vim.log.levels.ERROR, { title = "matugen integration" })
- return
-end
-
-local harmony = settings.harmony or 0.5
-local source_color = settings.source_color
-local bg_color = settings.background
-vim.o.background = settings.mode
-
-if not source_color or not bg_color then
- vim.notify(
- "Missing colors in matugen JSON. Check your template.",
- vim.log.levels.ERROR,
- { title = "matugen integration" }
- )
- return
-end
-
--- local theme_base = "github_" .. vim.o.background
-local theme_base = "kanagawa"
-if vim.o.background == "light" then
- theme_base = "one_light"
-end
-local theme_name = "bee_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()
- -- Clear the cached theme table to force a rebuild
- local f = io.open(settings_file_path, "r")
- if f then
- local new_content = f:read("*a")
- f:close()
- local ok_new, new_settings = pcall(vim.json.decode, new_content)
- if ok_new and new_settings.mode then
- vim.o.background = new_settings.mode
- end
- end
- 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(settings_file_path, {}, handler)
- end)
- )
- end
- _G._matugen_theme_watcher[1]:start(settings_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, source_color, harmony)
- harmonized = base46.theme_set_bg(harmonized, bg_color)
-
- base46.theme_tables[theme_name] = harmonized
-end
-
-base46.load(theme_name)
-vim.g.colors_name = theme_name
diff --git a/colors/matugen.lua b/colors/matugen.lua
new file mode 100644
index 0000000..241bdf2
--- /dev/null
+++ b/colors/matugen.lua
@@ -0,0 +1,78 @@
+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 config_home = vim.env.XDG_CONFIG_HOME
+if config_home == nil or #config_home == 0 then
+ config_home = vim.fs.joinpath(vim.env.HOME, ".config")
+end
+
+local colors_file_path = vim.fs.joinpath(config_home, "nvim", "colors.json")
+local colors_file = io.open(colors_file_path, "r")
+if colors_file == nil then
+ vim.notify(
+ "cannnot read matugen colors file at '" .. colors_file_path .. "'",
+ vim.log.levels.ERROR,
+ { title = "matugen integration" }
+ )
+ return
+end
+local colors = vim.json.decode(colors_file:read("*a"))
+colors_file:close()
+
+local mode = colors.mode
+if mode ~= nil then
+ if mode:match("light") then
+ vim.o.background = "light"
+ elseif mode:match("dark") then
+ vim.o.background = "dark"
+ end
+end
+
+local settings = { matugenTemplateNeovimSetBackground = true }
+
+local theme_base = ("github_" .. vim.o.background)
+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(colors_file_path, {}, handler)
+ end)
+ )
+ end
+ _G._matugen_theme_watcher[1]:start(colors_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.source_color, harmony)
+ if settings.matugenTemplateNeovimSetBackground ~= false then
+ harmonized = base46.theme_set_bg(harmonized, colors.background)
+ end
+
+ base46.theme_tables[theme_name] = harmonized
+end
+
+base46.load(theme_name)
+vim.g.colors_name = theme_name