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

Autocommand to toggle light and dark mode #233

Closed
fedemengo opened this issue Feb 7, 2023 · 4 comments
Closed

Autocommand to toggle light and dark mode #233

fedemengo opened this issue Feb 7, 2023 · 4 comments
Assignees
Labels
assigned Under progress. documentation Improvements or additions to documentation
Projects

Comments

@fedemengo
Copy link

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 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
Copy link

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 ful1e5 self-assigned this May 7, 2023
@ful1e5 ful1e5 added documentation Improvements or additions to documentation assigned Under progress. labels May 7, 2023
@ful1e5 ful1e5 added this to To do in Workboard via automation May 7, 2023
@ful1e5 ful1e5 moved this from To do to In progress in Workboard May 7, 2023
@ful1e5
Copy link
Member

ful1e5 commented May 8, 2023

@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, {})

@ful1e5 ful1e5 closed this as completed May 10, 2023
Workboard automation moved this from In progress to Done May 10, 2023
@paldepind
Copy link

@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

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assigned Under progress. documentation Improvements or additions to documentation
Projects
Development

No branches or pull requests

4 participants