Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theme): theme can be a function #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions doc/styler.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ Install the plugin with your preferred package manager:
themes = {
markdown = { colorscheme = "gruvbox" },
help = { colorscheme = "catppuccin-mocha", background = "dark" },
python = function(buf_path) {
if buf_path:match("cool_project") then
return { colorscheme = "tokyonight-storm" }
else
return { colorscheme = "gruvbox", bakcground = "dark" }
end
}
},
})
end,
Expand Down
5 changes: 3 additions & 2 deletions lua/styler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ M.themes = {}
---@type table<buffer, Theme>
M.bufs = {}

---@alias Theme {colorscheme: string, background?: "light"|"dark"}
---@alias Theme function|{colorscheme: string, background?: "light"|"dark"}
---@alias ThemeHighlights table<string, table>

---@param win window window id or 0 for the current window
Expand Down Expand Up @@ -42,7 +42,8 @@ function M.update(opts)
local buf = vim.api.nvim_win_get_buf(win)
if not (opts.buf and opts.buf ~= buf) then
local ft = vim.bo[buf].filetype
local theme = M.bufs[buf] or M.themes[ft]
local theme = M.bufs[buf]
or (type(M.themes[ft]) == "function" and M.themes[ft](vim.api.nvim_buf_get_name(buf)) or M.themes[ft])
if theme then
M.set_theme(win, theme)
else
Expand Down
Loading