diff --git a/lua/lualine.lua b/lua/lualine.lua index 717d14cbd..a3abbb8b4 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -280,6 +280,35 @@ local function set_statusline() end end +--- Sets &winbar option to lualine +local function set_winbar() + if next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil then + vim.go.winbar = "%{%v:lua.require'lualine'.winbar()%}" + end +end + +-- lualine.winbar function +--- Draw correct winbar for current window +---@param focused boolean : force the value of is_focused . useful for debugging +---@return string winbar string +local function winbar_dispatch(focused) + local retval + local current_ft = vim.bo.filetype + local is_focused = focused ~= nil and focused or modules.utils.is_focused() + for _, ft in pairs(config.options.disabled_filetypes) do + -- disable on specific filetypes + if ft == current_ft then + return '' + end + end + if is_focused then + retval = statusline(config.winbar, is_focused) + else + retval = statusline(config.inactive_winbar, is_focused) + end + return retval +end + -- lualine.statusline function --- Draw correct statusline for current window ---@param focused boolean : force the value of is_focused . useful for debugging @@ -331,6 +360,7 @@ local function setup(user_config) -- load components & extensions modules.loader.load_all(config) set_statusline() + set_winbar() set_tabline() if package.loaded['lualine.utils.notices'] then modules.utils_notices.notice_message_startup() @@ -340,6 +370,7 @@ end return { setup = setup, statusline = status_dispatch, + winbar = winbar_dispatch, tabline = tabline, get_config = modules.config_module.get_config, } diff --git a/lua/lualine/config.lua b/lua/lualine/config.lua index 3a5dc9180..c31bd2a4d 100644 --- a/lua/lualine/config.lua +++ b/lua/lualine/config.lua @@ -32,6 +32,8 @@ local config = { lualine_y = {}, lualine_z = {}, }, + winbar = {}, + inactive_winbar = {}, tabline = {}, extensions = {}, } @@ -76,6 +78,8 @@ local function apply_configuration(config_table) parse_sections('options') parse_sections('sections') parse_sections('inactive_sections') + parse_sections('winbar') + parse_sections('inactive_winbar') parse_sections('tabline') if config_table.extensions then config.extensions = utils.deepcopy(config_table.extensions) diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua index 180530149..49674849e 100644 --- a/lua/lualine/utils/loader.lua +++ b/lua/lualine/utils/loader.lua @@ -156,6 +156,8 @@ local function load_components(config) load_sections(config.sections, config.options) load_sections(config.inactive_sections, config.options) load_sections(config.tabline, config.options) + load_sections(config.winbar, config.options) + load_sections(config.inactive_winbar, config.options) end ---loads all the extensions diff --git a/tests/spec/lualine_spec.lua b/tests/spec/lualine_spec.lua index 430fb8869..1e8836d68 100644 --- a/tests/spec/lualine_spec.lua +++ b/tests/spec/lualine_spec.lua @@ -47,6 +47,8 @@ describe('Lualine', function() lualine_y = {}, lualine_z = {}, }, + winbar = {}, + inactive_winbar = {}, tabline = {}, extensions = {}, }