Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dark-notify

It's a program for watching when macOS switches to dark mode. Useful for making
your text editor switch to a dark theme. Includes a Neovim (Lua) plugin to do
It's a program for watching when macOS switches to dark mode. Useful for making
your text editor switch to a dark theme. Includes a Neovim (Lua) plugin to do
exactly that.

![Demo gif](demo.gif)
Expand Down Expand Up @@ -30,7 +30,7 @@ require('dark_notify').run()
EOF
```

By default, this will just execute `:set bg=dark` or `:set bg=light` as soon as
By default, this will just execute `:set bg=dark` or `:set bg=light` as soon as
the system appearance changes.

### Additional options
Expand Down Expand Up @@ -59,11 +59,24 @@ dn.run({
-- example
github = (vim.g.plug_home .. "/vim-colors-github/autoload/lightline/colorscheme/github.vim")
},
onchange = function(mode)
-- optional, you can configure your own things to react to changes.
-- this is called at startup and every time dark mode is switched,
-- either via the OS, or because you manually set/toggled the mode.
-- mode is either "light" or "dark"
-- optionally, you can configure what to do before/after changes.
-- this is called at startup and every time dark mode is switched,
-- either via the OS, or because you manually set/toggled the mode.
-- mode is either "light" or "dark"
before = function(mode)
-- your logic here
if mode == "dark" then
-- do something
else
-- do other thing
end
end,
after = function(mode)
if mode == "dark" then
-- do something
else
-- do other thing
end
end,
})

Expand Down
15 changes: 11 additions & 4 deletions lua/dark_notify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ local function apply_mode(mode)
local bg = sel.background or mode
local lltheme = sel.lightline or nil

if config.before ~= nil then
config.before(mode)
end

vim.api.nvim_command('set background=' .. bg)
if colorscheme ~= nil then
vim.api.nvim_command('colorscheme ' .. colorscheme)
Expand All @@ -79,10 +83,11 @@ local function apply_mode(mode)
end
end

if config.onchange ~= nil then
config.onchange(mode)
if config.after ~= nil then
config.after(mode)
end


state.current_mode = mode
end

Expand Down Expand Up @@ -181,7 +186,8 @@ function M.configure(config)
end
local lightline_loaders = config.lightline_loaders or {}
local schemes = config.schemes or {}
local onchange = config.onchange
local before = config.before
local after = config.after

for _, mode in pairs({ "light", "dark" }) do
if type(schemes[mode]) == "string" then
Expand All @@ -192,7 +198,8 @@ function M.configure(config)
edit_config(function (conf)
conf.lightline_loaders = lightline_loaders
conf.schemes = schemes
conf.onchange = onchange
conf.before = before
conf.after = after
end)
end

Expand Down