auto-dark-mode.nvim icon indicating copy to clipboard operation
auto-dark-mode.nvim copied to clipboard

flashes during startup

Open tomspeak opened this issue 1 year ago • 4 comments

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?

tomspeak avatar Feb 03 '24 13:02 tomspeak

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.

nekowinston avatar Feb 03 '24 13:02 nekowinston

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.

bugabinga avatar Feb 27 '24 17:02 bugabinga

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.

alycklama avatar Apr 19 '24 17:04 alycklama

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")

connorjs avatar May 18 '24 18:05 connorjs