dotfiles/config/nvim/lua/fschauen/util/lualine.lua

41 lines
1.1 KiB
Lua

local M = {}
---Make a lualine component that is colored only when focused.
---@param base table|string Either a lualine component or a component name.
---@return table component
M.dynamic_color = function(base)
local component = {}
if type(base) == "string" then
component = require("lualine.components." .. base):extend()
elseif type(base) == "table" then
component = base:extend()
else
return component
end
function component:init(options)
component.super.init(
self,
vim.tbl_deep_extend("keep", options or {}, {
colored = true,
dynamic_color = true,
})
)
self.saved_highlight = self.options.color_highlight
end
function component:update_status(is_focused)
if self.options.dynamic_color then self.options.colored = is_focused end
return component.super.update_status(self, is_focused)
end
function component:draw(default_highlight, is_focused)
self.options.color_highlight = self.options.colored and self.saved_highlight or nil
return component.super.draw(self, default_highlight, is_focused)
end
return component
end
return M