From 62b53c854ce0613e428145dba3e5add7eb8c739e Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Tue, 3 Aug 2021 12:08:17 +0600 Subject: [PATCH] feat: Allow extensions to spwcify inactive sections too --- lua/lualine/init.lua | 24 ++++++++++++++---------- lua/lualine/utils/loader.lua | 6 ++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lua/lualine/init.lua b/lua/lualine/init.lua index 64cfd8f..c98b18e 100644 --- a/lua/lualine/init.lua +++ b/lua/lualine/init.lua @@ -129,12 +129,15 @@ local function statusline(sections, is_focused) end -- check if any extension matches the filetype and return proper sections -local function get_extension_sections() +local function get_extension_sections(current_ft, is_focused) for _, extension in ipairs(config.extensions) do for _, filetype in ipairs(extension.filetypes) do - local current_ft = vim.api.nvim_buf_get_option( - vim.fn.winbufnr(vim.g.statusline_winid), 'filetype') - if current_ft == filetype then return extension.sections end + if current_ft == filetype then + if is_focused == false and extension.inactive_sections then + return extension.inactive_sections + end + return extension.sections + end end end return nil @@ -144,23 +147,24 @@ local function status_dispatch() -- disable on specific filetypes local current_ft = vim.api.nvim_buf_get_option( vim.fn.winbufnr(vim.g.statusline_winid), 'filetype') + local is_focused = vim.g.statusline_winid == vim.fn.win_getid() for _, ft in pairs(config.options.disabled_filetypes) do if ft == current_ft then vim.wo.statusline = '' return '' end end - local extension_sections = get_extension_sections() - if vim.g.statusline_winid == vim.fn.win_getid() then + local extension_sections = get_extension_sections(current_ft, is_focused) + if is_focused then if extension_sections ~= nil then - return statusline(extension_sections, true) + return statusline(extension_sections, is_focused) end - return statusline(config.sections, true) + return statusline(config.sections, is_focused) else if extension_sections ~= nil then - return statusline(extension_sections, false) + return statusline(extension_sections, is_focused) end - return statusline(config.inactive_sections, false) + return statusline(config.inactive_sections, is_focused) end end diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua index a46c927..e87eddc 100644 --- a/lua/lualine/utils/loader.lua +++ b/lua/lualine/utils/loader.lua @@ -49,9 +49,15 @@ local function load_extensions(config) if type(extension) == 'string' then local local_extension = require('lualine.extensions.' .. extension) load_sections(local_extension.sections, config.options) + if local_extension.inactive_sections then + load_sections(local_extension.inactive_sections, config.options) + end config.extensions[index] = local_extension elseif type(extension) == 'table' then load_sections(extension.sections, config.options) + if extension.inactive_sections then + load_sections(extension.inactive_sections, config.options) + end config.extensions[index] = extension end end