Giter VIP home page Giter VIP logo

dark-notify's Introduction

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 exactly that.

Demo gif

Install

brew install cormacrelf/tap/dark-notify

Neovim usage

Requires neovim 0.4.4 or later.

Add a plugin with your favourite plugin manager:

Plug 'cormacrelf/dark-notify'

Then add to your init.vim:

:lua <<EOF
require('dark_notify').run()
EOF

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

Additional options

local dn = require('dark_notify')

-- Configure
dn.run({
    schemes = {
      -- you can use a different colorscheme for each
      dark  = "dark colorscheme name",
      -- even a different `set background=light/dark` setting or lightline theme
      -- if you use lightline, you may want to configure lightline themes,
      -- even if they're the same one, especially if the theme reacts to :set bg
      light = {
        colorscheme = "light scheme name",
        background = "override to either light or dark",
        lightline = "set your lightline theme name here"
      }
    },
    lightline_loaders = {
        -- It's tricky to get lightline to update a colorscheme for `set bg=dark`.
        -- Add a line here to reload the config for your lightline theme.
        my_ll_theme_name = "path to a lightline autoload file",
        -- 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"
    end,
})

-- Draw the blinds for now
dn.set_mode("dark")

-- Swap to whatever it isn't currently
dn.toggle()

-- Match the system
dn.update()

-- Stop reacting to changes
dn.stop()

-- Start reacting again, with previous settings
dn.run()

You can put those in mappings if you want.

nmap <f5> :lua require('dark_notify').toggle()<cr>

What if I just want the toggle functionality / am not on macOS?

Use the configure function instead.

:lua <<EOF
require('dark_notify').configure({
    -- same options as run({ ... })
})
EOF

Command line usage

$ dark-notify
light
# then System Preferences > General, switch back and forth
dark
light
dark
# ... ctrl-C to quit.

You can also run another command whenever it changes:

$ dark-notify -c 'echo something'
something light
something dark
$ dark-notify -c 'python3 my-script.py'

dark-notify -h for more options.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.