diff --git a/nvim/init.lua b/nvim/init.lua index aec0f5d..3f39b53 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -11,6 +11,7 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) +local Utils = require("juancwu.utils") require("juancwu.config").setup({ - colorscheme = "kanagawa-dragon", + colorscheme = Utils.colors.get_timebased_colorscheme(), }) diff --git a/nvim/lua/juancwu/utils/colors.lua b/nvim/lua/juancwu/utils/colors.lua new file mode 100644 index 0000000..4f83a80 --- /dev/null +++ b/nvim/lua/juancwu/utils/colors.lua @@ -0,0 +1,21 @@ +---@class juancwu.utils.colors +local M = {} + +---@return boolean +function M.is_daytime() + local current_hour = tonumber(os.date("%H")) + return current_hour >= 7 and current_hour < 19 +end + +---@return string +function M.get_timebased_colorscheme() + local light = "kanagawa-lotus" + local dark = "kanagawa-dragon" + if M.is_daytime() then + return light + else + return dark + end +end + +return M diff --git a/nvim/lua/juancwu/utils/init.lua b/nvim/lua/juancwu/utils/init.lua index 7c1034b..8b5d893 100644 --- a/nvim/lua/juancwu/utils/init.lua +++ b/nvim/lua/juancwu/utils/init.lua @@ -1,10 +1,11 @@ ---@class Utils ---@field os juancwu.utils.os +---@field colors juancwu.utils.colors local M = setmetatable({}, { - __index = function(t, k) - t[k] = require("juancwu.utils." .. k) - return t[k] - end + __index = function(t, k) + t[k] = require("juancwu.utils." .. k) + return t[k] + end, }) return M