Skip to content

Commit

Permalink
docs: restructure docs & document fallback option
Browse files Browse the repository at this point in the history
  • Loading branch information
nekowinston committed Oct 9, 2024
1 parent 2190e4c commit f8bc4cd
Showing 1 changed file with 54 additions and 47 deletions.
101 changes: 54 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# auto-dark-mode.nvim

A Neovim plugin for macOS, Linux, and Windows that automatically changes the
editor appearance based on system settings.

Expand Down Expand Up @@ -28,71 +29,77 @@ editor appearance based on system settings.

<!-- panvimdoc-ignore-end -->

## Installation

### Using [vim-plug](https://github.com/junegunn/vim-plug)

```vim
Plug 'f-person/auto-dark-mode.nvim'
```
## 📋 Requirements
Your operating system needs to be:

## Requirements
* macOS, a Linux environment that implements
- a Linux desktop environment that implements
[`org.freedesktop.appearance.color-scheme`](https://github.com/flatpak/xdg-desktop-portal/issues/629),
Windows 10+ or WSL
* Neovim
such as
- [Gnome](https://gnome.org)
- [KDE](https://kde.org)
- [darkman](https://gitlab.com/WhyNotHugo/darkman) for window managers
- macOS Mojave or newer
- Windows 10 or newer (or WSL)

## Configuration
You need to call `setup` for initialization.
`setup` accepts a table with options – `set_dark_mode` function,
`set_light_mode` function, and `update_interval` integer.
## 📦 Installation

`set_dark_mode` is called when the system appearance changes to dark mode, and
`set_light_mode` is called when it changes to light mode.
By default, they just change the background option, but you can do whatever you like.
Install the plugin with your preferred package manager:

`update_interval` is how frequently the system appearance is checked.
The value needs to be larger than whatever time your system takes to query dark mode.
Otherwise you risk freezing neovim on shutdown.
The value is stored in milliseconds.
Defaults to `3000`.
### [lazy.nvim](https://github.com/folke/lazy.nvim)

```lua
local auto_dark_mode = require('auto-dark-mode')

auto_dark_mode.setup({
update_interval = 1000,
set_dark_mode = function()
vim.api.nvim_set_option_value('background', 'dark', {})
vim.cmd('colorscheme gruvbox')
end,
set_light_mode = function()
vim.api.nvim_set_option_value('background', 'light', {})
vim.cmd('colorscheme gruvbox')
end,
})
-- Lua
{
"f-person/auto-dark-mode.nvim",
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
}
```

### [vim-plug](https://github.com/junegunn/vim-plug)

```vim
Plug 'f-person/auto-dark-mode.nvim'
```

### Using [lazy](https://github.com/folke/lazy.nvim)
## ⚙️ Configuration

**auto-dark-mode** comes with the following defaults:

```lua
return {
"f-person/auto-dark-mode.nvim",
opts = {
update_interval = 1000,
{
set_dark_mode = function()
vim.api.nvim_set_option_value("background", "dark", {})
vim.cmd("colorscheme gruvbox")
vim.api.nvim_set_option_value("background", "dark", {})
end,
set_light_mode = function()
vim.api.nvim_set_option_value("background", "light", {})
vim.cmd("colorscheme gruvbox")
vim.api.nvim_set_option_value("background", "light", {})
end,
},
update_interval = 3000,
fallback = "dark"
}
```

#### Disable
`set_dark_mode` and `set_light_mode` are the hooks called when the system
appearance changes. By default, they change the
[background](https://neovim.io/doc/user/options.html#'background') option,
overriding the function allows for further customization.

`update_interval` is how frequently the system appearance is checked, in
milliseconds. The value needs to be higher than the amount of milliseconds it
takes to query your system for the dark mode state. Otherwise, you risk
freezing neovim on shutdown.

`fallback` specifies the theme to use when the auto-detection fails. This can
be particularly useful to specify a default version when remotely connecting
via SSH, or when using neovim on a tty.

## 🚀 Usage

### Disabling at runtime

You can disable `auto-dark-mode.nvim` at runtime via `lua require('auto-dark-mode').disable()`.

## Thanks To
Expand Down

0 comments on commit f8bc4cd

Please sign in to comment.