From 01ec926d525ee4b7bb94e6eb04c6743912d8134f Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Sat, 3 Aug 2024 18:09:17 +0200 Subject: [PATCH] Add nvim automatic theme switching For colorschemes that have different schemes for light vs dark modes --- vim/plugin/colors.lua | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 vim/plugin/colors.lua diff --git a/vim/plugin/colors.lua b/vim/plugin/colors.lua new file mode 100644 index 0000000..575d61e --- /dev/null +++ b/vim/plugin/colors.lua @@ -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