2021-03-18 00:57:59 +00:00
|
|
|
-- Copyright (c) 2020-2021 hoob3rt
|
|
|
|
-- MIT license, see LICENSE for more details.
|
|
|
|
local utils_component = require('lualine.utils.component')
|
2021-04-07 00:34:36 +00:00
|
|
|
local M = {}
|
2021-03-18 00:57:59 +00:00
|
|
|
-- Returns formated string for a section
|
|
|
|
function M.draw_section(section, highlight_name)
|
|
|
|
local status = {}
|
|
|
|
local drawn_components = {}
|
|
|
|
for _, component in pairs(section) do
|
|
|
|
local localstatus = component[1]()
|
|
|
|
if #localstatus > 0 then
|
|
|
|
local custom_highlight_at_begining =
|
|
|
|
localstatus:find('%%#.*#') == 1 or component.color ~= nil
|
|
|
|
-- Apply modifier functions for options
|
|
|
|
if component.format then localstatus = component.format(localstatus) end
|
|
|
|
localstatus = utils_component.apply_icon(localstatus, component)
|
|
|
|
localstatus = utils_component.apply_case(localstatus, component)
|
|
|
|
localstatus = utils_component.apply_padding(localstatus, component)
|
2021-04-07 00:34:36 +00:00
|
|
|
localstatus = utils_component.apply_highlights(localstatus, component,
|
|
|
|
highlight_name)
|
2021-03-18 00:57:59 +00:00
|
|
|
localstatus = utils_component.apply_spearator(localstatus, component)
|
|
|
|
if custom_highlight_at_begining or (#drawn_components > 0 and
|
|
|
|
not drawn_components[#drawn_components].separator_applied) then
|
|
|
|
-- Don't prepend with old highlight when the component changes it imidiately
|
|
|
|
-- Or when it was already applied with separator
|
|
|
|
table.insert(status, localstatus)
|
|
|
|
else
|
|
|
|
table.insert(status, highlight_name .. localstatus)
|
|
|
|
end
|
|
|
|
table.insert(drawn_components, component)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Draw nothing when all the components were empty
|
|
|
|
if #status == 0 then return '' end
|
|
|
|
-- Remove separators sorounding custom highlighted component
|
|
|
|
for i = 1, #status do
|
|
|
|
if (drawn_components[i].color and drawn_components[i].color.bg) or
|
|
|
|
drawn_components[i].custom_highlight then
|
2021-04-07 00:34:36 +00:00
|
|
|
status[i] =
|
|
|
|
utils_component.strip_separator(status[i], drawn_components[i])
|
2021-03-18 00:57:59 +00:00
|
|
|
if i > 1 then
|
2021-04-07 00:34:36 +00:00
|
|
|
status[i - 1] = utils_component.strip_separator(status[i - 1],
|
|
|
|
drawn_components[i - 1])
|
2021-03-18 00:57:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-07 00:34:36 +00:00
|
|
|
status[#status] = utils_component.strip_separator(status[#status],
|
|
|
|
drawn_components[#status])
|
2021-03-18 00:57:59 +00:00
|
|
|
return table.concat(status)
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|