Use table.concat instead of string concatentation (#7)

This commit is contained in:
Eli W. Hunter 2021-01-03 14:11:22 -05:00 committed by GitHub
parent dfaf37d560
commit b8ad8a13b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 48 deletions

View File

@ -66,33 +66,33 @@ local function StatusLine(isFocused)
M.theme = utils.setTheme(M.theme)
highlight.createHighlightGroups(M.theme)
end
local status = ''
local status = {}
if sections.lualine_a ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_a')
status = status .. utils.drawSection(sections.lualine_a, M.separator)
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a'))
table.insert(status, utils.drawSection(sections.lualine_a, M.separator))
end
if sections.lualine_b ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_b')
status = status .. utils.drawSection(sections.lualine_b, M.separator)
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b'))
table.insert(status, utils.drawSection(sections.lualine_b, M.separator))
end
if sections.lualine_c ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_c')
status = status .. utils.drawSection(sections.lualine_c, M.separator)
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c'))
table.insert(status, utils.drawSection(sections.lualine_c, M.separator))
end
status = status .. [[%=]]
table.insert(status, "%=")
if sections.lualine_x ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_c')
status = status .. utils.drawSection(sections.lualine_x, M.separator)
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_c'))
table.insert(status, utils.drawSection(sections.lualine_x, M.separator))
end
if sections.lualine_y ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_b')
status = status .. utils.drawSection(sections.lualine_y, M.separator)
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_b'))
table.insert(status, utils.drawSection(sections.lualine_y, M.separator))
end
if sections.lualine_z ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_a')
status = status .. utils.drawSection(sections.lualine_z, M.separator)
table.insert(status, highlight.formatHighlight(isFocused, 'lualine_a'))
table.insert(status, utils.drawSection(sections.lualine_z, M.separator))
end
return status
return table.concat(status)
end
function M.status()

View File

@ -1,27 +1,23 @@
local M = { }
local function highlight (name, foreground, background, special)
if special == nil then
special = 'none'
end
local command = 'highlight '
command = command .. name .. ' '
command = command .. 'guifg=' .. foreground .. ' '
command = command .. 'guibg=' .. background .. ' '
if special then
command = command .. 'gui=' .. special .. ' '
end
return command
local command = {
'highlight', name,
'guifg=' .. foreground,
'guibg=' .. background,
'gui=' .. (special or 'none'),
}
return table.concat(command, ' ')
end
function M.createHighlightGroups(theme)
for mode, sections in pairs(theme) do
for section, colorscheme in pairs(sections) do
local special = nil
if section == 'a' then
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg ,'bold'))
else
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg ))
special = 'bold'
end
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg, special))
end
end
end

View File

@ -5,29 +5,21 @@ function M.setTheme(theme)
end
function M.drawSection(section, separator)
local status = ''
for index, statusFunction in pairs(section) do
local status = {}
for _, statusFunction in pairs(section) do
local localstatus = statusFunction()
if localstatus:len() > 0 then
if separator:len() > 0 then
if index > 1 then
status = status .. separator .. ' '
end
status = status .. localstatus
status = status .. ' '
else
status = status .. localstatus
status = status .. ' '
if #localstatus > 0 then
table.insert(status, localstatus)
end
end
end
if status:len() > 0 then
if separator:len() > 0 and table.maxn(section) > 1 then
return ' ' .. status .. ' '
end
return ' ' .. status
end
if #status == 0 then
return ''
end
local sep = ' '
if #separator > 0 then
sep = ' ' .. separator .. ' '
end
return ' ' .. table.concat(status, sep) .. ' '
end
return M