Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: component does not use custom highlight name #68

Closed
3 tasks done
steschwa opened this issue Jan 21, 2024 · 2 comments
Closed
3 tasks done

bug: component does not use custom highlight name #68

steschwa opened this issue Jan 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@steschwa
Copy link

steschwa commented Jan 21, 2024

Did you check docs and existing issues?

  • I have read all the Feline docs
  • I have searched the existing issues of Feline
  • I have searched the existing issues of plugins related to this issue

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 creates StatusComponent_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 predefined hl.name. My naive approach was to just return the hl.name or generate a new name if none was passed and that seems to work

Steps To Reproduce

  1. Define component (see Repro for complete example):
local p_vi_mode = require("feline.providers.vi_mode")

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
}
  1. Restart Nvim to update config
  2. Check output of :filter /^FelineStatusbarViMode/ highlight which should be empty
  3. Check output of :filter /^StatusComponent_/ highlight which should output the auto-generated hl: StatusComponent_ffffff_ff0000_NONE xxx guifg=#ffffff guibg=#ff0000

Expected Behavior

I would expect that Feline does create a hl for me but uses the predefined name FelineStatusbarViMode instead of the fallback StatusComponent_...

Repro

require("lazy").setup(
    {
        {
            "freddiehaddad/feline.nvim",
            config = function()
                local f = require("feline")

                local p_vi_mode = require("feline.providers.vi_mode")

                local c = {
                    mode = {
                        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
                    }
                }

                local components = {
                    active = {
                        {
                            c.mode
                        }
                    },
                    inactive = {}
                }

                f.setup({components = components})
            end
        }
    }
)
@steschwa steschwa added the bug Something isn't working label Jan 21, 2024
@freddiehaddad
Copy link
Owner

freddiehaddad commented Jan 24, 2024

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",
        },
    }
}

@steschwa
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants