feat(ui): added multiple options for diff command

This commit is contained in:
Folke Lemaitre 2022-12-24 11:27:29 +01:00
commit 7d02da2ff0
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
6 changed files with 83 additions and 5 deletions

View file

@ -26,6 +26,7 @@ end
M.keys = {
hover = "K",
diff = "d",
close = "q",
details = "<cr>",
profile_sort = "<C-s>",

58
lua/lazy/view/diff.lua Normal file
View file

@ -0,0 +1,58 @@
local Util = require("lazy.util")
local M = {}
---@alias LazyDiff {commit:string} | {from:string, to:string}
---@alias LazyDiffFun fun(plugin:LazyPlugin, diff:LazyDiff)
M.handlers = {
---@type LazyDiffFun
browser = function(plugin, diff)
if plugin.url then
local url = plugin.url:gsub("%.git$", "")
if diff.commit then
Util.open(url .. "/commit/" .. diff.commit)
else
Util.open(url .. "/compare/" .. diff.from .. ".." .. diff.to)
end
else
Util.error("No url for " .. plugin.name)
end
end,
---@type LazyDiffFun
["diffview.nvim"] = function(plugin, diff)
if diff.commit then
vim.cmd.DiffviewOpen(("-C=%s"):format(plugin.dir) .. " " .. diff.commit)
else
vim.cmd.DiffviewOpen(("-C=%s"):format(plugin.dir) .. " " .. diff.from .. ".." .. diff.to)
end
end,
---@type LazyDiffFun
git = function(plugin, diff)
local cmd = { "git", "diff" }
if diff.commit then
cmd[#cmd + 1] = diff.commit
else
cmd[#cmd + 1] = diff.from
cmd[#cmd + 1] = diff.to
end
Util.open_cmd(cmd, { cwd = plugin.dir, filetype = "git" })
end,
---@type LazyDiffFun
terminal_git = function(plugin, diff)
local cmd = { "git", "diff" }
if diff.commit then
cmd[#cmd + 1] = diff.commit
else
cmd[#cmd + 1] = diff.from
cmd[#cmd + 1] = diff.to
end
Util.open_cmd(cmd, { cwd = plugin.dir, terminal = true, env = { PAGER = "cat" } })
end,
}
return M

View file

@ -25,7 +25,7 @@ function M.new(view)
local self = setmetatable({}, { __index = setmetatable(M, { __index = Text }) })
self.view = view
self.padding = 2
self.wrap = view.win_opts.width
self.wrap = view.opts.win_opts.width
return self
end
@ -56,8 +56,9 @@ function M:update()
end
end
local mode = self:title()
self:title()
local mode = self.view.state.mode
if mode == "help" then
self:help()
elseif mode == "profile" then
@ -139,7 +140,6 @@ function M:title()
end
self:nl():nl()
end
return self.view.state.mode
end
function M:help()
@ -395,12 +395,14 @@ function M:log(task)
if msg:find("^%S+!:") then
self:diagnostic({ message = "Breaking Changes", severity = vim.diagnostic.severity.WARN })
end
self:append(ref .. " ", "LazyCommit", { indent = 6 })
self:append(ref:sub(1, 7) .. " ", "LazyCommit", { indent = 6 })
self:append(vim.trim(msg)):highlight({
["#%d+"] = "Number",
["^%S+:"] = "Title",
["^%S+(%(.*%)):"] = "Italic",
["`.-`"] = "@text.literal.markdown_inline",
["%*.-%*"] = "Italic",
["%*%*.-%*%*"] = "Bold",
})
-- string.gsub
self:append(" " .. time, "Comment")