nvim: support different dark and light colorschemes

This commit is contained in:
2025-04-01 21:35:02 +02:00
parent 1513d23ec4
commit 29608ff8c4
7 changed files with 110 additions and 37 deletions

View File

@ -32,6 +32,7 @@
"melange-nvim": { "branch": "master", "commit": "2db5407f2f6d6d6286f50f2f7365728d66f6f3ae" },
"mellifluous.nvim": { "branch": "v1", "commit": "1637e46585435ebda7963248e0e65422effad8d9" },
"mini.nvim": { "branch": "main", "commit": "0420076298c4457f200c2de468f65d080597a347" },
"nano-theme.nvim": { "branch": "main", "commit": "0b1158c4911f4bd9d5a1e2e7669ebff893435b64" },
"neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" },
"neogit": { "branch": "master", "commit": "6d1bd94f7fca92a50a892f494920696b5defa8c8" },
"nordic.nvim": { "branch": "main", "commit": "8627750ece357e9670f9e69853091f7fbb8d6523" },

View File

@ -113,10 +113,4 @@ vim.keymap.set("n", "<leader>ss", "<cmd>source ~/.config/nvim/after/plugin/luasn
-- colors
key('n', '<F6>', function()
if vim.o.background == "dark" then
vim.o.background = "light"
else
vim.o.background = "dark"
end
end)
key('n', '<F6>', function() require('lupan.utils').toggle_color_scheme() end, { desc = 'Toggle background' })

View File

@ -2,6 +2,12 @@ local M = {}
local filename = os.getenv('HOME') .. '/.config/alacritty/alacritty.toml'
local colorschemes = nil
function M.set_color_schemes(dark, light)
colorschemes = { dark = dark, light = light }
end
function M.terminalbg()
local ok, lines = pcall(io.lines, filename)
if ok then
@ -14,11 +20,29 @@ function M.terminalbg()
return "dark"
end
function M.update_color_scheme()
vim.o.background = M.terminalbg()
if colorschemes then
vim.cmd.colorscheme(colorschemes[vim.o.background])
end
end
function M.toggle_color_scheme()
if vim.o.background == "dark" then
vim.o.background = "light"
else
vim.o.background = "dark"
end
if colorschemes then
vim.cmd.colorscheme(colorschemes[vim.o.background])
end
end
local w = vim.uv.new_fs_event()
local function watch(fname)
w:start(filename, {}, vim.schedule_wrap(function(...)
vim.o.background = M.terminalbg()
M.update_color_scheme()
w:stop()
watch(fname)
end))

View File

@ -11,9 +11,23 @@ return {
},
{
"savq/melange-nvim",
},
{
'ronisbr/nano-theme.nvim',
config = function()
vim.o.background = require('lupan.utils').terminalbg()
vim.cmd.colorscheme('melange')
local nano = require('nano-theme.colors')
local nano_get = nano.get
function nano.get()
local t = nano_get()
local light = vim.o.background == 'light'
if not light then
t.nano_strong.fg = '#ECEFF4'
end
return t
end
require('lupan.utils').set_color_schemes('nano-theme', 'nano-theme')
require('lupan.utils').update_color_scheme()
end
},
{

View File

@ -18,7 +18,7 @@ return {
harpoon = { switch = 'f' },
},
colors = {
file = '#5a418a',
file = '#EBCB8B',
},
},
keys = {