Make galaxline component index dynamic (#434)

This commit is contained in:
gukz 2021-05-27 12:05:23 +08:00 committed by GitHub
parent 10589dcdf1
commit 12b5dc796f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,7 @@ local condition = require('galaxyline.condition')
local gls = gl.section local gls = gl.section
gl.short_line_list = {'NvimTree', 'vista', 'dbui', 'packer'} gl.short_line_list = {'NvimTree', 'vista', 'dbui', 'packer'}
gls.left[1] = { table.insert(gls.left, {
ViMode = { ViMode = {
provider = function() provider = function()
-- auto change color according the vim mode -- auto change color according the vim mode
@ -56,11 +56,11 @@ gls.left[1] = {
end, end,
highlight = {colors.red, colors.bg} highlight = {colors.red, colors.bg}
} }
} })
print(vim.fn.getbufvar(0, 'ts')) print(vim.fn.getbufvar(0, 'ts'))
vim.fn.getbufvar(0, 'ts') vim.fn.getbufvar(0, 'ts')
gls.left[2] = { table.insert(gls.left, {
GitIcon = { GitIcon = {
provider = function() provider = function()
return '' return ''
@ -70,9 +70,9 @@ gls.left[2] = {
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.orange, colors.bg} highlight = {colors.orange, colors.bg}
} }
} })
gls.left[3] = { table.insert(gls.left, {
GitBranch = { GitBranch = {
provider = 'GitBranch', provider = 'GitBranch',
condition = condition.check_git_workspace, condition = condition.check_git_workspace,
@ -80,45 +80,45 @@ gls.left[3] = {
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.left[4] = { table.insert(gls.left, {
DiffAdd = { DiffAdd = {
provider = 'DiffAdd', provider = 'DiffAdd',
condition = condition.hide_in_width, condition = condition.hide_in_width,
icon = '', icon = '',
highlight = {colors.green, colors.bg} highlight = {colors.green, colors.bg}
} }
} })
gls.left[5] = { table.insert(gls.left, {
DiffModified = { DiffModified = {
provider = 'DiffModified', provider = 'DiffModified',
condition = condition.hide_in_width, condition = condition.hide_in_width,
icon = '', icon = '',
highlight = {colors.blue, colors.bg} highlight = {colors.blue, colors.bg}
} }
} })
gls.left[6] = { table.insert(gls.left, {
DiffRemove = { DiffRemove = {
provider = 'DiffRemove', provider = 'DiffRemove',
condition = condition.hide_in_width, condition = condition.hide_in_width,
icon = '', icon = '',
highlight = {colors.red, colors.bg} highlight = {colors.red, colors.bg}
} }
} })
gls.right[1] = { table.insert(gls.right, {
DiagnosticError = {provider = 'DiagnosticError', icon = '', highlight = {colors.error_red, colors.bg}} DiagnosticError = {provider = 'DiagnosticError', icon = '', highlight = {colors.error_red, colors.bg}}
} })
gls.right[2] = {DiagnosticWarn = {provider = 'DiagnosticWarn', icon = '', highlight = {colors.orange, colors.bg}}} table.insert(gls.right, {DiagnosticWarn = {provider = 'DiagnosticWarn', icon = '', highlight = {colors.orange, colors.bg}}})
gls.right[3] = { table.insert(gls.right, {
DiagnosticHint = {provider = 'DiagnosticHint', icon = '', highlight = {colors.vivid_blue, colors.bg}} DiagnosticHint = {provider = 'DiagnosticHint', icon = '', highlight = {colors.vivid_blue, colors.bg}}
} })
gls.right[4] = {DiagnosticInfo = {provider = 'DiagnosticInfo', icon = '', highlight = {colors.info_yellow, colors.bg}}} table.insert(gls.right, {DiagnosticInfo = {provider = 'DiagnosticInfo', icon = '', highlight = {colors.info_yellow, colors.bg}}})
gls.right[5] = { table.insert(gls.right, {
TreesitterIcon = { TreesitterIcon = {
provider = function() provider = function()
if next(vim.treesitter.highlighter.active) ~= nil then return '' end if next(vim.treesitter.highlighter.active) ~= nil then return '' end
@ -128,9 +128,9 @@ gls.right[5] = {
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.green, colors.bg} highlight = {colors.green, colors.bg}
} }
} })
gls.right[6] = { table.insert(gls.right, {
ShowLspClient = { ShowLspClient = {
provider = 'GetLspClient', provider = 'GetLspClient',
condition = function() condition = function()
@ -141,27 +141,27 @@ gls.right[6] = {
icon = '', icon = '',
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.right[7] = { table.insert(gls.right, {
LineInfo = { LineInfo = {
provider = 'LineColumn', provider = 'LineColumn',
separator = ' ', separator = ' ',
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.right[8] = { table.insert(gls.right, {
PerCent = { PerCent = {
provider = 'LinePercent', provider = 'LinePercent',
separator = ' ', separator = ' ',
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.right[9] = { table.insert(gls.right, {
Tabstop = { Tabstop = {
provider = function() provider = function()
return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
@ -171,9 +171,9 @@ gls.right[9] = {
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.right[10] = { table.insert(gls.right, {
BufferType = { BufferType = {
provider = 'FileTypeName', provider = 'FileTypeName',
condition = condition.hide_in_width, condition = condition.hide_in_width,
@ -181,9 +181,9 @@ gls.right[10] = {
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.right[11] = { table.insert(gls.right, {
FileEncode = { FileEncode = {
provider = 'FileEncode', provider = 'FileEncode',
condition = condition.hide_in_width, condition = condition.hide_in_width,
@ -191,9 +191,9 @@ gls.right[11] = {
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.right[12] = { table.insert(gls.right, {
Space = { Space = {
provider = function() provider = function()
return ' ' return ' '
@ -202,19 +202,19 @@ gls.right[12] = {
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.orange, colors.bg} highlight = {colors.orange, colors.bg}
} }
} })
gls.short_line_left[1] = { table.insert(gls.short_line_left, {
BufferType = { BufferType = {
provider = 'FileTypeName', provider = 'FileTypeName',
separator = ' ', separator = ' ',
separator_highlight = {'NONE', colors.bg}, separator_highlight = {'NONE', colors.bg},
highlight = {colors.grey, colors.bg} highlight = {colors.grey, colors.bg}
} }
} })
gls.short_line_left[2] = { table.insert(gls.short_line_left, {
SFileName = {provider = 'SFileName', condition = condition.buffer_not_empty, highlight = {colors.grey, colors.bg}} SFileName = {provider = 'SFileName', condition = condition.buffer_not_empty, highlight = {colors.grey, colors.bg}}
} })
gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.bg}}} table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.bg}}})