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

Override Colors on Per Theme Basis #70

Open
mike-lloyd03 opened this issue Mar 23, 2022 · 2 comments · May be fixed by #226
Open

Override Colors on Per Theme Basis #70

mike-lloyd03 opened this issue Mar 23, 2022 · 2 comments · May be fixed by #226

Comments

@mike-lloyd03
Copy link

Thanks for this plug. It works really well. Is there a way to override colors on a per-theme basis?

Example: I'd like to override bg1 but only on the dark theme and leave the light theme as default.

require("onedark").setup({
    style = "dark",
    toggle_style_list = { "dark", "light" },
    colors = {
        bg0 = (vim.g.onedark_config.style == "dark") and "#1a1c23" or "#fafafa",
    },
}

This obviously doesn't work because setup configs are only evaluated upon initialization. But some way to do this would be nice.

Thanks!

@dev-msp
Copy link

dev-msp commented Nov 2, 2022

This is possible without an update to the plugin (though it should probably support this use case anyway). You can take advantage of the ColorSchemePre autocmd event to update your plugin config before it's used to apply the theme.

config = function()
  local onedark = require("onedark")
  local default_style = "dark"

  local function get_theme_overrides(style)
    local palette = require("onedark.palette")[style]
    if type(palette) == "nil" then
      vim.notify(string.format("couldn't get palette for style %q", style), vim.log.levels.ERROR)
      return
    end
    return {
      highlights = {
        -- ....
      },
    }
  end

  local augroup_id = vim.api.nvim_create_augroup("OnedarkStyle", {})

  vim.api.nvim_clear_autocmds({ group = augroup_id })
  vim.api.nvim_create_autocmd("ColorSchemePre", {
    group = augroup_id,
    desc = "Apply theme overrides before colorscheme change",
    callback = function()
      if vim.g.onedark_config and vim.g.onedark_config.loaded then
        local overrides = get_theme_overrides(vim.g.onedark_config.style)
        onedark.set_options("highlights", overrides.highlights)
        -- onedark.set_options("colors", overrides.colors)
        -- etc
      end
    end,
  })

  onedark.setup({
    toggle_style_list = { "dark", "light" },
    highlights = get_theme_overrides(default_style).highlights,
  })
  onedark.load()
end

@zhengpd
Copy link

zhengpd commented May 20, 2023

Also like this. It would be easier to set up if onedark has builtin support for per-theme overrides.

@Tom-Hubrecht Tom-Hubrecht linked a pull request Aug 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants