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

Plugin assumes RGB colors => does not support cterm colors (from 256 color palette) #36

Closed
bew opened this issue Jun 5, 2022 · 6 comments · Fixed by #157
Closed

Plugin assumes RGB colors => does not support cterm colors (from 256 color palette) #36

bew opened this issue Jun 5, 2022 · 6 comments · Fixed by #157

Comments

@bew
Copy link

bew commented Jun 5, 2022

Hello!

I'm in the process of converting my old nvim config to Lua, and rewriting most of my config.
I've chosen heirline for the statusline, I love what you did with it!

I noticed that the highlighting system assume we're using RGB colors, but in my case I want to only use colors from the 256 color palette.

>>> preview of the available colors, from 0 to 255 <<<

image
(this palette has been generated using https://github.com/guns/xterm-color-table.vim)

I actually prefer using these than using RGB colors, because 256 colors are largely enough for me, and RGB actually give to much choice for my taste..


FYI highlights in 256 color mode are given using ctermfg, ctermbg and cterm (for the style)
Read more at :h highlight-args

I quickly looked at your code, the highlight is created here:

vim.api.nvim_set_hl(0, hl_name, hl)

that function does accept cterm* params.

I tested this:

lua vim.api.nvim_set_hl(0, "TestGroup", {cterm={bold = true}, ctermbg=124, ctermfg=255})
hi TestGroup

and the output is:
image

👉 I think the simplest implementation in heirline would be to accept (and merge them as necessary) the new fields cterm, ctermbg & ctermfg in the hl component property.
(the implementation of name_hl would also need to take this into account)

What do you think ?

@bew bew changed the title colors from the 256color palette do not work (RGB colors are implied) Plugin assumes RGB colors => does not support cterm colors (from 256 color palette) Jun 5, 2022
@rebelot
Copy link
Owner

rebelot commented Jun 6, 2022

you can use 256 color names (i.e https://www.ditig.com/256-colors-cheat-sheet)

{
    provider = 'AbraCadabra!',
    hl = { fg = "LightGoldenrod1", bg = "CornflowerBlue"}
}

@rebelot rebelot closed this as completed Jun 6, 2022
@bew
Copy link
Author

bew commented Jun 6, 2022

Interesting but unfortunately no, it doesn't work as it sets the guifg & guibg fields, not the cterm* fields:
image

And the resulting statusline, if using your example as a statusline:
image

I didn't enable RGB support in neovim and my terminal, and would much prefer to have my tools use 256 terminal colors than RGB ones.
Do you see what I mean?

@rebelot rebelot reopened this Jun 6, 2022
@rebelot
Copy link
Owner

rebelot commented Jun 6, 2022

I see, I thought you only needed a convenient way to indicate 8 bit colors.

I'll think about it.

@rebelot rebelot closed this as completed in 60d92a6 Jun 7, 2022
@bew
Copy link
Author

bew commented Jun 7, 2022

Thanks a lot!

I tried using this:

  require"heirline".setup({
    { provider = "before " },
    {
      provider = "%f",
      hl = { cterm = {italic = true}, ctermfg = 123 },
    },
    { provider = " after" },
  })

And I get:
image

👉 I'd have expected to not have any background colors, and have the same default white everywher.

I'm not sure if the behavior is intended or not.. is it because statusline highlights need to always have a background?
What would be the proper way to fix that if it's intended?

@rebelot
Copy link
Owner

rebelot commented Jun 7, 2022

is it because statusline highlights need to always have a background?

It's not they need, it's just the way vim handles highlights, if you don't provide a background color you won't have one. Commonly, one wants some default colors tho, here's an example.

All highlights will be recursively merged, so foreground will be overwritten, but if no background is provided, the default one will be used.

 require"heirline".setup({
    hl = function()
        if conditions.is_active() then
            return "StatusLine"
        else
            return "StatusLineNC"
        end
    end,
    { provider = "before " },
    {
      provider = "%f",
      hl = { cterm = {italic = true}, ctermfg = 123 },
    },
    { provider = " after" },
  })

@bew
Copy link
Author

bew commented Jun 7, 2022

Makes sense!

As for the weird black background, it was actually an issue with my theme.. I really have no idea why I had soo many cterm=reverse in it.. it messes up everything!! (now I have 0 left ^^)

Thanks a lot again for the examples and the plugin, it's great \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants