EdenEast / nightfox.nvim

🦊A highly customizable theme for vim and neovim with support for lsp, treesitter and a variety of plugins.
MIT License
2.91k stars 136 forks source link

feature: Switch between dark and light variants #369

Open ifab opened 10 months ago

ifab commented 10 months ago

Is your feature request related to a problem? Please describe.

Many popular Neovim themes automatically choose between a dark and a light variant, depending on whether vim.o.background is set to "dark" or "light". This is very useful if one frequently switches between a dark and a light theme in the terminal. Currently, Nightfox seems to be missing this feature.

Describe the solution you'd like

The solution implemented in Catppuccin, for example, is great. It provides the following configuration option:

background = { -- :h background
    light = "latte",
    dark = "mocha",
},

Other themes such as TokyoNight and Kanagawa have similar options.

Describe alternatives you've considered

I currently use the following workaround, which is far from ideal:

vim.api.nvim_create_autocmd({ "VimEnter" }, {
  callback = function()
    vim.cmd("sleep 1m")
    if vim.o.background == "dark" then
      vim.cmd("colorscheme nightfox")
    else
      vim.cmd("colorscheme dayfox")
    end
  end,
})

Additional context

No response

EdenEast commented 10 months ago

Hi there,

Firstly, thank you for reaching out with your suggestions for Nightfox!

However, I want to clarify a few things about Nightfox's current structure. As it stands, Nightfox differs from the other styles you've mentioned in a fundamental way. The main issue is that Nightfox doesn't have a concept of a style or variant. In contrast, the other color schemes you referred to can change their primary theme based on a configuration setting. For instance, invoking catppuccin might yield either a mocha or latte theme, depending on a config option.

Nightfox, on the other hand, has distinct, standalone color schemes. When you call colorscheme nightfox, it will consistently apply the Nightfox theme. I are hesitant to introduce a configuration option that could make the call to Nightfox ambiguous regarding the actual color scheme applied.

ifab commented 10 months ago

Thanks for your quick response! I understand that you do not want to introduce any ambiguity into the interface.

So maybe it is better if I ask the following question: What is the recommended way to automatically switch between two colorschemes, say Nightfox and Dayfox, depending on the value of vim.o.background?

I'm not too happy with my current workaround solution (mentioned above) because:

EdenEast commented 10 months ago

When you use the command colorscheme vim checks the colors folder in your runtimepath (example). Using this you could create your own file and call that instead of the ones shipped with nightfox.

-- ~/.config/nvim/colors/something.lua

local style = vim.o.background == "light" and "dayfox" or "nightfox"
require("nightfox.config").set_fox(name)
require("nightfox").load()

Then you can call colorscheme something and that file will be applied.

Just an idea on how I would handle this use case.

ifab commented 10 months ago

Thanks for the suggestion! Unfortunately this does not seem to work. The selected colorscheme is always Nightfox, regardless of the terminal background color. I think the reason is that Neovim sets vim.o.background too late (see this issue). This is why the workaround mentioned above is inside a VimEnter handler and also adds an additional delay.

I guess I will keep using the workaround for the time being. But just out of curiosity, how do you make use of your different colorschemes? Do you just switch them manually, or perhaps always use the same?

EdenEast commented 10 months ago

I have what some would say an overly complicated setup for handling themes. I create an autocmd at startup on the event ColorScheme that registers a hook. That hook will write the name of the colorscheme getting appiled to a text file. I then load my plugins, and after apply my theme based on that text file.

As for syncing my theme with my terminal I have a shell script that I use to write to all the appropriate places. I use wezterm as my terminal so when I make the change to the wezterm config it will hot reload the change. That script also writes to that neovim theme cache file. This means that if I am on my laptop outside and I need a light theme I call tcc dayfox and everything is now light theme.

You can find my dotfiles in the repo nyx (another way to say nix). My config is built around nix but you can find my config files for nvim here.

Hope you find some of these ideas interesting.

ifab commented 10 months ago

Thank you very much for the detailed reply, I really appreciate the time you took to answer my questions! Indeed your setup seems a bit complicated, but now I understand why you have no personal need for the feature described above.

Anyway, just in case you want to provide this feature in nightfox.nvim some day, here is a suggestion for the user interface that avoids the ambiguity you mentioned. It's basically just a variation of your own idea:

abmantis commented 5 months ago

I have a script with gsettings --monitor to react on changes to the global dark/light mode, and that toggles nvim color by using the background setting: https://github.com/abmantis/hypr.dotfiles/blob/main/scripts/color_scheme_handler.sh#L4

It would be great if this theme would support that, as it makes that a generic solution so I can manage themes inside nvim config, without having to change that script too

angelidis commented 3 months ago

the metafox idea from ifab is really good.

i think a lot of us are used from websites/phones where you can switch between dark and light themes easily depending on time of the day or surrounding lighting conditions.

please consider adding this!

regardless, the whole nightfox collection is amazing -- thank you for all your work!