famiu / feline.nvim

A minimal, stylish and customizable statusline for Neovim written in Lua
GNU General Public License v3.0
1.04k stars 55 forks source link

[Question] How to change colors of feline.nvim when you toggle a color scheme? #36

Closed olimorris closed 3 years ago

olimorris commented 3 years ago

I wondered if anyone has come up with a nice way of toggling colors with feline.nvim when changing their color scheme/theme?

Right now I have a hacked up method that reloads my feline config when the theme changes (via an autocommand), including loading of colors. But this only seems to work a couple of times before stopping altogether:

Screen Shot 2021-08-30 at 21 04 52

For reference, my relevant code is:

--statusline.lua file

local M = {}

-- Load the correct colour palette
local function load_colors()
    local colors = require('themes')
    if vim.g.theme == 'onedark' then
        return colors.onedark
    else
        return colors.onelight
    end
end

-- Setup our feline statusline
function M.__load()
    M.colors = load_colors()

    -- Set our components here
    -- Omitted from this example but included a link below!

    require('feline').setup({
        preset = 'noicon',
        default_fg = M.colors.fg,
        default_bg = M.colors.bg,
        vi_mode_colors = M.vi_mode_colors,
        components = M.components,
        properties = M.properties
    })
end

return M

--autocmds.lua file
if pcall(require, 'feline') then
    utils.augroup({refresh_statusline_colors = {{'ColorScheme', '*', "lua require('plugins.configs.statusline').__load()"}}})
end

My full feline config can be found here, FYI.

famiu commented 3 years ago

Have you tried making use of require('feline').reset_highlights()?

olimorris commented 3 years ago

That's a really great shout! Had completely missed that!