Closed stevenxxiu closed 10 months ago
Hey Steven! Thank you for your contribution. There are two remarks about the change you suggest:
- local name = 'HWS_' .. color:gsub('[^a-zA-Z0-9_.@-]', '')
+ local name = 'HWS_' .. color:gsub('[^a-zA-Z0-9_.@]', '')
- local name = 'HWS_' .. color:gsub('[^a-zA-Z0-9_.@]', '')
+ local name = 'HWS_' .. color:gsub('#', '')
A user can set a color name that contains any char. However, it is better to warn that it will not work than removing invalid chars and ending up with not working highlighting (though there will be no errors in such case)
A better solution will be to strip '#' in core.lua
file
# core.lua
+ local name = 'HWS_' .. valid_color(color)
And to check in init.lua
user provided palette on valid colors with something like this function
# init.lua
+local function valid_color(color)
+ return api.nvim_get_color_by_name(color) ~= -1
+end
I think I can finish this pull request tomorrow. I was going to rework init.lua
anyway
@stevenxxiu, I can merge your pull request if you change it to
+ local name = 'HWS_' .. color:gsub('#', '')
Or I can merge the one below if you prove that it is better (e.g., by providing ways to set valid colors with '@' in the name)
+ local name = 'HWS_' .. color:gsub('[^a-zA-Z0-9_.@]', '')
Hi Vladislav!
The reason I changed this is due to your call to vim.fn.matchadd()
. The first argument is a group name. Per Syntax - Neovim docs, the only valid group names are [a-zA-Z0-9_.@-]*
.
Looking at https://neovim.io/doc/user/syntax.html#guifg, all the valid color names appear to work as group names, except the character #
.
Which colors have a @
in them? I think my code works with @
, as it only removes characters that aren't valid group names.
Or perhaps the group name can be generated separately from the color name?
Yep, Syntax - Neovim docs say that the only valid group names are [a-zA-Z0-9_.@-]*
. However, they might be out of date :( Since I tested group names containing dash char -
, and Neovim complained about it. So experimentally [^a-zA-Z0-9_.@]
is the right regex for substitution.
Anyway, I prepared an update that handles hex codes and wrong color group names. Sadly, but it means that it would have rewritten your PR completely, even if had merged it. But I'll think about how to say my thanks to you. Because I really appreciate your contribution!
This gives support to
#RRGGBB
colors, such as Catppuccin's Latte flavor's background color of#eff1f5
.