rktjmp / lush.nvim

Create Neovim themes with real-time feedback, export anywhere.
MIT License
1.4k stars 46 forks source link

Following the guide to configure an existing theme removes icon colors #118

Closed rorystephenson closed 1 year ago

rorystephenson commented 1 year ago

Following this section of the guide to configure an existing theme caused icon colours to disappear for me.

Setting the force_clean options resolves it for me as follows:

lush(spec, {force_clean = false})

However this seems to break some other colors.

EDIT:

I've found a solution that seems to work:

  lush(function()
    return spec
  end)

I'm not sure why (I'm totally new to lush and lua) but this brings back the icon colors and doesn't break other colors.

rktjmp commented 1 year ago

Is that not the same as the guide, without attaching it to _G?

-- You may prefer to put this in its own module, shown on _G for brevity.
_G.customise_colorscheme = function()
  -- now we can apply the modified spec.
  lush(spec)
end

I'm also not sure what icon colors are specifically, from a plugin?

rorystephenson commented 1 year ago

Actually on re-checking my problems are not resolved.

I'm also not sure what icon colors are specifically, from a plugin?

Yeah sorry the icons are in nvim-tree (I have webdev icons installed and they work fine when not using a lush theme).


So the issue remains that when I follow the instructions to configure an existing theme it removes the icon colors for me.

EDIT:

In case it's helpful my autocmd declaration is:

vim.api.nvim_create_autocmd({ "VimEnter", "ColorScheme" }, { callback = customise_colorscheme })
rktjmp commented 1 year ago

Ah, that documentation is for extending a lush theme - something that exports all the group information, are you extending a non-lush theme? What theme are you extending?

rorystephenson commented 1 year ago

I am extending this lush theme as follows:

-- Apply the theme
vim.cmd 'colorscheme darcula-solid'

-- First we will need lush, and the colorscheme we wish to modify
local lush = require('lush')
local darcula_solid = require('lush_theme.darcula-solid')
local spec = lush.extends({darcula_solid}).with(function()
  -- Pallete copied from https://github.com/briones-gabriel/darcula-solid.nvim/blob/main/lua/lush_theme/darcula-solid.lua
  local fg      = lush.hsl(210, 7, 82)
  local yellow  = lush.hsl(37, 100, 71)

  return {
    Type { fg = yellow },
    Function { fg = fg },
  }
end)

-- Place theme modification callback in module to make it private.
_G.customise_colorscheme = function()
  -- Apply the modified spec.
  lush(function()
    return spec
  end)
end

-- Apply theme modificatio
vim.api.nvim_create_autocmd({ "VimEnter", "ColorScheme" }, { callback = customise_colorscheme })

Calling lush in this way is not working as my modifications are not applied whilst if I change it to lush(spec) my modifications work but the icon colors disappear.

rktjmp commented 1 year ago

I believe this works for me, but its a bit ugly and I don't recommend it.


require("nvim-tree").setup()
_G.customise_colorscheme = function()
  -- Apply the modified spec.
  lush(spec)
  -- trigger colorscheme changed events which nvim-tree will see and adjust its theme
  vim.api.nvim_exec_autocmds("ColorScheme", {})
end
-- Removed ColorScheme so we don't recursively loop
vim.api.nvim_create_autocmd({"VimEnter" }, { callback = customise_colorscheme })

With the previous method, nvim-tree would sometimes fire its "colorscheme changed" handler before or after we adjusted the colors, so it was a bit wonky.

That example is probably too thin really, I think you're better off creating a colorscheme in the way vim expects.

-- ~/.config/nvim/colors/roryula.lua
-- See create.md and lush-template for more details
-- set some colorscheme detains, normal vim stuff
vim.opt.background = 'dark'
vim.g.colors_name = 'roryula'

-- We can just require the top theme and do our modifications,
local lush = require('lush')
local darcula_solid = require('lush_theme.darcula-solid')
local spec = lush.extends({darcula_solid}).with(function()
  -- Pallete copied from https://github.com/briones-gabriel/darcula-solid.nvim/blob/main/lua/lush_theme/darcula-solid.lua
  local fg      = lush.hsl(210, 7, 82)
  local yellow  = lush.hsl(37, 100, 71)

  return {
    Type { fg = yellow },
    Function { fg = fg },
  }
end)

-- this call is the equivalent to require('lush')(require('theme...'))
-- but we can do it all in one file.
lush(spec)

then

:colorscheme roryula or vim.cmd("colorscheme roryula") in your config, etc.

I will update the documentation to follow this pattern, its much better.

rktjmp commented 1 year ago

Also not sure if it's clear from the docs, but the darcula_solid variable is actually a table containing all the group data, so you can write

    Function { fg = darcula_solid.Normal.fg },

To set Function to whatever the upstream sets for Normal.fg, and you can chain that with any color operations too (eg: darcula_solid.Normal.fg.darken(10), etc)

rorystephenson commented 1 year ago

That's all working perfectly now and it's a much cleaner approach, thank you very much!