Skip to content

Commit 05b7d09

Browse files
committed
feat(status): add mini.diff support to git diff components
1 parent 58c4130 commit 05b7d09

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lua/astroui/status/component.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function M.git_diff(opts)
224224
surround = { separator = "left", color = "git_diff_bg", condition = condition.git_changed },
225225
update = {
226226
"User",
227-
pattern = { "GitSignsUpdate", "GitSignsChanged" },
227+
pattern = { "GitSignsUpdate", "GitSignsChanged", "MiniDiffUpdated" },
228228
callback = function() vim.schedule(vim.cmd.redrawstatus) end,
229229
},
230230
init = init.update_events { "BufEnter" },

lua/astroui/status/condition.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@ end
9494
function M.git_changed(bufnr)
9595
if type(bufnr) == "table" then bufnr = bufnr.bufnr end
9696
if not bufnr then bufnr = 0 end
97-
local git_status = vim.b[bufnr].gitsigns_status_dict
98-
return git_status and (git_status.added or 0) + (git_status.removed or 0) + (git_status.changed or 0) > 0
97+
local git_status, total
98+
if vim.b[bufnr].gitsigns_status_dict then -- gitsigns support
99+
git_status = vim.b[bufnr].gitsigns_status_dict
100+
total = (git_status.added or 0) + (git_status.removed or 0) + (git_status.changed or 0)
101+
elseif vim.b[bufnr].minidiff_summary then -- mini.diff support
102+
git_status = vim.b[bufnr].minidiff_summary
103+
total = (git_status.add or 0) + (git_status.delete or 0) + (git_status.change or 0)
104+
end
105+
return total and total > 0
99106
end
100107

101108
--- A condition function if the current buffer is modified

lua/astroui/status/provider.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ function M.git_branch(opts)
433433
return function(self) return status_utils.stylize(vim.b[self and self.bufnr or 0].gitsigns_head or "", opts) end
434434
end
435435

436+
local minidiff_types = { added = "add", changed = "change", removed = "delete" }
437+
436438
--- A provider function for showing the current git diff count of a specific type
437439
---@param opts? table options for type of git diff and options passed to the stylize function
438440
---@return function|nil # the function for outputting the git diff
@@ -441,11 +443,13 @@ end
441443
function M.git_diff(opts)
442444
if not opts or not opts.type then return end
443445
return function(self)
444-
local status = vim.b[self and self.bufnr or 0].gitsigns_status_dict
445-
return status_utils.stylize(
446-
status and status[opts.type] and status[opts.type] > 0 and tostring(status[opts.type]) or "",
447-
opts
448-
)
446+
local bufnr, total = self and self.bufnr or 0, nil
447+
if vim.b[bufnr].gitsigns_status_dict then -- gitsigns support
448+
total = vim.b[bufnr].gitsigns_status_dict[opts.type]
449+
elseif vim.b[bufnr].minidiff_summary then -- mini.diff support
450+
total = vim.b[bufnr].minidiff_summary[minidiff_types[opts.type]]
451+
end
452+
return status_utils.stylize(total and total > 0 and tostring(total) or "", opts)
449453
end
450454
end
451455

0 commit comments

Comments
 (0)