feat: made extensions consistent with statusline
This commit is contained in:
parent
e4723362c4
commit
c19724fbaa
|
@ -35,8 +35,32 @@ M.inactive_sections = {
|
||||||
lualine_z = { }
|
lualine_z = { }
|
||||||
}
|
}
|
||||||
|
|
||||||
M.extensions = {
|
M.extensions = {}
|
||||||
}
|
|
||||||
|
local function apply_configuration(config_table)
|
||||||
|
if not config_table then return end
|
||||||
|
local function parse_sections(section_group_name)
|
||||||
|
if not config_table[section_group_name] then return end
|
||||||
|
for section_name, section in pairs(config_table[section_group_name]) do
|
||||||
|
M[section_group_name][section_name] = config_table[section_group_name][section_name]
|
||||||
|
if type(section) == 'table' then
|
||||||
|
for _, component in pairs(section) do
|
||||||
|
if type(component) == 'table' and type(component[2]) == 'table' then
|
||||||
|
local options = component[2]
|
||||||
|
component[2] = nil
|
||||||
|
for key, val in pairs(options) do
|
||||||
|
component[key] = val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
parse_sections('options')
|
||||||
|
parse_sections('sections')
|
||||||
|
parse_sections('inactive_sections')
|
||||||
|
if config_table.extensions then M.extensions = config_table.extensions end
|
||||||
|
end
|
||||||
|
|
||||||
local function check_single_separator()
|
local function check_single_separator()
|
||||||
local compoennt_separator = M.options.component_separators
|
local compoennt_separator = M.options.component_separators
|
||||||
|
@ -126,8 +150,6 @@ local function component_loader(component)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function load_components()
|
|
||||||
local function load_sections(sections)
|
local function load_sections(sections)
|
||||||
for section_name, section in pairs(sections) do
|
for section_name, section in pairs(sections) do
|
||||||
for index, component in pairs(section) do
|
for index, component in pairs(section) do
|
||||||
|
@ -141,21 +163,18 @@ local function load_components()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function load_components()
|
||||||
load_sections(M.sections)
|
load_sections(M.sections)
|
||||||
load_sections(M.inactive_sections)
|
load_sections(M.inactive_sections)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function load_extensions()
|
local function load_extensions()
|
||||||
for _, extension in pairs(M.extensions) do
|
for index, extension in pairs(M.extensions) do
|
||||||
if type(extension) == 'string' then
|
local local_extension = require('lualine.extensions.' .. extension)
|
||||||
require('lualine.extensions.' .. extension).load_extension()
|
load_sections(local_extension.sections)
|
||||||
end
|
load_sections(local_extension.inactive_sections)
|
||||||
if type(extension) == 'table' then
|
M.extensions[index] = local_extension
|
||||||
extension.load_extension()
|
|
||||||
end
|
|
||||||
if type(extension) == 'function' then
|
|
||||||
extension()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -181,7 +200,27 @@ local function lualine_set_theme()
|
||||||
theme_set = M.options.theme
|
theme_set = M.options.theme
|
||||||
end
|
end
|
||||||
|
|
||||||
local function statusline(sections, is_focused)
|
local function statusline(is_focused)
|
||||||
|
local sections = nil
|
||||||
|
for _, extension in ipairs(M.extensions) do
|
||||||
|
for _, filetype in ipairs(extension.filetypes) do
|
||||||
|
if vim.bo.filetype == filetype then
|
||||||
|
if is_focused then
|
||||||
|
sections = extension.sections
|
||||||
|
else
|
||||||
|
sections = extension.inactive_sections
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if sections == nil then
|
||||||
|
if is_focused then
|
||||||
|
sections = M.sections
|
||||||
|
else
|
||||||
|
sections = M.inactive_sections
|
||||||
|
end
|
||||||
|
end
|
||||||
if M.options.theme ~= theme_set then
|
if M.options.theme ~= theme_set then
|
||||||
_G.lualine_set_theme()
|
_G.lualine_set_theme()
|
||||||
end
|
end
|
||||||
|
@ -252,9 +291,9 @@ end
|
||||||
|
|
||||||
local function status_dispatch()
|
local function status_dispatch()
|
||||||
if vim.g.statusline_winid == vim.fn.win_getid() then
|
if vim.g.statusline_winid == vim.fn.win_getid() then
|
||||||
return statusline(M.sections, true)
|
return statusline(true)
|
||||||
else
|
else
|
||||||
return statusline(M.inactive_sections, false)
|
return statusline(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue