2020-12-30 14:48:51 +00:00
|
|
|
local utils = require('lualine.utils')
|
|
|
|
local highlight = require('lualine.highlight')
|
|
|
|
|
|
|
|
local M = { }
|
|
|
|
|
|
|
|
M.theme = 'gruvbox'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
local function StatusLine(isFocused)
|
|
|
|
local sections = M.sections
|
|
|
|
if not isFocused then
|
|
|
|
sections = M.inactiveSections
|
|
|
|
end
|
|
|
|
if type(M.theme) == 'string' then
|
|
|
|
M.theme = utils.setTheme(M.theme)
|
|
|
|
highlight.createHighlightGroups(M.theme)
|
|
|
|
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
|
|
|
|
|
|
|
|
function M.status()
|
|
|
|
loadComponents()
|
|
|
|
loadExtensions()
|
|
|
|
_G.statusline = StatusLine
|
|
|
|
vim.cmd([[autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.statusline(1)]])
|
|
|
|
vim.cmd([[autocmd WinLeave,BufLeave * setlocal statusline=%!v:lua.statusline()]])
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|