Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Burgin committed Sep 14, 2021
1 parent 284c951 commit 2f3f316
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
std = "min"
cache = true
include_files = {"lua"}
globals = {"vim"}
37 changes: 19 additions & 18 deletions lua/background_nvim.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
function check_which_theme()
local M = {}
local opts = {
ms = 60 * 1000, -- 60 seconds
hour = 17, -- 5pm
}

function M.check_which_theme()
local hour = os.date("*t").hour
if (hour > vim.g.BackgroundNvimHour - 1) then
print(os.date("*t").sec)
if (hour > opts.hour) then
vim.opt.background = 'dark'
else
vim.opt.background = 'light'
end
end

local M = {}

function M.setup(options)
if (not(vim.g.BackgroundNvimMS)) then
vim.g.BackgroundNvimMS = 60000
end

if (not(vim.g.BackgroundNvimHour)) then
vim.g.BackgroundNvimHour = 17
end

if (options) then
if (options.ms) then
vim.g.BackgroundNvimMS = options.ms
opts = options.ms
end

if (options.hour) then
vim.g.BackgroundNvimHour = options.hour
opts = options.hour
end
end

check_which_theme();

M.check_which_theme();

if (vim.g.background_nvim_timer) then
vim.cmd("call timer_stop(" .. vim.g.background_nvim_timer .. ")")
end

vim.cmd([[
func! ThemeChecker(timer)
lua check_which_theme()
lua require('background_nvim').check_which_theme()
endfunc
let timer = timer_start(g:BackgroundNvimMS, 'ThemeChecker', {'repeat': -1})
let g:background_nvim_timer = timer_start(]] .. opts.ms .. [[, 'ThemeChecker', {'repeat': -1})
]])
end

Expand Down

0 comments on commit 2f3f316

Please sign in to comment.