feat: Allow extensions to spwcify inactive sections too
This commit is contained in:
parent
51daaf6f5a
commit
62b53c854c
|
@ -129,12 +129,15 @@ local function statusline(sections, is_focused)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if any extension matches the filetype and return proper sections
|
-- 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 _, extension in ipairs(config.extensions) do
|
||||||
for _, filetype in ipairs(extension.filetypes) do
|
for _, filetype in ipairs(extension.filetypes) do
|
||||||
local current_ft = vim.api.nvim_buf_get_option(
|
if current_ft == filetype then
|
||||||
vim.fn.winbufnr(vim.g.statusline_winid), 'filetype')
|
if is_focused == false and extension.inactive_sections then
|
||||||
if current_ft == filetype then return extension.sections end
|
return extension.inactive_sections
|
||||||
|
end
|
||||||
|
return extension.sections
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
|
@ -144,23 +147,24 @@ local function status_dispatch()
|
||||||
-- disable on specific filetypes
|
-- disable on specific filetypes
|
||||||
local current_ft = vim.api.nvim_buf_get_option(
|
local current_ft = vim.api.nvim_buf_get_option(
|
||||||
vim.fn.winbufnr(vim.g.statusline_winid), 'filetype')
|
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
|
for _, ft in pairs(config.options.disabled_filetypes) do
|
||||||
if ft == current_ft then
|
if ft == current_ft then
|
||||||
vim.wo.statusline = ''
|
vim.wo.statusline = ''
|
||||||
return ''
|
return ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local extension_sections = get_extension_sections()
|
local extension_sections = get_extension_sections(current_ft, is_focused)
|
||||||
if vim.g.statusline_winid == vim.fn.win_getid() then
|
if is_focused then
|
||||||
if extension_sections ~= nil then
|
if extension_sections ~= nil then
|
||||||
return statusline(extension_sections, true)
|
return statusline(extension_sections, is_focused)
|
||||||
end
|
end
|
||||||
return statusline(config.sections, true)
|
return statusline(config.sections, is_focused)
|
||||||
else
|
else
|
||||||
if extension_sections ~= nil then
|
if extension_sections ~= nil then
|
||||||
return statusline(extension_sections, false)
|
return statusline(extension_sections, is_focused)
|
||||||
end
|
end
|
||||||
return statusline(config.inactive_sections, false)
|
return statusline(config.inactive_sections, is_focused)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,15 @@ local function load_extensions(config)
|
||||||
if type(extension) == 'string' then
|
if type(extension) == 'string' then
|
||||||
local local_extension = require('lualine.extensions.' .. extension)
|
local local_extension = require('lualine.extensions.' .. extension)
|
||||||
load_sections(local_extension.sections, config.options)
|
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
|
config.extensions[index] = local_extension
|
||||||
elseif type(extension) == 'table' then
|
elseif type(extension) == 'table' then
|
||||||
load_sections(extension.sections, config.options)
|
load_sections(extension.sections, config.options)
|
||||||
|
if extension.inactive_sections then
|
||||||
|
load_sections(extension.inactive_sections, config.options)
|
||||||
|
end
|
||||||
config.extensions[index] = extension
|
config.extensions[index] = extension
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue