2021-05-09 21:11:18 +00:00
|
|
|
-- Copyright (c) 2020-2021 hoob3rt
|
|
|
|
-- MIT license, see LICENSE for more details.
|
|
|
|
local function component_loader(component)
|
|
|
|
if type(component[1]) == 'function' then
|
|
|
|
return
|
|
|
|
require 'lualine.components.special.function_component':new(component)
|
|
|
|
end
|
|
|
|
if type(component[1]) == 'string' then
|
|
|
|
-- load the component
|
|
|
|
local ok, loaded_component = pcall(require,
|
|
|
|
'lualine.components.' .. component[1])
|
|
|
|
if ok then
|
|
|
|
component.component_name = component[1]
|
|
|
|
loaded_component = loaded_component:new(component)
|
|
|
|
elseif component[1]:find('[gvtwb]?o?:') == 1 then
|
|
|
|
loaded_component =
|
|
|
|
require 'lualine.components.special.vim_var_component':new(component)
|
|
|
|
else
|
|
|
|
loaded_component =
|
|
|
|
require 'lualine.components.special.eval_func_component':new(component)
|
|
|
|
end
|
|
|
|
return loaded_component
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function load_sections(sections, options)
|
2021-08-02 15:16:17 +00:00
|
|
|
for section_name, section in pairs(sections) do
|
|
|
|
for index, component in pairs(section) do
|
|
|
|
if type(component) == 'string' or type(component) == 'function' then
|
|
|
|
component = {component}
|
|
|
|
end
|
|
|
|
component.self = {}
|
|
|
|
component.self.section = section_name
|
|
|
|
-- apply default args
|
|
|
|
component = vim.tbl_extend('keep', component, options)
|
|
|
|
section[index] = component_loader(component)
|
|
|
|
end
|
|
|
|
end
|
2021-05-09 21:11:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function load_components(config)
|
|
|
|
load_sections(config.sections, config.options)
|
|
|
|
load_sections(config.inactive_sections, config.options)
|
|
|
|
load_sections(config.tabline, config.options)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function load_extensions(config)
|
|
|
|
for index, extension in pairs(config.extensions) do
|
2021-05-14 18:24:54 +00:00
|
|
|
if type(extension) == 'string' then
|
2021-08-13 01:25:17 +00:00
|
|
|
local local_extension = vim.deepcopy(require('lualine.extensions.' .. extension))
|
2021-05-14 18:24:54 +00:00
|
|
|
load_sections(local_extension.sections, config.options)
|
2021-08-03 06:08:17 +00:00
|
|
|
if local_extension.inactive_sections then
|
|
|
|
load_sections(local_extension.inactive_sections, config.options)
|
|
|
|
end
|
2021-08-13 01:20:56 +00:00
|
|
|
if type(local_extension.init) == 'function' then
|
|
|
|
local_extension.init()
|
|
|
|
end
|
2021-05-14 18:24:54 +00:00
|
|
|
config.extensions[index] = local_extension
|
|
|
|
elseif type(extension) == 'table' then
|
2021-08-13 01:25:17 +00:00
|
|
|
local local_extension = vim.deepcopy(extension)
|
|
|
|
load_sections(local_extension.sections, config.options)
|
|
|
|
if local_extension.inactive_sections then
|
|
|
|
load_sections(local_extension.inactive_sections, config.options)
|
2021-08-03 06:08:17 +00:00
|
|
|
end
|
2021-08-13 01:20:56 +00:00
|
|
|
if type(local_extension.init) == 'function' then
|
|
|
|
local_extension.init()
|
|
|
|
end
|
2021-08-13 01:25:17 +00:00
|
|
|
config.extensions[index] = local_extension
|
2021-05-14 18:24:54 +00:00
|
|
|
end
|
2021-05-09 21:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function load_all(config)
|
|
|
|
load_components(config)
|
|
|
|
load_extensions(config)
|
|
|
|
end
|
|
|
|
|
|
|
|
return {load_all = load_all}
|