folke / tokyonight.nvim

🏙 A clean, dark Neovim theme written in Lua, with support for lsp, treesitter and lots of plugins. Includes additional themes for Kitty, Alacritty, iTerm and Fish.
Apache License 2.0
6.25k stars 414 forks source link

bug: terminal color too late #591

Closed cathaysia closed 2 months ago

cathaysia commented 2 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0

Operating system/version

Linux dragon 6.9.7-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 27 18:11:45 UTC 2024 x86_64 GNU/Linux

Describe the bug

here: https://github.com/folke/tokyonight.nvim/blob/0a84c2df1dc65610ee0d9b516b2fb342e4b0ed6f/lua/tokyonight/theme.lua#L26

delay the setting of terminal_colors, this results in the vim.g.terminal_color_0 not being set when the ColorScheme event is triggered.

Unfortunately my plugin currently relies on these values. I know tokyonight provides some APIs to let me get its color directly, but I have some other themes, so I am not inclined to use fixed colors.

Considering that the this function should be only run once, is a synchronous setup also acceptable?

Steps To Reproduce

  1. checkout main
  2. add log for nvim:
vim.api.nvim_create_autocmd({ 'ColorScheme' }, {
    callback = function()
        print(vim.g.terminal_color_0)
    end()

Expected Behavior

vim.g.terminal_color_0 != nil

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here