Automatic dark and light mode for the terminal
Sometimes I need a refresher for my eyes, not always using a dark screen with light text. This can easily become tiring, specially when reading long texts like books or when the environment is also bright.
I noticed this after switching my smartphone from dark to light mode, something I normally set to dark as soon as I get any device. It was relieving, and the text became clearly more readable. The same happened later when I tried different light themes for Neovim and Wezterm.
Ended up changing my configuration to let both applications identify the mode the system is using, and apply themes accordingly.
The theme I chose was Kanagawa1, specifically dragon
and lotus
variants. I like having muted colors, otherwise I find them too distracting. I’ve even thought about switching to other monochrome options, but so far this has been great. The biggest change I made was lotus
’s background, since I’m not a fan of yellow background since I stopped using Solarized themes.
Wezterm
For Wezterm, it’s already documented how to have different themes based on the system’s mode enabled2. The only thing left was adding both dark and light colors, and setting them up.
1local dark_theme = wezterm.color.get_builtin_schemes()['Kanagawa Dragon (Gogh)']
2dark_theme.foreground = "#f0f0f0"
3dark_theme.background = "#111111"
4
5local light_theme = {
6 background = "#EEEEEE",
7 foreground = "#222222",
8
9 cursor_bg = "#c8c093",
10 cursor_fg = "#c8c093",
11 cursor_border = "#c8c093",
12
13 selection_fg = "#c8c093",
14 selection_bg = "#2d4f67",
15
16 scrollbar_thumb = "#16161d",
17 split = "#16161d",
18
19 ansi = { "#c8c093", "#c34043", "#76946a", "#c0a36e", "#7e9cd8", "#957fb8", "#6a9589", "#090618" },
20 brights = { "#dcd7ba", "#e82424", "#98bb6c", "#e6c384", "#7fb4ca", "#938aa9", "#7aa89f", "#727169" },
21 indexed = { [16] = "#ffa066", [17] = "#ff5d62" },
22}
23
24config.color_schemes = {
25 ['Kanagawa Dark'] = dark_theme,
26 ['Kanagawa Light'] = light_theme,
27}
28
29function get_appearance()
30 if wezterm.gui then
31 return wezterm.gui.get_appearance()
32 end
33 return 'Dark'
34end
35
36function scheme_for_appearance(appearance)
37 if appearance:find 'Dark' then
38 return 'Kanagawa Dark'
39 else
40 return 'Kanagawa Light'
41 end
42end
43
44config.color_scheme = scheme_for_appearance(get_appearance())
Neovim
The solution here was pretty much two plugins, one for switching the theme3, and the theme itself. Good thing the theme plugins allows overriding the colors directly; I still need to override more but I don’t think I’ll use light mode that often. Below is the configuration using Lazy.
1 {
2 "f-person/auto-dark-mode.nvim",
3 opts = {
4 update_interval = 1000,
5 set_dark_mode = function()
6 vim.cmd("colorscheme kanagawa-dragon")
7 end,
8 set_light_mode = function()
9 vim.cmd("colorscheme kanagawa-lotus")
10 end,
11 },
12 },
13 {
14 "rebelot/kanagawa.nvim",
15 opts = {
16 colors = {
17 palette = {
18 lotusInk1 = "#222222",
19 lotusWhite3 = "#EEEEEE"
20 },
21 theme = {
22 all = {
23 ui = {
24 bg_gutter = "none"
25 }
26 }
27 }
28 }
29 }
30 }
Result
Dark Mode
Light Mode