Skip to content

Commit ce0a60d

Browse files
committed
feat: add 'auto' option to use vim.o.background for light/dark theme
fixes #63
1 parent 8baad5d commit ce0a60d

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ require("cyberdream").setup({
113113
terminal_colors = true,
114114

115115
theme = {
116-
variant = "default", -- use "light" for the light variant
116+
variant = "default", -- use "light" for the light variant. Also accepts "auto" to set dark or light colors based on the current value of `vim.o.background`
117117
highlights = {
118118
-- Highlight groups to override, adding new groups is also possible
119119
-- See `:h highlight-groups` for a list of highlight groups or run `:hi` to see all groups and their current values

lua/cyberdream/config.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local M = {}
22

33
---@class ThemeConfig
4-
---@field variant? string | "'default'" | "'light'"
4+
---@field variant? string | "'default'" | "'light'" | "'auto'"
55
---@field colors? table<string, string>
66
---@field highlights? table<string, table<string, string>>
77

lua/cyberdream/init.lua

+12
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,16 @@ vim.api.nvim_create_user_command("CyberdreamToggleMode", function()
1818
vim.api.nvim_exec_autocmds("User", { pattern = "CyberdreamToggleMode", data = new_variant })
1919
end, {})
2020

21+
vim.api.nvim_create_autocmd("OptionSet", {
22+
pattern = "background",
23+
callback = function()
24+
if vim.g.cyberdream_opts.theme.variant ~= "auto" then
25+
return
26+
end
27+
local new_variant = vim.v.option_new == "dark" and "default" or "light"
28+
util.toggle_lualine_theme(new_variant)
29+
vim.api.nvim_exec_autocmds("User", { pattern = "CyberdreamToggleMode", data = new_variant })
30+
end,
31+
})
32+
2133
return M

lua/cyberdream/theme.lua

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ function M.setup()
1212
t = colors.light
1313
end
1414

15+
if opts.theme.variant == "auto" then
16+
if vim.o.background == "light" then
17+
t = colors.light
18+
end
19+
end
20+
1521
-- Override colors with user defined colors
1622
t = vim.tbl_deep_extend("force", t, opts.theme.colors)
1723

0 commit comments

Comments
 (0)