From 19783174314d5b609cbd3a043cbcd390e4a569ac Mon Sep 17 00:00:00 2001 From: Matt Leong Date: Sun, 5 Dec 2021 10:01:07 -0800 Subject: [PATCH] feat(statusline): clean up bracket provider --- lua/cosmic/modules/statusline/init.lua | 29 ++++++++++++++++++++------ lua/cosmic/theme/icons.lua | 3 +++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lua/cosmic/modules/statusline/init.lua b/lua/cosmic/modules/statusline/init.lua index 0389cf2..53ae843 100644 --- a/lua/cosmic/modules/statusline/init.lua +++ b/lua/cosmic/modules/statusline/init.lua @@ -86,15 +86,31 @@ local BracketProvider = function(icon, cond) return function() local result - if cond == true or cond == false then + if type(cond) == 'boolean' then result = cond else result = cond() 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 end + + if type(result) == 'string' then + if #result > 0 then + return icon + end + end end end @@ -245,7 +261,7 @@ gls.left = { { DiffAdd = { provider = 'DiffAdd', - icon = '  ', + icon = ' ' .. icons.diff_add, condition = check_width_and_git_and_buffer, highlight = { colors.diffAdd, colors.statusline_bg }, }, @@ -254,7 +270,7 @@ gls.left = { DiffModified = { provider = 'DiffModified', condition = check_width_and_git_and_buffer, - icon = '  ', + icon = ' ' .. icons.diff_modified, highlight = { colors.diffModified, colors.statusline_bg }, }, }, @@ -262,7 +278,7 @@ gls.left = { DiffRemove = { provider = 'DiffRemove', condition = check_width_and_git_and_buffer, - icon = '  ', + icon = ' ' .. icons.diff_remove, highlight = { colors.diffDeleted, colors.statusline_bg }, }, }, @@ -309,6 +325,7 @@ gls.right = { DiagnosticInfoLeftBracket = { provider = BracketProvider(icons.arrow_left, diag.get_diagnostic_info), highlight = 'DiagnosticInfo', + condition = condition.buffer_not_empty, }, }, { @@ -316,7 +333,7 @@ gls.right = { provider = diag.get_diagnostic_info, icon = ' ' .. icons.info .. ' ', highlight = 'DiagnosticInfo', - condition = check_width_and_git_and_buffer, + condition = condition.buffer_not_empty, }, }, { diff --git a/lua/cosmic/theme/icons.lua b/lua/cosmic/theme/icons.lua index 2b83bce..fe7b1ce 100644 --- a/lua/cosmic/theme/icons.lua +++ b/lua/cosmic/theme/icons.lua @@ -30,6 +30,9 @@ local icons = { file2 = '', clock = '', word = '', + diff_add = ' ', + diff_modified = ' ', + diff_remove = ' ', git = { unstaged = '✗', staged = '✓',