Add nvim automatic theme switching
For colorschemes that have different schemes for light vs dark modes
This commit is contained in:
parent
34c7c0700d
commit
01ec926d52
1 changed files with 67 additions and 0 deletions
67
vim/plugin/colors.lua
Normal file
67
vim/plugin/colors.lua
Normal file
|
@ -0,0 +1,67 @@
|
|||
local wezvar = require "wezvar"
|
||||
|
||||
local termcolors = {}
|
||||
|
||||
local dark = {
|
||||
dayfox = "nightfox";
|
||||
antiphoton = "photon";
|
||||
fogbell_light = "fogbell";
|
||||
}
|
||||
local light = {}
|
||||
for _light, _dark in pairs(dark) do
|
||||
light[_dark] = _light
|
||||
end
|
||||
|
||||
function termcolors.propagate()
|
||||
local num_color = vim.fn.synIDattr(vim.fn.hlID("normal"), "bg")
|
||||
if vim.env.TERM_PROGRAM == "WezTerm" then
|
||||
wezvar("bgcolor", num_color)
|
||||
end
|
||||
end
|
||||
|
||||
function termcolors.reset()
|
||||
if vim.env.TERM_PROGRAM == "WezTerm" then
|
||||
wezvar("bgcolor", "")
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||
desc = "Sets wezterm's background colour to match vim";
|
||||
callback = termcolors.propagate;
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("ExitPre", {
|
||||
desc = "Resets terminal colours back to normal";
|
||||
callback = termcolors.reset;
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("Dark", function()
|
||||
if vim.o.bg ~= "dark" then
|
||||
local current_colors_name = vim.g.colors_name
|
||||
vim.g.ayucolor = "dark"
|
||||
vim.g.arcadia_Daybreak = nil
|
||||
vim.g.arcadia_Midnight = 1
|
||||
vim.g.alduin_Shout_Become_Ethereal = 1
|
||||
vim.o.bg = "dark"
|
||||
vim.cmd("colorscheme " .. (dark[current_colors_name] or current_colors_name))
|
||||
end
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("Light", function()
|
||||
if vim.o.bg ~= "light" then
|
||||
local current_colors_name = vim.g.colors_name
|
||||
vim.g.ayucolor = "light"
|
||||
vim.g.arcadia_Daybreak = 1
|
||||
vim.g.arcadia_Midnight = nil
|
||||
vim.g.alduin_Shout_Become_Ethereal = nil
|
||||
vim.o.bg = "light"
|
||||
vim.cmd("colorscheme " .. (light[current_colors_name] or current_colors_name))
|
||||
end
|
||||
end, {})
|
||||
|
||||
vim.cmd("colorscheme nord")
|
||||
if vim.fn.filereadable(os.getenv("HOME") .. "/.dark")==1 then
|
||||
vim.cmd("Dark")
|
||||
else
|
||||
vim.cmd("Light")
|
||||
end
|
Loading…
Reference in a new issue