nvim/lua/custom/plugins/auto-dark-mode.lua
Jeremie Fraeys ecb3452195
All checks were successful
Luacheck / luacheck (push) Successful in 11s
StyLua / stylua (push) Successful in 3s
fix: prevent startup flash by setting colorscheme early and deferring oil
2026-02-08 15:53:51 -05:00

66 lines
2 KiB
Lua
Executable file

-- Define the function to set custom highlights for both themes
local function set_lsp_highlights(mode)
local hl = vim.api.nvim_set_hl
-- Shared diagnostic groups
local diagnostic_groups = {
'DiagnosticVirtualTextError',
'DiagnosticVirtualTextWarn',
'DiagnosticVirtualTextInfo',
'DiagnosticVirtualTextHint',
'DiagnosticUnderlineError',
'DiagnosticUnderlineWarn',
'DiagnosticUnderlineInfo',
'DiagnosticUnderlineHint',
}
if mode == 'dark' then
local fg = 'NONE'
local bg = '#272822'
local comment = '#75715e'
local line_nr = '#90908a'
for _, group in ipairs(diagnostic_groups) do
hl(0, group, { fg = fg, bg = bg, underline = false })
end
hl(0, 'TreesitterContext', { bg = bg })
hl(0, 'TreesitterContextLineNumber', { fg = line_nr })
hl(0, 'TreesitterContextSeparator', { fg = comment })
elseif mode == 'light' then
local bg = '#fdf6e3'
local fg = '#657b83'
local comment = '#586e75'
hl(0, 'LspDocumentHighlight', { bg = bg, fg = fg, underline = false })
hl(0, 'DiagnosticVirtualTextError', { fg = '#dc322f' })
hl(0, 'DiagnosticVirtualTextWarn', { fg = '#b58900' })
hl(0, 'DiagnosticVirtualTextInfo', { fg = '#268bd2' })
hl(0, 'DiagnosticVirtualTextHint', { fg = '#2aa198' })
hl(0, 'TreesitterContext', { bg = 'NONE' })
hl(0, 'TreesitterContextLineNumber', { fg = comment })
hl(0, 'TreesitterContextSeparator', { fg = comment })
end
end
return {
'f-person/auto-dark-mode.nvim',
opts = {
update_interval = 2000,
set_dark_mode = function()
vim.api.nvim_set_option_value('background', 'dark', {})
vim.cmd('colorscheme monokai')
-- Apply custom highlight settings for Monokai
set_lsp_highlights('dark')
end,
set_light_mode = function()
vim.api.nvim_set_option_value('background', 'light', {})
vim.cmd('colorscheme solarized')
-- Apply custom highlight settings for Solarized
set_lsp_highlights('light')
end,
},
}