mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-13 17:22:08 -04:00
New neovim theme engine (#1985)
* feat(matugen)!: rework completely neovim's theme engine * fix: link to neovim theme plugin * fix: expect AvengeMedia/base46 instead of Silzinc/base46
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
[templates.dmsneovim]
|
||||
input_path = 'SHELL_DIR/matugen/templates/neovim.lua'
|
||||
output_path = 'CONFIG_DIR/nvim/lua/plugins/dankcolors.lua'
|
||||
output_path = 'CONFIG_DIR/nvim/colors/dms.lua'
|
||||
|
||||
@@ -1,40 +1,83 @@
|
||||
return {
|
||||
{
|
||||
"RRethy/base16-nvim",
|
||||
priority = 1000,
|
||||
config = function()
|
||||
require('base16-colorscheme').setup({
|
||||
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 = "dms integration" }
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
base00 = '{{colors.background.dark.hex}}',
|
||||
base01 = '{{colors.surface_container_low.dark.hex}}',
|
||||
base02 = '{{colors.surface_container.dark.hex}}',
|
||||
base03 = '{{dank16.color8.dark.hex}}',
|
||||
base0B = '{{dank16.color3.dark.hex}}',
|
||||
base04 = '{{dank16.color7.default.hex}}',
|
||||
base05 = '{{dank16.color15.default.hex}}',
|
||||
base06 = '{{dank16.color15.default.hex}}',
|
||||
base07 = '{{dank16.color15.default.hex}}',
|
||||
base08 = '{{dank16.color9.default.hex}}',
|
||||
base09 = '{{dank16.color9.default.hex}}',
|
||||
base0A = '{{dank16.color12.default.hex}}',
|
||||
base0C = '{{dank16.color14.default.hex}}',
|
||||
base0D = '{{dank16.color12.default.hex}}',
|
||||
base0E = '{{dank16.color13.default.hex}}',
|
||||
base0F = '{{dank16.color13.default.hex}}',
|
||||
})
|
||||
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, "DankMaterialShell", "settings.json")
|
||||
local settings_file = io.open(settings_file_path, "r")
|
||||
if settings_file == nil then
|
||||
vim.notify(
|
||||
"cannnot read dms settings file at '" .. settings_file_path .. "'",
|
||||
vim.log.levels.ERROR,
|
||||
{ title = "dms integration" }
|
||||
)
|
||||
return
|
||||
end
|
||||
local settings = vim.json.decode(settings_file:read("*a"))
|
||||
settings_file:close()
|
||||
|
||||
local current_file_path = vim.fn.stdpath("config") .. "/lua/plugins/dankcolors.lua"
|
||||
if not _G._matugen_theme_watcher then
|
||||
local uv = vim.uv or vim.loop
|
||||
_G._matugen_theme_watcher = uv.new_fs_event()
|
||||
_G._matugen_theme_watcher:start(current_file_path, {}, vim.schedule_wrap(function()
|
||||
local new_spec = dofile(current_file_path)
|
||||
if new_spec and new_spec[1] and new_spec[1].config then
|
||||
new_spec[1].config()
|
||||
print("Theme reload")
|
||||
end
|
||||
end))
|
||||
end
|
||||
local function deepGet(t, k)
|
||||
for _, s in ipairs(k) do
|
||||
if type(t) ~= "table" then
|
||||
return
|
||||
end
|
||||
}
|
||||
}
|
||||
t = t[s]
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
local current_file_path = debug.getinfo(1, "S").source:sub(2)
|
||||
local theme_base = deepGet(settings, { "matugenTemplateNeovimSettings", vim.o.background, "baseTheme" })
|
||||
or ("github_" .. vim.o.background)
|
||||
local harmony = deepGet(settings, { "matugenTemplateNeovimSettings", vim.o.background, "harmony" }) or 0.5
|
||||
local theme_name = "dms"
|
||||
|
||||
if not _G._matugen_theme_watcher then
|
||||
local uv = vim.uv or vim.loop
|
||||
_G._matugen_theme_watcher = { uv.new_fs_event(), 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)
|
||||
vim.notify("Theme reload", vim.log.levels.INFO, { title = "dms integration" })
|
||||
end
|
||||
-- NOTE: contrary to what the documentation says, uv fs events usually do not manage to react to more than one edit.
|
||||
-- I understand that this is not intended: some edit processes in a typical system (e.g. the one neovim uses with
|
||||
-- multiple renames and changes) make things hard to follow for libuv. Therefore, a restart is the best option.
|
||||
_G._matugen_theme_watcher[1]:stop()
|
||||
_G._matugen_theme_watcher[2]:stop()
|
||||
_G._matugen_theme_watcher[1]:start(current_file_path, {}, handler)
|
||||
_G._matugen_theme_watcher[2]:start(settings_file_path, {}, handler)
|
||||
end)
|
||||
)
|
||||
end
|
||||
_G._matugen_theme_watcher[1]:start(current_file_path, {}, handler)
|
||||
_G._matugen_theme_watcher[2]: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, "{{colors.source_color.default.hex}}", harmony)
|
||||
harmonized = base46.theme_set_bg(harmonized, "{{colors.background.default.hex}}")
|
||||
|
||||
base46.theme_tables[theme_name] = harmonized
|
||||
end
|
||||
|
||||
base46.load(theme_name)
|
||||
vim.g.colors_name = theme_name
|
||||
|
||||
Reference in New Issue
Block a user