(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.api.nvim_create_user_command("FormatEnable", function(args)
|
||||||
vim.g.disable_autoformat = false
|
vim.g.disable_autoformat = false
|
||||||
end, { desc = "Enable Autoformat" })
|
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
|
end
|
||||||
|
|
||||||
setmetatable(M, {
|
setmetatable(M, {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
---@class juancwu.utils.colors
|
---@class juancwu.utils.colors
|
||||||
local M = {}
|
local M = {}
|
||||||
|
local light = "catppuccin-latte"
|
||||||
|
local dark = "catppuccin-mocha"
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_daytime()
|
function M.is_daytime()
|
||||||
|
|
@ -9,13 +11,23 @@ end
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
function M.get_timebased_colorscheme()
|
function M.get_timebased_colorscheme()
|
||||||
local light = "catppuccin-latte"
|
|
||||||
local dark = "catppuccin-mocha"
|
|
||||||
if M.is_daytime() then
|
if M.is_daytime() then
|
||||||
|
vim.g.is_light_colors = true
|
||||||
return light
|
return light
|
||||||
else
|
else
|
||||||
|
vim.g.is_light_colors = false
|
||||||
return dark
|
return dark
|
||||||
end
|
end
|
||||||
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
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue