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 = '' },
|
2022-07-22 13:29:55 +00:00
|
|
|
disabled_filetypes = {
|
|
|
|
statusline = {},
|
2022-07-22 13:30:37 +00:00
|
|
|
winbar = {},
|
2022-07-22 13:29:55 +00:00
|
|
|
},
|
2022-07-29 10:54:31 +00:00
|
|
|
ignore_focus = {},
|
2021-10-07 22:18:14 +00:00
|
|
|
always_divide_middle = true,
|
2022-07-22 13:29:55 +00:00
|
|
|
globalstatus = vim.go.laststatus == 3,
|
|
|
|
refresh = {
|
|
|
|
statusline = 1000,
|
|
|
|
tabline = 1000,
|
|
|
|
winbar = 1000,
|
2022-07-22 13:30:37 +00:00
|
|
|
},
|
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 = {},
|
2022-07-22 13:29:55 +00:00
|
|
|
winbar = {},
|
|
|
|
inactive_winbar = {},
|
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-07-22 13:29:55 +00:00
|
|
|
---copy raw disabled_filetypes to inner statusline & winbar tables.
|
|
|
|
---@param disabled_filetypes table
|
|
|
|
---@return table
|
|
|
|
local function fix_disabled_filetypes(disabled_filetypes)
|
2022-07-22 13:30:37 +00:00
|
|
|
if disabled_filetypes == nil then
|
|
|
|
return
|
|
|
|
end
|
2022-07-22 13:29:55 +00:00
|
|
|
if disabled_filetypes.statusline == nil then
|
|
|
|
disabled_filetypes.statusline = {}
|
|
|
|
end
|
|
|
|
if disabled_filetypes.winbar == nil then
|
|
|
|
disabled_filetypes.winbar = {}
|
|
|
|
end
|
|
|
|
for k, disabled_ft in ipairs(disabled_filetypes) do
|
|
|
|
table.insert(disabled_filetypes.statusline, disabled_ft)
|
|
|
|
table.insert(disabled_filetypes.winbar, disabled_ft)
|
|
|
|
disabled_filetypes[k] = nil
|
|
|
|
end
|
|
|
|
return disabled_filetypes
|
|
|
|
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
|
2022-07-28 07:14:55 +00:00
|
|
|
if section_name == 'refresh' then
|
|
|
|
config[section_group_name][section_name] =
|
|
|
|
vim.tbl_deep_extend('force', config[section_group_name][section_name], utils.deepcopy(section))
|
|
|
|
else
|
|
|
|
config[section_group_name][section_name] = utils.deepcopy(section)
|
|
|
|
end
|
2021-05-09 21:11:18 +00:00
|
|
|
end
|
|
|
|
end
|
2022-07-22 13:29:55 +00:00
|
|
|
if vim.fn.has('nvim-0.8') == 0 and (next(config_table.winbar or {}) or next(config_table.inactive_winbar or {})) then
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.utils_notices.add_notice('### winbar\nSorry `winbar can only be used in neovim 0.8 or higher.\n')
|
2022-07-22 13:29:55 +00:00
|
|
|
config_table.winbar = {}
|
|
|
|
config_table.inactive_winbar = {}
|
|
|
|
end
|
2022-01-02 11:38:39 +00:00
|
|
|
parse_sections('options')
|
|
|
|
parse_sections('sections')
|
|
|
|
parse_sections('inactive_sections')
|
|
|
|
parse_sections('tabline')
|
2022-07-22 13:29:55 +00:00
|
|
|
parse_sections('winbar')
|
|
|
|
parse_sections('inactive_winbar')
|
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)
|
2022-07-22 13:29:55 +00:00
|
|
|
config.options.disabled_filetypes = fix_disabled_filetypes(config.options.disabled_filetypes)
|
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
|
|
|
}
|