(nvim) add fn & cmd to toggle colorscheme

This commit is contained in:
jc 2024-06-06 15:23:59 -04:00
commit 61665c1235
No known key found for this signature in database
2 changed files with 21 additions and 2 deletions

View file

@ -58,6 +58,13 @@ function M.setup(opts)
vim.api.nvim_create_user_command("FormatEnable", function(args)
vim.g.disable_autoformat = false
end, { desc = "Enable Autoformat" })
-- create command to toggle colorscheme
vim.api.nvim_create_user_command(
"ToggleColors",
require("juancwu.utils.colors").toggle_colors,
{ desc = "Toggle colorscheme" }
)
end
setmetatable(M, {

View file

@ -1,5 +1,7 @@
---@class juancwu.utils.colors
local M = {}
local light = "catppuccin-latte"
local dark = "catppuccin-mocha"
---@return boolean
function M.is_daytime()
@ -9,13 +11,23 @@ end
---@return string
function M.get_timebased_colorscheme()
local light = "catppuccin-latte"
local dark = "catppuccin-mocha"
if M.is_daytime() then
vim.g.is_light_colors = true
return light
else
vim.g.is_light_colors = false
return dark
end
end
function M.toggle_colors()
if vim.g.is_light_colors then
vim.g.is_light_colors = false
vim.cmd.colorscheme(dark)
else
vim.g.is_light_colors = true
vim.cmd.colorscheme(light)
end
end
return M