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]: Does not respect ctermbg/ctermfg settings #788

Open
1 task done
FalcoGer opened this issue Jul 11, 2023 · 6 comments
Open
1 task done

[Bug]: Does not respect ctermbg/ctermfg settings #788

FalcoGer opened this issue Jul 11, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@FalcoGer
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

The issue is that the documentation says one should set the ctermbg and ctermfg colors with this format.

When `termguicolors` is not enabled, a user is expected to specify colour values
similar to the format above (use `ctermbg` and `ctermfg` instead). A user can
also directly specify [colour
numbers](https://www.ditig.com/256-colors-cheat-sheet).

for example: >lua
    highlights = {
        fill = {
            ctermbg = 7,
            ctermfg = 0,
        }
    }

This will set the background of the highlight group to gray and foreground to
black. Here the colours are system determined, and the user may have changed
the rgb values through customizing the terminal emulator itself. This is
possible for colour numbers 0-15.

But that doesn't work.

image

As you can see the selected tab text is not in white as specified by tab_selected.ctermfg = 15, none of the other colors work either.

What did you expect to happen?

Use of the specified foreground and background colors instead of the default terminal color, which I have set to green.

Config

local bufferline = require("bufferline")

-- background color definitions
-- same as normal background
local background = '#121212'
local backgroundterm = 233
-- not selected, not visible
local normal = '#262626'
local normalterm = 235
-- visible, not selected
local visible = '#444444'
local visibleterm = 238
-- selected
local selected = '#808080'
local selectedterm = 8

-- foreground colors from Coc for hint, info, warning and error
local hintcolor = '#008080'
local hintcolorterm = 6
local infocolor = '#0000FF'
local infocolorterm = 12
local warningcolor = '#FFFF00'
local warningcolorterm = 11
local errorcolor = '#FF0000'
local errorcolorterm = 9

-- :help bufferline-configuration
bufferline.setup(
{
    options = {
        mode = "buffers",
        separator_style = "slant",
        --[[
        style_preset = {
            bufferline.style_preset.no_italic,
            bufferline.style_preset.no_bold
        },
        ]]--
        numbers = function(opts)
            return string.format('%s|%s', opts.raise(opts.ordinal), opts.raise(opts.id))
        end,
        indicator = {
            style = "underline"
        },
        diagnostics = "coc",
        -- ignore unused parameter
        -- luacheck: push ignore 212
        ---@diagnostic disable-next-line
        diagnostics_indicator = function(count, level, diagnostics_dict, context)
            -- luacheck: pop
            if (count == 0) then
                return ""
            end
            --[[
            if context.buffer:current() then
                return ""
            end
            ]]--
            local icon = '' .. ' ' .. level
            if level:match("error") then
                icon = ''
            elseif level:match("warning") then
                icon = ''
            elseif level:match("info") or level:match("hint") then
                icon = ''
            end
            -- kitty scales down the icon if there is no space on the right
            return icon .. " " .. count
        end,
        hover= {
            enabled = true,
            delay = 0,
            reveal = {"close"}
        },
        close_icon = '',
        buffer_close_icon = '',
        show_tab_indicators = true,
        show_duplicate_prefix = true,
        always_show_bufferline = true,
        name_formatter = function(buf)
            if (buf.buffers == nil) then
                -- it's a buffer
                return buf.name
            end
            -- it's a tab
            local count = 0
            for _ in pairs(buf.buffers) do count = count + 1 end
            return string.format('%d %d ', vim.api.nvim_tabpage_get_number(buf.tabnr), count)
        end,
        offsets = {
            {
                filetype = "NvimTree",
                text = function()
                    return vim.fn.getcwd()
                end,
                highlight = "Directory",
                text_align = "left"
            }
        },
        themable = true,
    }, -- end options
    highlights = { -- help bufferline-highlights
        fill = {
            bg = background,
            ctermbg = backgroundterm
        },
        tab = { -- non selected tab
            bg = normal,
            ctermbg = normalterm,
            fg = '#808080',
            ctermfg = 8
        },
        tab_separator = { -- non selected tab separators
            bg = normal, -- this is inside the "tab"
            ctermbg = normalterm,
            fg = background, -- actual corner piece, blends into background
            ctermfg = backgroundterm
        },
        tab_selected = { -- selected tab
            bg = selected,
            ctermbg = selectedterm,
            fg = '#FFFFFF',
            ctermfg = 15
        },
        tab_separator_selected = { -- selected tab separators
            bg = selected,
            ctermbg = selectedterm,
            fg = background,
            ctermfg = backgroundterm
        },
        background = { -- non visible, non selected buffers
            bg =normal,
            ctermbg = normalterm
        },
        separator = {
            bg = normal,
            ctermbg = normalterm,
            fg = background,
            ctermfg = backgroundterm
        },
        buffer_visible = { -- buffer visible, but not selected
            bg = visible,
            ctermbg = visibleterm
        },
        separator_visible = {
            bg = visible,
            ctermbg = visibleterm,
            fg = background,
            ctermfg = backgroundterm
        },
        buffer_selected = {
            bg = selected,
            ctermbg = selectedterm
        },
        separator_selected = {
            bg = selected,
            ctermbg = selectedterm,
            fg = background,
            ctermfg = backgroundterm
        },
        modified = {
            bg = normal,
            ctermfg = normalterm
        },
        modified_visible = {
            bg = visible,
            ctermbg = visibleterm
        },
        modified_selected = {
            bg = selected,
            ctermbg = selectedterm
        },
        duplicate = {
            strikethrough = true
        },
        duplicate_visible =
        {
            strikethrough = true
        },
        duplicate_selected = {
            strikethrough = true
        },
        diagnostic = {
            bg = normal,
            ctermbg = normalterm
        },
        diagnostic_visible = {
            bg = visible,
            ctermbg = visibleterm
        },
        diagnostic_selected = {
            bg = selected,
            ctermbg = selectedterm
        },
        close_button = {
            bg = normal,
            ctermbg = normalterm
        },
        close_button_visible = {
            bg = visible,
            ctermbg = visibleterm
        },
        close_button_selected = {
            bg = selected,
            ctermbg = selectedterm
        },
        numbers = {
            bg = normal,
            ctermbg = normalterm
        },
        numbers_visible = {
            bg = visible,
            ctermbg = visibleterm
        },
        numbers_selected = {
            bg = selected,
            ctermbg = selectedterm
        },
        hint = {
            bg = normal,
            ctermbg = normalterm,
            sp = hintcolor,
            undercurl = true
        },
        hint_visible = {
            bg = visible,
            ctermbg = visibleterm,
            sp = hintcolor,
            undercurl = true
        },
        hint_selected = {
            bg = selected,
            ctermbg = selectedterm,
            sp = hintcolor,
            undercurl = true
        },
        hint_diagnostic = {
            bg = normal,
            ctermbg = normalterm,
            fg = hintcolor,
            ctermfg = hintcolorterm
        },
        hint_diagnostic_visible = {
            bg = visible,
            ctermbg = visibleterm,
            fg = hintcolor,
            ctermfg = hintcolorterm
        },
        hint_diagnostic_selected = {
            bg = selected,
            ctermbg = selectedterm,
            fg = hintcolor,
            ctermfg = hintcolorterm
        },
        info = {
            bg = normal,
            ctermbg = normalterm,
            sp = infocolor,
            undercurl = true
        },
        info_visible = {
            bg = visible,
            ctermbg = visibleterm,
            sp = infocolor,
            undercurl = true
        },
        info_selected = {
            bg = selected,
            ctermbg = selectedterm,
            sp = infocolor,
            undercurl = true
        },
        info_diagnostic = {
            bg = normal,
            ctermbg = normalterm,
            fg = infocolor,
            ctermfg = infocolorterm
        },
        info_diagnostic_visible = {
            bg = visible,
            ctermbg = visibleterm,
            fg = infocolor,
            ctermfg = infocolorterm
        },
        info_diagnostic_selected = {
            bg = selected,
            ctermbg = selectedterm,
            fg = infocolor,
            ctermfg = infocolorterm
        },
        warning = {
            bg = normal,
            ctermbg = normalterm,
            sp = warningcolor,
            undercurl = true
        },
        warning_visible = {
            bg = visible,
            ctermbg = visibleterm,
            sp = warningcolor,
            undercurl = true
        },
        warning_selected = {
            bg = selected,
            ctermbg = selectedterm,
            sp = warningcolor,
            undercurl = true
        },
        warning_diagnostic = {
            bg = normal,
            ctermbg = normalterm,
            fg = warningcolor,
            ctermfg = warningcolorterm
        },
        warning_diagnostic_visible = {
            bg = visible,
            ctermbg = visibleterm,
            fg = warningcolor,
            ctermfg = warningcolorterm
        },
        warning_diagnostic_selected = {
            bg = selected,
            ctermbg = selectedterm,
            fg = warningcolor,
            ctermfg = warningcolorterm
        },
        error = {
            bg = normal,
            ctermbg = normalterm,
            sp = errorcolor,
            undercurl = true
        },
        error_visible = {
            bg = visible,
            ctermbg = visibleterm,
            sp = errorcolor,
            undercurl = true
        },
        error_selected = {
            bg = selected,
            ctermbg = selectedterm,
            sp = errorcolor,
            undercurl = true
        },
        error_diagnostic = {
            bg = normal,
            ctermbg = normalterm,
            fg = errorcolor,
            ctermfg = errorcolorterm
        },
        error_diagnostic_visible = {
            bg = visible,
            ctermbg = visibleterm,
            fg = errorcolor,
            ctermfg = errorcolorterm
        },
        error_diagnostic_selected = {
            bg = selected,
            ctermbg = selectedterm,
            fg = errorcolor,
            ctermfg = errorcolorterm
        },
    }
})

Additional Information

Terminal is kitty 0.28.1 created by Kovid Goyal
nvim is NVIM v0.10.0-dev-5ceb2238d - Release - LuaJIT 2.1.0-beta3
OS is Linux <hostname goes here> 5.15.0-75-generic #82-Ubuntu SMP Tue Jun 6 23:10:23 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Release is Ubuntu 22.04 LTS

Not sure if it ever worked, but I only checked the most recent version, see below.

commit

bf2f6b7

@FalcoGer FalcoGer added the bug Something isn't working label Jul 11, 2023
@FalcoGer
Copy link
Author

I'd usually use set termguicolor, but that doesn't work with asciinema

@akinsho
Copy link
Owner

akinsho commented Jul 11, 2023

Hi @FalcoGer,

I'm not entirely clear what I'm seeing in the screenshot, there is quite a lot going on there and I don't know what I'm supposed to be picking out.

That being said, the addition of cterm colours was entirely done by a user who was very keen on having this support in bufferline. I do not use them did not write the docs for them and frankly have never had to fiddle with them before. I know next to nothing about them really and have always used termguicolors which hex values and designed this plugin very much around that. I don't know if many users who use cterm colors are using his addition of these changes successfully or not I've never heard from anyone about that.

I personally was reluctant accept his PR for this exact reason i.e. someone would one day appear asking me a bunch of questions about cterm colours. I'm happy to take more contributions if you dig into the code and find there is a bug or issue but AFAIK this functionality should be working unless there was a regression which is possible.

TLDR please feel free to contribute a fix as someone who uses this. For my own part this is something I don't get many requests about and that I fully don't use.

EDIT: Whilst I'm unlikely to personally get involved I can
a) help guide you to the areas of code that might be relevant e.g. highlight.lua
b) I think if the problem was more clearly stated with a simple example I could test with that would be a worthwhile starting point but as I mentioned tbh I'm more inclined to deprecate this support to avoid future issues about it than to really dig into it.

@FalcoGer
Copy link
Author

FalcoGer commented Jul 11, 2023

What's important in the screenshot is that the text in bufferline is green on dark gray background, when I have explicitly set it to white on gray. I use the same colors for cterm as I do for guiterm, so it really ought to look like this instead.

image

Maybe I'm doing something wrong though.

@rbjorklin
Copy link

I'm seeing something similar where my separators are coming back light instead of dark.

Screenshot from 2023-09-17 16-15-19

@jjo93sa
Copy link

jjo93sa commented Mar 30, 2024

Me too, this is a very confusing behaviour
Screenshot 2024-03-30 at 16 30 52
The problem I'm having is getting the separators to "disappear" into the background so the tabs look slanted

@tienbuigia
Copy link

I have this around area, padding like that doesn't respect the colors I set.
20240425_01h44m57s_grim

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

5 participants