feat(statusline): clean up bracket provider

This commit is contained in:
Matt Leong 2021-12-05 10:01:07 -08:00
parent 1866fc1218
commit 1978317431
2 changed files with 26 additions and 6 deletions

View file

@ -86,15 +86,31 @@ local BracketProvider = function(icon, cond)
return function() return function()
local result local result
if cond == true or cond == false then if type(cond) == 'boolean' then
result = cond result = cond
else else
result = cond() result = cond()
end end
if result ~= nil and result ~= '' then if result == nil then
return
end
if type(result) == 'number' then
if result > 0 then
return icon
end
end
if type(result) == 'boolean' and result == true then
return icon return icon
end end
if type(result) == 'string' then
if #result > 0 then
return icon
end
end
end end
end end
@ -245,7 +261,7 @@ gls.left = {
{ {
DiffAdd = { DiffAdd = {
provider = 'DiffAdd', provider = 'DiffAdd',
icon = ' ', icon = ' ' .. icons.diff_add,
condition = check_width_and_git_and_buffer, condition = check_width_and_git_and_buffer,
highlight = { colors.diffAdd, colors.statusline_bg }, highlight = { colors.diffAdd, colors.statusline_bg },
}, },
@ -254,7 +270,7 @@ gls.left = {
DiffModified = { DiffModified = {
provider = 'DiffModified', provider = 'DiffModified',
condition = check_width_and_git_and_buffer, condition = check_width_and_git_and_buffer,
icon = ' ', icon = ' ' .. icons.diff_modified,
highlight = { colors.diffModified, colors.statusline_bg }, highlight = { colors.diffModified, colors.statusline_bg },
}, },
}, },
@ -262,7 +278,7 @@ gls.left = {
DiffRemove = { DiffRemove = {
provider = 'DiffRemove', provider = 'DiffRemove',
condition = check_width_and_git_and_buffer, condition = check_width_and_git_and_buffer,
icon = ' ', icon = ' ' .. icons.diff_remove,
highlight = { colors.diffDeleted, colors.statusline_bg }, highlight = { colors.diffDeleted, colors.statusline_bg },
}, },
}, },
@ -309,6 +325,7 @@ gls.right = {
DiagnosticInfoLeftBracket = { DiagnosticInfoLeftBracket = {
provider = BracketProvider(icons.arrow_left, diag.get_diagnostic_info), provider = BracketProvider(icons.arrow_left, diag.get_diagnostic_info),
highlight = 'DiagnosticInfo', highlight = 'DiagnosticInfo',
condition = condition.buffer_not_empty,
}, },
}, },
{ {
@ -316,7 +333,7 @@ gls.right = {
provider = diag.get_diagnostic_info, provider = diag.get_diagnostic_info,
icon = ' ' .. icons.info .. ' ', icon = ' ' .. icons.info .. ' ',
highlight = 'DiagnosticInfo', highlight = 'DiagnosticInfo',
condition = check_width_and_git_and_buffer, condition = condition.buffer_not_empty,
}, },
}, },
{ {

View file

@ -30,6 +30,9 @@ local icons = {
file2 = '', file2 = '',
clock = '', clock = '',
word = '', word = '',
diff_add = '',
diff_modified = '',
diff_remove = '',
git = { git = {
unstaged = '', unstaged = '',
staged = '', staged = '',