projekt0n / github-nvim-theme

GitHub's Neovim themes
MIT License
2.07k stars 106 forks source link

Autocommand to toggle light and dark mode #233

Closed fedemengo closed 1 year ago

fedemengo commented 1 year ago

It would be nice if by toggling vim.o.background to light/dark the theme would automatically set the appropriate colorscheme

In my config I create an [autocmd](https://neovim.io/doc/user/api.html#nvim_create_autocmd()) to do that, I don't know if this is the best way to do it

(fn toggle [ev]
  (vim.cmd (.. "colorscheme github_" (. vim.o :background) "_default")))

(vim.api.nvim_create_autocmd ["OptionSet"] {
  :pattern ["background"]
  :callback toggle })
paldepind commented 1 year ago

I agree. It would be nice if the theme didn't have several "github_light" and "github_dark" variants but just respected the background option instead.

ful1e5 commented 1 year ago

@fedemengo @paldepind

Using this user command, you can toggle the colorscheme to the appropriate opposite variant, apart from the github_dark_dimmed variant using :ToggleGithubTheme.

vim.api.nvim_create_user_command('ToggleGithubTheme', function()
  local colo = vim.g.colors_name
  if colo:find('dimmed') then
    vim.cmd('colorscheme github_light')
  elseif colo:find('dark') then
    vim.cmd('colorscheme ' .. colo:gsub('dark', 'light'))
  else
    vim.cmd('colorscheme ' .. colo:gsub('light', 'dark'))
  end
end, {})
paldepind commented 1 year ago

@ful1e5 Sorry, but this doesn't really address the original issue. The theme still does not take Vim's background value into account as far as I can tell. Great theme otherwise 👍

towry commented 5 months ago

@fedemengo @paldepind

Using this user command, you can toggle the colorscheme to the appropriate opposite variant, apart from the github_dark_dimmed variant using :ToggleGithubTheme.

vim.api.nvim_create_user_command('ToggleGithubTheme', function()
  local colo = vim.g.colors_name
  if colo:find('dimmed') then
    vim.cmd('colorscheme github_light')
  elseif colo:find('dark') then
    vim.cmd('colorscheme ' .. colo:gsub('dark', 'light'))
  else
    vim.cmd('colorscheme ' .. colo:gsub('light', 'dark'))
  end
end, {})

How does this solve the original issue?