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' },
|
|
|
|
lualine_diagnostics = { }
|
|
|
|
}
|
|
|
|
|
|
|
|
M.inactiveSections = {
|
|
|
|
lualine_a = { },
|
|
|
|
lualine_b = { },
|
|
|
|
lualine_c = { 'filename' },
|
|
|
|
lualine_x = { 'location' },
|
|
|
|
lualine_y = { },
|
|
|
|
lualine_z = { }
|
|
|
|
}
|
|
|
|
|
|
|
|
M.extensions = {
|
|
|
|
}
|
|
|
|
|
|
|
|
local function loadComponents()
|
|
|
|
local function loadSections(sections)
|
|
|
|
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
|
|
|
|
loadSections(M.sections)
|
|
|
|
loadSections(M.inactiveSections)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function loadExtensions()
|
|
|
|
for _, extension in pairs(M.extensions) do
|
|
|
|
if type(extension) == 'string' then
|
|
|
|
require('lualine.components.extensions.' .. extension).loadExtension()
|
|
|
|
end
|
|
|
|
if type(extension) == 'table' then
|
|
|
|
extension.loadExtension()
|
|
|
|
end
|
|
|
|
if type(extension) == 'function' then
|
|
|
|
extension()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-04 00:17:51 +00:00
|
|
|
local function setLualineTheme()
|
|
|
|
if type(M.theme) == 'string' then
|
|
|
|
M.theme =require('lualine.themes.'.. M.theme)
|
|
|
|
end
|
|
|
|
highlight.createHighlightGroups(M.theme)
|
|
|
|
theme_set = M.theme
|
|
|
|
end
|
|
|
|
|
2020-12-30 14:48:51 +00:00
|
|
|
local function StatusLine(isFocused)
|
|
|
|
local sections = M.sections
|
|
|
|
if not isFocused then
|
|
|
|
sections = M.inactiveSections
|
|
|
|
end
|
2021-01-04 00:17:51 +00:00
|
|
|
if M.theme ~= theme_set then
|
|
|
|
setLualineTheme()
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-03 19:11:22 +00:00
|
|
|
local status = {}
|
2020-12-30 14:48:51 +00:00
|
|
|
if sections.lualine_a ~= nil then
|
2021-01-03 19:11:22 +00:00
|
|
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a'))
|
|
|
|
table.insert(status, utils.drawSection(sections.lualine_a, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
if sections.lualine_b ~= nil then
|
2021-01-03 19:11:22 +00:00
|
|
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b'))
|
|
|
|
table.insert(status, utils.drawSection(sections.lualine_b, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
if sections.lualine_c ~= nil then
|
2021-01-03 19:11:22 +00:00
|
|
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c'))
|
|
|
|
table.insert(status, utils.drawSection(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, "%=")
|
2020-12-30 14:48:51 +00:00
|
|
|
if sections.lualine_x ~= nil then
|
2021-01-03 19:11:22 +00:00
|
|
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c'))
|
|
|
|
table.insert(status, utils.drawSection(sections.lualine_x, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
if sections.lualine_y ~= nil then
|
2021-01-03 19:11:22 +00:00
|
|
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b'))
|
|
|
|
table.insert(status, utils.drawSection(sections.lualine_y, M.separator))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
if sections.lualine_z ~= nil then
|
2021-01-03 19:11:22 +00:00
|
|
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a'))
|
|
|
|
table.insert(status, utils.drawSection(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-01-04 00:17:51 +00:00
|
|
|
function execAutocommands()
|
2020-12-30 14:48:51 +00:00
|
|
|
_G.statusline = StatusLine
|
2021-01-04 00:17:51 +00:00
|
|
|
_G.highlight = setLualineTheme
|
2020-12-30 14:48:51 +00:00
|
|
|
vim.cmd([[autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.statusline(1)]])
|
|
|
|
vim.cmd([[autocmd WinLeave,BufLeave * setlocal statusline=%!v:lua.statusline()]])
|
2021-01-04 00:17:51 +00:00
|
|
|
vim.cmd([[autocmd ColorScheme * call v:lua.highlight()]])
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.status()
|
|
|
|
loadComponents()
|
|
|
|
loadExtensions()
|
|
|
|
setLualineTheme()
|
|
|
|
execAutocommands()
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|