(nvim) add fn & cmd to toggle colorscheme
This commit is contained in:
parent
1a5ad084ce
commit
61665c1235
2 changed files with 21 additions and 2 deletions
|
|
@ -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, {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue