nordic.nvim icon indicating copy to clipboard operation
nordic.nvim copied to clipboard

Feat: Improve changing palette and extended palette

Open AlexvZyl opened this issue 11 months ago • 4 comments

We need a better way to reliably override the palette and extended palette.

We should take inspiration from how tokyonight does it:

https://github.com/folke/tokyonight.nvim/blob/fbe3a27378fdd51a8ddd04f57012455436916a62/lua/tokyonight/theme.lua#L873 https://github.com/folke/tokyonight.nvim/blob/fbe3a27378fdd51a8ddd04f57012455436916a62/lua/tokyonight/colors.lua#L158

AlexvZyl avatar Mar 23 '24 18:03 AlexvZyl

Questions:

  1. what should be the functions be named? I will go with on_palette & on_highlight for now.

  2. should the arguments passed to on_palette & on_highlight be stateful? So should changes made in a first call to on_palette be reflected in the arguments passed to a second call?

So I will start implmenting:

-- This callback can be used to override the colors used in the palette.
    on_palette = function(palette) return palette end,
-- This callback can be used to override highlights before they are applied.
    on_highlight = function(highlights, palette) return highlights end,

5-pebbles avatar Mar 24 '24 16:03 5-pebbles

I think I am going to have to think on this one for a few days.

override allows you to set any highlights like tokyonight's on_highlights... but it would be nice if users could set colors like bg which are used internally.

What about using more highlight linking? So make a highlight group for bg and then all backgrounds link to that? Then in override / on_highlight(or whatever I call it) you could change the Background, Visual, etc... highlight and those changes would be reflected everywhere.

5-pebbles avatar Mar 24 '24 17:03 5-pebbles

This is my best idea so far: 26f9c4a

5-pebbles avatar Mar 25 '24 15:03 5-pebbles

I think this is the best solution changing_palette

using the base palette works the same as normal, and you can set values in the extended palette just as you would the base palette.

You can even use values in the extended palette but they will be nil for the fist call:

#100 can be solved with 3 lines:

            on_palette = function(palette)
                -- the if is needed because on_palette is called twice and one time palette.bg is nil which breaks blend
                if palette.bg ~= nil then
                    palette.bg_visual = require("nordic.utils").blend(palette.orange.base, palette.bg, 0.15)
                end
                return palette
            end,

25-03-24@19:33:46

 

I am not sure about on_highlight but I think it is better for the future (because the plugin provides the palette).

I will re add support for override + add a deprecated warning on launch... then I will open a PR.

5-pebbles avatar Mar 25 '24 19:03 5-pebbles