2021-05-09 21:11:18 +00:00
|
|
|
-- Copyright (c) 2020-2021 hoob3rt
|
|
|
|
-- MIT license, see LICENSE for more details.
|
2021-11-25 06:57:00 +00:00
|
|
|
local utils = require 'lualine.utils.utils'
|
|
|
|
|
2021-05-09 21:11:18 +00:00
|
|
|
local config = {
|
|
|
|
options = {
|
|
|
|
icons_enabled = true,
|
2021-08-14 06:02:30 +00:00
|
|
|
theme = 'auto',
|
2021-09-14 15:14:23 +00:00
|
|
|
component_separators = { left = '', right = '' },
|
|
|
|
section_separators = { left = '', right = '' },
|
2021-09-03 18:28:20 +00:00
|
|
|
disabled_filetypes = {},
|
2021-10-07 22:18:14 +00:00
|
|
|
always_divide_middle = true,
|
2021-05-09 21:11:18 +00:00
|
|
|
},
|
|
|
|
sections = {
|
2021-09-03 18:28:20 +00:00
|
|
|
lualine_a = { 'mode' },
|
|
|
|
lualine_b = { 'branch', 'diff', { 'diagnostics', sources = { 'nvim_lsp', 'coc' } } },
|
|
|
|
lualine_c = { 'filename' },
|
|
|
|
lualine_x = { 'encoding', 'fileformat', 'filetype' },
|
|
|
|
lualine_y = { 'progress' },
|
|
|
|
lualine_z = { 'location' },
|
2021-05-09 21:11:18 +00:00
|
|
|
},
|
|
|
|
inactive_sections = {
|
|
|
|
lualine_a = {},
|
|
|
|
lualine_b = {},
|
2021-09-03 18:28:20 +00:00
|
|
|
lualine_c = { 'filename' },
|
|
|
|
lualine_x = { 'location' },
|
2021-05-09 21:11:18 +00:00
|
|
|
lualine_y = {},
|
2021-09-03 18:28:20 +00:00
|
|
|
lualine_z = {},
|
2021-05-09 21:11:18 +00:00
|
|
|
},
|
|
|
|
tabline = {},
|
2021-09-03 18:28:20 +00:00
|
|
|
extensions = {},
|
2021-05-09 21:11:18 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
--- change separator format 'x' to {left='x', right='x'}
|
|
|
|
---@param separators string|table
|
|
|
|
---@return table
|
2021-05-09 21:11:18 +00:00
|
|
|
local function fix_separators(separators)
|
|
|
|
if separators ~= nil then
|
|
|
|
if type(separators) == 'string' then
|
2021-09-14 15:14:23 +00:00
|
|
|
return { left = separators, right = separators }
|
2021-05-09 21:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return separators
|
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
---extends config based on configtable
|
|
|
|
---@param config_table table
|
|
|
|
---@return table copy of config
|
2021-05-09 21:11:18 +00:00
|
|
|
local function apply_configuration(config_table)
|
2021-09-03 18:28:20 +00:00
|
|
|
if not config_table then
|
2021-11-25 06:57:00 +00:00
|
|
|
return utils.deepcopy(config)
|
2021-09-03 18:28:20 +00:00
|
|
|
end
|
2021-05-09 21:11:18 +00:00
|
|
|
local function parse_sections(section_group_name)
|
2021-11-22 13:40:18 +00:00
|
|
|
if config_table[section_group_name] == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not next(config_table[section_group_name]) then
|
|
|
|
config[section_group_name] = {}
|
2021-09-03 18:28:20 +00:00
|
|
|
return
|
|
|
|
end
|
2021-05-09 21:11:18 +00:00
|
|
|
for section_name, section in pairs(config_table[section_group_name]) do
|
2021-11-25 06:57:00 +00:00
|
|
|
config[section_group_name][section_name] = utils.deepcopy(section)
|
2021-05-09 21:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
2021-09-03 18:28:20 +00:00
|
|
|
parse_sections 'options'
|
|
|
|
parse_sections 'sections'
|
|
|
|
parse_sections 'inactive_sections'
|
|
|
|
parse_sections 'tabline'
|
2021-08-08 17:44:03 +00:00
|
|
|
if config_table.extensions then
|
2021-11-25 06:57:00 +00:00
|
|
|
config.extensions = utils.deepcopy(config_table.extensions)
|
2021-08-08 17:44:03 +00:00
|
|
|
end
|
2021-09-03 18:28:20 +00:00
|
|
|
config.options.section_separators = fix_separators(config.options.section_separators)
|
|
|
|
config.options.component_separators = fix_separators(config.options.component_separators)
|
2021-11-25 06:57:00 +00:00
|
|
|
return utils.deepcopy(config)
|
2021-05-09 21:11:18 +00:00
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
--- returns current active config
|
|
|
|
---@return table a copy of config
|
2021-08-04 02:28:53 +00:00
|
|
|
local function get_current_config()
|
2021-11-25 06:57:00 +00:00
|
|
|
return utils.deepcopy(config)
|
2021-08-04 01:13:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2021-08-04 02:28:53 +00:00
|
|
|
get_config = get_current_config,
|
2021-09-03 18:28:20 +00:00
|
|
|
apply_configuration = apply_configuration,
|
2021-08-04 01:13:37 +00:00
|
|
|
}
|