Use table.concat instead of string concatentation (#7)
This commit is contained in:
parent
dfaf37d560
commit
b8ad8a13b2
|
@ -66,33 +66,33 @@ local function StatusLine(isFocused)
|
||||||
M.theme = utils.setTheme(M.theme)
|
M.theme = utils.setTheme(M.theme)
|
||||||
highlight.createHighlightGroups(M.theme)
|
highlight.createHighlightGroups(M.theme)
|
||||||
end
|
end
|
||||||
local status = ''
|
local status = {}
|
||||||
if sections.lualine_a ~= nil then
|
if sections.lualine_a ~= nil then
|
||||||
status = status .. highlight.formatHighlight(isFocused, 'lualine_a')
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a'))
|
||||||
status = status .. utils.drawSection(sections.lualine_a, M.separator)
|
table.insert(status, utils.drawSection(sections.lualine_a, M.separator))
|
||||||
end
|
end
|
||||||
if sections.lualine_b ~= nil then
|
if sections.lualine_b ~= nil then
|
||||||
status = status .. highlight.formatHighlight(isFocused, 'lualine_b')
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b'))
|
||||||
status = status .. utils.drawSection(sections.lualine_b, M.separator)
|
table.insert(status, utils.drawSection(sections.lualine_b, M.separator))
|
||||||
end
|
end
|
||||||
if sections.lualine_c ~= nil then
|
if sections.lualine_c ~= nil then
|
||||||
status = status .. highlight.formatHighlight(isFocused, 'lualine_c')
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c'))
|
||||||
status = status .. utils.drawSection(sections.lualine_c, M.separator)
|
table.insert(status, utils.drawSection(sections.lualine_c, M.separator))
|
||||||
end
|
end
|
||||||
status = status .. [[%=]]
|
table.insert(status, "%=")
|
||||||
if sections.lualine_x ~= nil then
|
if sections.lualine_x ~= nil then
|
||||||
status = status .. highlight.formatHighlight(isFocused, 'lualine_c')
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c'))
|
||||||
status = status .. utils.drawSection(sections.lualine_x, M.separator)
|
table.insert(status, utils.drawSection(sections.lualine_x, M.separator))
|
||||||
end
|
end
|
||||||
if sections.lualine_y ~= nil then
|
if sections.lualine_y ~= nil then
|
||||||
status = status .. highlight.formatHighlight(isFocused, 'lualine_b')
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b'))
|
||||||
status = status .. utils.drawSection(sections.lualine_y, M.separator)
|
table.insert(status, utils.drawSection(sections.lualine_y, M.separator))
|
||||||
end
|
end
|
||||||
if sections.lualine_z ~= nil then
|
if sections.lualine_z ~= nil then
|
||||||
status = status .. highlight.formatHighlight(isFocused, 'lualine_a')
|
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a'))
|
||||||
status = status .. utils.drawSection(sections.lualine_z, M.separator)
|
table.insert(status, utils.drawSection(sections.lualine_z, M.separator))
|
||||||
end
|
end
|
||||||
return status
|
return table.concat(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.status()
|
function M.status()
|
||||||
|
|
|
@ -1,27 +1,23 @@
|
||||||
local M = { }
|
local M = { }
|
||||||
|
|
||||||
local function highlight (name, foreground, background, special)
|
local function highlight (name, foreground, background, special)
|
||||||
if special == nil then
|
local command = {
|
||||||
special = 'none'
|
'highlight', name,
|
||||||
end
|
'guifg=' .. foreground,
|
||||||
local command = 'highlight '
|
'guibg=' .. background,
|
||||||
command = command .. name .. ' '
|
'gui=' .. (special or 'none'),
|
||||||
command = command .. 'guifg=' .. foreground .. ' '
|
}
|
||||||
command = command .. 'guibg=' .. background .. ' '
|
return table.concat(command, ' ')
|
||||||
if special then
|
|
||||||
command = command .. 'gui=' .. special .. ' '
|
|
||||||
end
|
|
||||||
return command
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.createHighlightGroups(theme)
|
function M.createHighlightGroups(theme)
|
||||||
for mode, sections in pairs(theme) do
|
for mode, sections in pairs(theme) do
|
||||||
for section, colorscheme in pairs(sections) do
|
for section, colorscheme in pairs(sections) do
|
||||||
|
local special = nil
|
||||||
if section == 'a' then
|
if section == 'a' then
|
||||||
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg ,'bold'))
|
special = 'bold'
|
||||||
else
|
|
||||||
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg ))
|
|
||||||
end
|
end
|
||||||
|
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg, special))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,29 +5,21 @@ function M.setTheme(theme)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.drawSection(section, separator)
|
function M.drawSection(section, separator)
|
||||||
local status = ''
|
local status = {}
|
||||||
for index, statusFunction in pairs(section) do
|
for _, statusFunction in pairs(section) do
|
||||||
local localstatus = statusFunction()
|
local localstatus = statusFunction()
|
||||||
if localstatus:len() > 0 then
|
if #localstatus > 0 then
|
||||||
if separator:len() > 0 then
|
table.insert(status, localstatus)
|
||||||
if index > 1 then
|
|
||||||
status = status .. separator .. ' '
|
|
||||||
end
|
|
||||||
status = status .. localstatus
|
|
||||||
status = status .. ' '
|
|
||||||
else
|
|
||||||
status = status .. localstatus
|
|
||||||
status = status .. ' '
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if status:len() > 0 then
|
if #status == 0 then
|
||||||
if separator:len() > 0 and table.maxn(section) > 1 then
|
return ''
|
||||||
return ' ' .. status .. ' '
|
|
||||||
end
|
|
||||||
return ' ' .. status
|
|
||||||
end
|
end
|
||||||
return ''
|
local sep = ' '
|
||||||
|
if #separator > 0 then
|
||||||
|
sep = ' ' .. separator .. ' '
|
||||||
|
end
|
||||||
|
return ' ' .. table.concat(status, sep) .. ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue