f-person / auto-dark-mode.nvim

A Neovim plugin for macOS, Linux & Windows that automatically changes the editor appearance based on system settings.
GNU General Public License v3.0
299 stars 22 forks source link

flashes during startup #17

Open tomspeak opened 8 months ago

tomspeak commented 8 months ago
return {
  'f-person/auto-dark-mode.nvim',
  priority = 1000,
  lazy = false,

  config = {
    update_interval = 30000,
    set_dark_mode = function()
      vim.api.nvim_set_option('background', 'dark')
    end,
    set_light_mode = function()
      vim.api.nvim_set_option('background', 'light')
    end,
  },
}

With this configuration, if I am in light mode, on startup it will briefly flash in dark mode, then switch to light mode.

Is there a way for me to make it set to the correct value on startup and not have this flash?

nekowinston commented 8 months ago

AFAIK not really, the best workaround I can offer is to use a transparent background, if your Terminal syncs dark/light as well. That way, you won't get the flash for the background at least.

bugabinga commented 7 months ago

This probably happens because Neovim and/or your color scheme set the background to dark before this plugin has a chance to be loaded.

My workaround looks like this:

return {
  'f-person/auto-dark-mode.nvim',
  lazy = false,
  priority = 9999,
  init = function()
      -- Get the current hour
      local current_hour = tonumber( os.date  '%H'  )

      -- Set the background based on the time of day
      if current_hour >= 9 and current_hour < 17 then
        vim.opt.background = 'light'
      else
        vim.opt.background = 'dark'
      end
  end,
  opts = {
    ...
  },
}

This happens to work for me, because my system also changes between light ad dark mode during those hours.

Another alternative could be to vendor the code of this plugin into your configuration and have it run very early, maybe.

alycklama commented 5 months ago

I was able to fix this on my machine by not setting any theme explicitly. I forgot I manually set the theme when loading the theme in Lazy. By removing this, it no longer flashes.

connorjs commented 4 months ago

Setting the vim color scheme as the “base” scheme seems to fix this enough for me. That scheme seems to use terminal colors, so there is no main background flash. YMMV.

vim.cmd.colorscheme("vim")