Closed steschwa closed 9 months ago
Hello @steschwa, thanks for posting. I think I'm a little confused by the bug report. When using a highlight name (i.e. string), the intention is that the highlight has already been defined and you want to use it for the component.
For example, if you used nvim_set_hl
to create the highlight group FelineStatusbarViMode
then you would reference it in the component hl config:
local c = {
mode = {
provider = function()
return string.format(" %s ", p_vi_mode.get_vim_mode())
end,
hl = 'FelineStatusbarViMode'
}
}
If you're wanting feline to handle the highlight for the component, specifying a name doesn't really matter since it will be created internally and used for the life of the component.
All you really need to provide is the fg
, bg
, and style
properties for the hl
to achieve what you need (at least in the example).
I agree that this part is a little confusing as an example and might possibly be incorrect. Perhaps this was how the highlighting used to work at some point. I will look through the code to try and understand what the objective here is:
-- As a function returning a table hl = function() return { name = require('feline.providers.vi_mode').get_mode_highlight_name(), fg = require('feline.providers.vi_mode').get_mode_color(), style = 'bold' } end
Is something not not working? From what I see in your example, all you need for the component is:
local c = {
mode = {
provider = function()
return string.format(" %s ", p_vi_mode.get_vim_mode())
end,
hl = {
fg = "#ffffff",
bg = "#ff0000",
},
}
}
Oh yeah i think i just got confused by the example. My understanding was that
"if i specify a name, feline uses that name to generate a hl group (using fg
/bg
and style
)".
Using a name
key when hl
is a table doesn't make much sense then i guess.
Thanks for clarification
Did you check docs and existing issues?
Neovim version (nvim -v)
0.9.5
Operating system/version
macOS 14.2
Describe the bug
Setting a custom provider highlight name using a function does create a highlight name using it's other properties (e.g.
fg
/bg
) instead of using the predefined name.The example in USAGE.md doesn't work either. The Name of the hl should be something like
StatusComponentVim...
(according to https://github.com/freddiehaddad/feline.nvim/blob/main/lua/feline/providers/vi_mode.lua#L56) but rather createsStatusComponent_60A040_1F1F23_bold
TLDR: After some digging around i found
function parse_hl
https://github.com/freddiehaddad/feline.nvim/blob/main/lua/feline/generator.lua#L120, which just ignores the predefinedhl.name
. My naive approach was to just return thehl.name
or generate a new name if none was passed and that seems to workSteps To Reproduce
local vi_mode_component = { provider = function() return string.format(" %s ", p_vi_mode.get_vim_mode()) end, hl = function() return { name = "FelineStatusbarViMode" .. p_vi_mode.get_mode_highlight_name(), fg = "#ffffff", bg = "#ff0000" } end }