Skip to content

Commit 90f6f2d

Browse files
committed
feat: add dynamic DMS/base46 theme integration and switch the default colorscheme to Catppuccin
1 parent a18d727 commit 90f6f2d

2 files changed

Lines changed: 128 additions & 16 deletions

File tree

colors/dms.lua

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
local present, base46 = pcall(require, "base46")
2+
if not present or not base46._DMS_SUPPORT then
3+
vim.notify(
4+
"base46 plugin not found or incorrect, make sure to install AvengeMedia/base46",
5+
vim.log.levels.ERROR,
6+
{ title = "dms integration" }
7+
)
8+
return
9+
end
10+
11+
local config_home = vim.env.XDG_CONFIG_HOME
12+
if config_home == nil or #config_home == 0 then
13+
config_home = vim.fs.joinpath(vim.env.HOME, ".config")
14+
end
15+
local settings_file_path = vim.fs.joinpath(config_home, "DankMaterialShell", "settings.json")
16+
local settings_file = io.open(settings_file_path, "r")
17+
if settings_file == nil then
18+
vim.notify(
19+
"cannnot read dms settings file at '" .. settings_file_path .. "'",
20+
vim.log.levels.ERROR,
21+
{ title = "dms integration" }
22+
)
23+
return
24+
end
25+
local settings = vim.json.decode(settings_file:read("*a"))
26+
settings_file:close()
27+
28+
local function deepGet(t, k)
29+
for _, s in ipairs(k) do
30+
if type(t) ~= "table" then
31+
return
32+
end
33+
t = t[s]
34+
end
35+
return t
36+
end
37+
38+
local current_file_path = debug.getinfo(1, "S").source:sub(2)
39+
local theme_base = deepGet(settings, { "matugenTemplateNeovimSettings", vim.o.background, "baseTheme" })
40+
or ("github_" .. vim.o.background)
41+
local harmony = deepGet(settings, { "matugenTemplateNeovimSettings", vim.o.background, "harmony" }) or 0.5
42+
local theme_name = "dms"
43+
44+
if not _G._matugen_theme_watcher then
45+
local uv = vim.uv or vim.loop
46+
_G._matugen_theme_watcher = { uv.new_fs_event(), uv.new_fs_event(), reload_timer = uv.new_timer() }
47+
48+
local debounce_time = 100 -- ms
49+
local function handler()
50+
_G._matugen_theme_watcher.reload_timer:stop()
51+
_G._matugen_theme_watcher.reload_timer:start(
52+
debounce_time,
53+
0,
54+
vim.schedule_wrap(function()
55+
base46.theme_tables[theme_name] = nil
56+
if vim.g.colors_name == theme_name then
57+
vim.cmd.colorscheme(theme_name)
58+
vim.notify("Theme reload", vim.log.levels.INFO, { title = "dms integration" })
59+
end
60+
-- NOTE: contrary to what the documentation says, uv fs events usually do not manage to react to more than one edit.
61+
-- I understand that this is not intended: some edit processes in a typical system (e.g. the one neovim uses with
62+
-- multiple renames and changes) make things hard to follow for libuv. Therefore, a restart is the best option.
63+
_G._matugen_theme_watcher[1]:stop()
64+
_G._matugen_theme_watcher[2]:stop()
65+
_G._matugen_theme_watcher[1]:start(current_file_path, {}, handler)
66+
_G._matugen_theme_watcher[2]:start(settings_file_path, {}, handler)
67+
end)
68+
)
69+
end
70+
_G._matugen_theme_watcher[1]:start(current_file_path, {}, handler)
71+
_G._matugen_theme_watcher[2]:start(settings_file_path, {}, handler)
72+
end
73+
74+
if not base46.theme_tables[theme_name] or base46.theme_tables[theme_name].type ~= vim.o.background then
75+
local builtin = vim.deepcopy(assert(base46.get_builtin_theme(theme_base)))
76+
local harmonized = base46.theme_harmonize(builtin, "#89b4fa", harmony)
77+
harmonized = base46.theme_set_bg(harmonized, "#1e1e2e")
78+
79+
base46.theme_tables[theme_name] = harmonized
80+
end
81+
82+
base46.load(theme_name)
83+
vim.g.colors_name = theme_name

init.lua

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -789,28 +789,57 @@ require('lazy').setup({
789789
},
790790
},
791791

792-
{ -- You can easily change to a different colorscheme.
793-
-- Change the name of the colorscheme plugin below, and then
794-
-- change the command in the config to whatever the name of that colorscheme is.
795-
--
796-
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
797-
'folke/tokyonight.nvim',
798-
priority = 1000, -- Make sure to load this before all the other start plugins.
792+
{ -- Colorscheme
793+
'catppuccin/nvim',
794+
name = 'catppuccin',
795+
priority = 1000,
799796
config = function()
800-
---@diagnostic disable-next-line: missing-fields
801-
require('tokyonight').setup {
802-
styles = {
803-
comments = { italic = false }, -- Disable italics in comments
797+
require('catppuccin').setup {
798+
flavour = 'mocha',
799+
background = {
800+
light = 'latte',
801+
dark = 'mocha',
804802
},
803+
transparent_background = true,
804+
show_end_of_buffer = false,
805+
term_colors = true,
806+
integrations = {
807+
gitsigns = true,
808+
mason = true,
809+
mini = {
810+
enabled = true,
811+
indentscope_color = '',
812+
},
813+
native_lsp = {
814+
enabled = true,
815+
inlay_hints = {
816+
background = true,
817+
},
818+
},
819+
telescope = {
820+
enabled = true,
821+
},
822+
treesitter = true,
823+
which_key = true,
824+
},
825+
custom_highlights = function(colors)
826+
return {
827+
CursorLineNr = { fg = colors.lavender, bold = true },
828+
FloatBorder = { bg = colors.mantle, fg = colors.surface2 },
829+
LineNr = { fg = colors.overlay1 },
830+
NormalFloat = { bg = colors.mantle },
831+
Pmenu = { bg = colors.mantle, fg = colors.text },
832+
PmenuSel = { bg = colors.surface0, fg = colors.text, bold = true },
833+
StatusLine = { bg = colors.surface0, fg = colors.text },
834+
StatusLineNC = { bg = colors.base, fg = colors.overlay1 },
835+
Visual = { bg = colors.surface1 },
836+
}
837+
end,
805838
}
806839

807-
-- Load the colorscheme here.
808-
-- Like many other themes, this one has different styles, and you could load
809-
-- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'.
810-
vim.cmd.colorscheme 'tokyonight-night'
840+
vim.cmd.colorscheme 'catppuccin'
811841
end,
812842
},
813-
{ 'catppuccin/nvim', name = 'catppuccin', priority = 1000 },
814843

815844
-- Highlight todo, notes, etc in comments
816845
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },

0 commit comments

Comments
 (0)