2020-12-30 14:48:51 +00:00
|
|
|
local utils = require('lualine.utils')
|
|
|
|
local highlight = require('lualine.highlight')
|
|
|
|
|
|
|
|
local M = { }
|
|
|
|
|
|
|
|
M.theme = 'gruvbox'
|
2021-01-04 00:17:51 +00:00
|
|
|
local theme_set = {}
|
2020-12-30 14:48:51 +00:00
|
|
|
|
|
|
|
M.separator = '|'
|
|
|
|
|
|
|
|
M.sections = {
|
|
|
|
lualine_a = { 'mode' },
|
|
|
|
lualine_b = { 'branch' },
|
|
|
|
lualine_c = { 'filename' },
|
|
|
|
lualine_x = { 'encoding', 'fileformat', 'filetype' },
|
|
|
|
lualine_y = { 'progress' },
|
|
|
|
lualine_z = { 'location' },
|
|
|
|
}
|
|
|
|
|
2021-01-04 01:14:29 +00:00
|
|
|
M.inactive_sections = {
|
2020-12-30 14:48:51 +00:00
|
|
|
lualine_a = { },
|
|
|
|
lualine_b = { },
|
|
|
|
lualine_c = { 'filename' },
|
|
|
|
lualine_x = { 'location' },
|
|
|
|
lualine_y = { },
|
2021-01-05 23:43:36 +00:00
|
|
|
lualine_z = { }
|
2020-12-30 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
M.extensions = {
|
|
|
|
}
|
|
|
|
|
2021-01-04 01:14:29 +00:00
|
|
|
local function load_components()
|
|
|
|
local function load_sections(sections)
|
2020-12-30 14:48:51 +00:00
|
|
|
for _, section in pairs(sections) do
|
|
|
|
for index, component in pairs(section) do
|
|
|
|
if type(component) == 'string' then
|
|
|
|
section[index] = require('lualine.components.' .. component)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
load_sections(M.sections)
|
|
|
|
load_sections(M.inactive_sections)
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
2021-01-04 01:14:29 +00:00
|
|
|
local function load_extensions()
|
2020-12-30 14:48:51 +00:00
|
|
|
for _, extension in pairs(M.extensions) do
|
|
|
|
if type(extension) == 'string' then
|
2021-01-04 01:14:29 +00:00
|
|
|
require('lualine.extensions.' .. extension).load_extension()
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
if type(extension) == 'table' then
|
2021-01-04 01:14:29 +00:00
|
|
|
extension.load_extension()
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
if type(extension) == 'function' then
|
|
|
|
extension()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-04 01:14:29 +00:00
|
|
|
local function set_lualine_theme()
|
2021-01-04 00:17:51 +00:00
|
|
|
if type(M.theme) == 'string' then
|
2021-01-04 01:14:29 +00:00
|
|
|
M.theme = require('lualine.themes.'.. M.theme)
|
2021-01-04 00:17:51 +00:00
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
highlight.create_highlight_groups(M.theme)
|
2021-01-04 00:17:51 +00:00
|
|
|
theme_set = M.theme
|
|
|
|
end
|
|
|
|
|
2021-02-05 12:29:34 +00:00
|
|
|
local function statusline(sections, is_focused)
|
2021-01-03 19:11:22 +00:00
|
|
|
local status = {}
|
2021-01-04 01:14:29 +00:00
|
|
|
if sections.lualine_a then
|
|
|
|
table.insert(status, highlight.format_highlight(is_focused, 'lualine_a'))
|
|
|
|
table.insert(status, utils.draw_section(sections.lualine_a, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
if sections.lualine_b then
|
|
|
|
table.insert(status, highlight.format_highlight(is_focused, 'lualine_b'))
|
|
|
|
table.insert(status, utils.draw_section(sections.lualine_b, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
if sections.lualine_c then
|
|
|
|
table.insert(status, highlight.format_highlight(is_focused, 'lualine_c'))
|
|
|
|
table.insert(status, utils.draw_section(sections.lualine_c, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-03 19:11:22 +00:00
|
|
|
table.insert(status, "%=")
|
2021-01-04 01:14:29 +00:00
|
|
|
if sections.lualine_x then
|
|
|
|
table.insert(status, highlight.format_highlight(is_focused, 'lualine_c'))
|
|
|
|
table.insert(status, utils.draw_section(sections.lualine_x, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
if sections.lualine_y then
|
|
|
|
table.insert(status, highlight.format_highlight(is_focused, 'lualine_b'))
|
|
|
|
table.insert(status, utils.draw_section(sections.lualine_y, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
if sections.lualine_z then
|
|
|
|
table.insert(status, highlight.format_highlight(is_focused, 'lualine_a'))
|
|
|
|
table.insert(status, utils.draw_section(sections.lualine_z, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-03 19:11:22 +00:00
|
|
|
return table.concat(status)
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
2021-02-05 12:29:34 +00:00
|
|
|
local function status_dispatch()
|
|
|
|
if vim.g.statusline_winid == vim.fn.win_getid() then
|
|
|
|
return statusline(M.sections, true)
|
|
|
|
else
|
|
|
|
return statusline(M.inactive_sections, false)
|
|
|
|
end
|
2021-01-05 23:43:36 +00:00
|
|
|
end
|
|
|
|
|
2021-01-04 01:14:29 +00:00
|
|
|
local function exec_autocommands()
|
|
|
|
_G.set_lualine_theme = set_lualine_theme
|
2021-01-15 04:15:04 +00:00
|
|
|
vim.api.nvim_exec([[
|
|
|
|
augroup lualine
|
|
|
|
autocmd!
|
|
|
|
autocmd ColorScheme * call v:lua.set_lualine_theme()
|
|
|
|
augroup END
|
|
|
|
]], false)
|
2021-01-04 00:17:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.status()
|
2021-01-04 01:14:29 +00:00
|
|
|
load_components()
|
|
|
|
load_extensions()
|
|
|
|
set_lualine_theme()
|
|
|
|
exec_autocommands()
|
2021-02-05 12:29:34 +00:00
|
|
|
_G.lualine_statusline = status_dispatch
|
|
|
|
vim.o.statusline = '%!v:lua.lualine_statusline()'
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|