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

Setting foreground to "NONE" on component is ignored #151

Closed
miversen33 opened this issue Jul 29, 2023 · 10 comments
Closed

Setting foreground to "NONE" on component is ignored #151

miversen33 opened this issue Jul 29, 2023 · 10 comments

Comments

@miversen33
Copy link
Contributor

To start, here is a screenshot showing the issue
image

This is accomplished with the following cokeline configuration

vim.api.nvim_set_hl(0, 'BufferLineFill', { fg = 'NONE', bg = 'NONE' })
require("cokeline").setup({
    fill_hl = "BufferLineFill",
    default_hl = {
        fg = "NONE",
        bg = "NONE"
    },
    components = {
        {
            text = function(buffer)
                return
                buffer.is_focused and ""
                or " "
            end,
            fg = "NONE",
            bg = "NONE"
        },
        {
            text = function(buffer) return buffer.filename .. ' ' end,
            style = function(buffer)
                if buffer.is_hovered and not buffer.is_focused then
                    return 'underline'
                end
            end
        },
    }
})

I would expect this to set the Foreground of the first component to NONE as that is what I am actively telling it to do. However it is being overriden by something.

Below is a repo lua config that can be used to recreate this issue

-- Minimal configuration
-- mini.lua
-- Use with the --clean -u flags. EG nvim --clean -u mini.lua
-- This config will create a temp directory and will blow away that temp directory
-- everytime this configuration is loaded. Great for simulating a new installation
-- of a plugin

-- Setting some basic vim options
-- Some junk because I am sick of formatting tables in print
local _print = _G.print
local clean_string = function(...)
    local args = { n = select("#", ...), ... }
    local formatted_args = {}
    for i=1, args.n do
        local item = select(i, ...)
        if not item then item = 'nil' end
        local t_type = type(item)
        if t_type == 'table' or t_type == 'function' or t_type == 'userdata' then
            item = vim.inspect(item)
        end
        table.insert(formatted_args, item)
    end
    return table.concat(formatted_args, ' ')
end
_G.print = function(...)
    _print(clean_string(...))
end

vim.opt.mouse = 'a'
vim.opt.termguicolors = true
-- If you want to play around with this, you can set the do_clean
-- variable to false. This will allow changes made to
-- underlying plugins to persist between sessions, while
-- still keeping everything in its own directory so
-- as to not affect your existing neovim installation.
--
-- Setting this to true will result in a fresh clone of
-- all modules
local do_clean = true

local sep = vim.loop.os_uname().sysname:lower():match('windows') and '\\' or '/' -- \ for windows, mac and linux both use \

local mod_path = string.format("%s%sclean-test%s", vim.fn.stdpath('cache'), sep, sep)
if vim.loop.fs_stat(mod_path) and do_clean then
    print("Found previous clean test setup. Cleaning it out")
    -- Clearing out the mods directory and recreating it so 
    -- you have a fresh run everytime
    vim.fn.delete(mod_path, 'rf')
end

vim.fn.mkdir(mod_path, 'p')

local modules = {
    {'nvim-lua/plenary.nvim'},
    {'nvim-tree/nvim-web-devicons'},
    {'willothy/nvim-cokeline', mod = "cokeline"},
}

for _, module in ipairs(modules) do
    local repo = module[1]
    local branch = module.branch
    local module_name = repo:match('/(.*)')
    local module_path = string.format('%s%s%s', mod_path, sep, module_name)
    if not vim.loop.fs_stat(module_name) then
        -- The module doesn't exist, download it
        local cmd = {
            'git',
            'clone'
        }
        if branch then
            table.insert(cmd, '--branch')
            table.insert(cmd, branch)
        end
        table.insert(cmd, string.format('https://github.com/%s', repo))
        table.insert(cmd, module_path)
        vim.fn.system(cmd)
        local message = string.format("Downloaded %s", module_name)
        if branch then
            message = string.format("%s on branch %s", message, branch)
        end
        print(message)
    end
    vim.opt.runtimepath:append(module_path)
end

print("Finished installing plugins. Beginning Setup of plugins")

for _, module in ipairs(modules) do
    if module.mod then
        print(string.format("Loading %s", module.mod))
        local success, err = pcall(require, module.mod)
        if not success then
            print(string.format("Failed to load module %s", module.mod))
            error(err)
        end
    end
end

-- --> Do you module setups below this line <-- --
vim.api.nvim_set_hl(0, 'BufferLineFill', { fg = 'NONE', bg = 'NONE' })
require('cokeline').setup({
    fill_hl = "BufferLineFill",
    default_hl = {
        fg = "NONE",
        bg = "NONE"
    },
    components = {
        {
            text = function(buffer)
                return
                buffer.is_focused and ""
                or " "
            end,
            fg = "NONE",
            bg = "NONE"
        },
        {
            text = function(buffer) return buffer.filename .. ' ' end,
            style = function(buffer)
                if buffer.is_hovered and not buffer.is_focused then
                    return 'underline'
                end
            end
        },
    }
})
-- --> Do your module setups above this line <-- --

print("Completed minimal setup!")

I took a quick peek at the source, but nothing is standing out as overriding the foreground so I don't really know what is happening here.

This functionality is a bit important when you start messing with some of the weirder nerdfonts (such as nf-pl-left_hard_divider) as you have to set the Foreground to the color you want the "background" to be, and the Background to the color you want the foreground to be

@willothy
Copy link
Owner

Thanks for reporting! I'm currently reworking highlights to use nvim_[get/set]_hl (#150) - I'll make sure this isn't still an issue in that patch.

@willothy
Copy link
Owner

Hmm... this actually may not be a cokeline issue. I need to look into it more, but even setting fg to "NONE" directly before every call to set_hl has the same result.

@miversen33
Copy link
Contributor Author

What is really interesting is fg=NONE works just fine on components that aren't active. I don't know if that helps at all. Below is a screenshot of my current cokeline configuration showing this
image
image

@willothy
Copy link
Owner

That is good to know! I'll keep looking into it today.

@willothy
Copy link
Owner

Quite stumped by this at the moment, but I'll keep trying. Until then, you can use the highlight option to set a highlight group entirely for a component, I'm able to get foreground transparency with that. You might have to create a few highlight groups, but that's the only workaround I've found atm. This is a weird one haha

@willothy
Copy link
Owner

Idea: why not conditionally use 🭨 when you need no background there instead? As far as I can tell, you can't set fg to none in the tabline in Vim at all.

@miversen33
Copy link
Contributor Author

Psh, you think I would look at literally any other characters in the powerline fonts? 😂

I will give that a shot and see if it works. It makes sense that is should I think.

@willothy
Copy link
Owner

willothy commented Aug 25, 2023

Yeah, not sure why setting fg isn't possible but I can't get it to work at all. May be a terminal emulator thing? I'm on Wezterm. I haven't tried other terminals but if they don't work either, it may be worth submitting an issue upstream to Neovim.

And I'm not sure how I thought I got it working before, pretty sure I was just confused because I can't replicate what I described.

@miversen33
Copy link
Contributor Author

Sorry I hadn't gotten back to you on this. The icon provided isn't in the fonts I have setup for my terminal (I am using wezterm as well). I can see transparent foregrounds just kinda being a pain in the ass to support within neovim itself so it is very possible that this is something that just can't be done (in which case I will need to either accept my current solution of a color that you generally don't see, or fix my font setup to provide a unicode character that will work in my setup).

This may just be a limitation of neovim, you are right. I don't know that I care enough to open up anything upstream on Neovim for this (mainly because I don't want to go through the effort of trying to recreate the issue in a minimal configuration when I don't fully understand where in the highlight process the issue exists in the first place).

Probably worth closing this out unless you want to dig deeper into it lol

@willothy
Copy link
Owner

willothy commented Sep 8, 2023

Fair, no worries! I use FiraMono so maybe it's nerdfont-specific, though I had thought that Wezterm shipped with nerdfonts by default. Understandable, this is a pretty weird issue, definitely tough to create a plugin-less minimal config.

I'll close this for now, I think I've dug enough into it to conclude that it's just not possible unfortunately, but if I find anything else out I'll reopen this and update.

Hope you find a solution that works!

@willothy willothy closed this as completed Sep 8, 2023
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

No branches or pull requests

2 participants