2021-05-09 21:11:18 +00:00
|
|
|
-- Copyright (c) 2020-2021 hoob3rt
|
|
|
|
-- MIT license, see LICENSE for more details.
|
2022-03-18 00:59:01 +00:00
|
|
|
local require = require('lualine_require').require
|
2022-01-02 11:38:39 +00:00
|
|
|
local utils = require('lualine.utils.utils')
|
2022-03-18 00:59:01 +00:00
|
|
|
local modules = require('lualine_require').lazy_require {
|
|
|
|
utils_notices = 'lualine.utils.notices',
|
|
|
|
}
|
2021-11-25 06:57:00 +00:00
|
|
|
|
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,
|
2022-03-18 00:59:01 +00:00
|
|
|
globalstatus = false,
|
2021-05-09 21:11:18 +00:00
|
|
|
},
|
|
|
|
sections = {
|
2021-09-03 18:28:20 +00:00
|
|
|
lualine_a = { 'mode' },
|
2021-12-09 17:18:11 +00:00
|
|
|
lualine_b = { 'branch', 'diff', 'diagnostics' },
|
2021-09-03 18:28:20 +00:00
|
|
|
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
|
|
|
|
|
2022-05-30 14:25:05 +00:00
|
|
|
---extends config based on config_table
|
2021-10-12 14:04:47 +00:00
|
|
|
---@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
|
2022-03-18 00:59:01 +00:00
|
|
|
if config_table.options and config_table.options.globalstatus and vim.fn.has('nvim-0.7') == 0 then
|
|
|
|
modules.utils_notices.add_notice(
|
|
|
|
'### Options.globalstatus\nSorry `globalstatus` option can only be used in neovim 0.7 or higher.\n'
|
|
|
|
)
|
|
|
|
config_table.options.globalstatus = false
|
|
|
|
end
|
2022-01-02 11:38:39 +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
|
|
|
}
|